1
0
mirror of synced 2025-12-19 18:10:59 -05:00

validate that 'pathname' is not repeated as query (#37319)

This commit is contained in:
Peter Bengtsson
2023-05-31 07:37:14 -04:00
committed by GitHub
parent 7d00e4036d
commit 21eeb2cc28
2 changed files with 10 additions and 0 deletions

View File

@@ -21,6 +21,9 @@ const validationMiddleware = (req, res, next) => {
if (!pathname) {
return res.status(400).json({ error: `No 'pathname' query` })
}
if (Array.isArray(pathname)) {
return res.status(400).json({ error: "Multiple 'pathname' keys" })
}
if (!pathname.trim()) {
return res.status(400).json({ error: `'pathname' query empty` })
}

View File

@@ -63,6 +63,13 @@ describe('pageinfo api', () => {
expect(error).toBe("'pathname' query empty")
})
test('repeated pathname query string key', async () => {
const res = await get('/api/pageinfo/v1?pathname=a&pathname=b')
expect(res.statusCode).toBe(400)
const { error } = JSON.parse(res.body)
expect(error).toBe("Multiple 'pathname' keys")
})
test('redirects correct the URL', async () => {
// Regular redirect from `redirect_from`
{