Skip to content
Snippets Groups Projects
Unverified Commit 06464008 authored by chris48s's avatar chris48s Committed by GitHub
Browse files

ensure redirect target path is correctly encoded (#6229)

parent 6128aa55
No related branches found
No related tags found
No related merge requests found
...@@ -82,7 +82,7 @@ module.exports = function redirector(attrs) { ...@@ -82,7 +82,7 @@ module.exports = function redirector(attrs) {
trace.logTrace('inbound', emojic.ticket, 'Named params', namedParams) trace.logTrace('inbound', emojic.ticket, 'Named params', namedParams)
trace.logTrace('inbound', emojic.crayon, 'Query params', queryParams) trace.logTrace('inbound', emojic.crayon, 'Query params', queryParams)
const targetPath = transformPath(namedParams) const targetPath = encodeURI(transformPath(namedParams))
trace.logTrace('validate', emojic.dart, 'Target', targetPath) trace.logTrace('validate', emojic.dart, 'Target', targetPath)
let urlSuffix = ask.uri.search || '' let urlSuffix = ask.uri.search || ''
......
...@@ -121,6 +121,20 @@ describe('Redirector', function () { ...@@ -121,6 +121,20 @@ describe('Redirector', function () {
) )
}) })
it('should correctly encode the redirect URL', async function () {
const { statusCode, headers } = await got(
`${baseUrl}/very/old/service/hello%0Dworld.svg?foobar=a%0Db`,
{
followRedirect: false,
}
)
expect(statusCode).to.equal(301)
expect(headers.location).to.equal(
'/new/service/hello%0Dworld.svg?foobar=a%0Db'
)
})
describe('transformQueryParams', function () { describe('transformQueryParams', function () {
const route = { const route = {
base: 'another/old/service', base: 'another/old/service',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment