fix: handle upper case protocol like HTTP or HTTPS (#1805)
Co-authored-by: fengmk2 <suqian.yf@antgroup.com>
This commit is contained in:
@@ -20,6 +20,13 @@ describe('ctx.redirect(url)', () => {
|
||||
assert.strictEqual(ctx.status, 302)
|
||||
})
|
||||
|
||||
it('should formatting url before redirect', () => {
|
||||
const ctx = context()
|
||||
ctx.redirect('HTTP://google.com\\@apple.com')
|
||||
assert.strictEqual(ctx.response.header.location, 'http://google.com/@apple.com')
|
||||
assert.strictEqual(ctx.status, 302)
|
||||
})
|
||||
|
||||
it('should auto fix not encode url', done => {
|
||||
const app = new Koa()
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ module.exports = {
|
||||
redirect (url, alt) {
|
||||
// location
|
||||
if (url === 'back') url = this.ctx.get('Referrer') || alt || '/'
|
||||
if (url.startsWith('https://') || url.startsWith('http://')) {
|
||||
if (/^https?:\/\//i.test(url)) {
|
||||
// formatting url again avoid security escapes
|
||||
url = new URL(url).toString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user