Skip to content

Commit a6dc0a6

Browse files
author
Peter Bengtsson
authored
'constructor' is NOT a recognized value key (#46220)
1 parent f785f84 commit a6dc0a6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/shielding/middleware/handle-invalid-query-string-values.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ const RECOGNIZED_VALUES = {
1919
platform: allPlatforms,
2020
tool: Object.keys(allTools),
2121
}
22+
// So we can look up if a key in the object is actually present
23+
// and not a built in.
24+
// Otherwise...
25+
//
26+
// > const myObj = {foo: 'bar'}
27+
// > 'constructor' in myObj
28+
// true
29+
//
30+
const RECOGNIZED_VALUES_KEYS = new Set(Object.keys(RECOGNIZED_VALUES))
2231

2332
export default function handleInvalidQuerystringValues(req, res, next) {
2433
const { method, query } = req
2534
if (method === 'GET' || method === 'HEAD') {
2635
for (const key of Object.keys(query)) {
27-
if (key in RECOGNIZED_VALUES) {
36+
if (RECOGNIZED_VALUES_KEYS.has(key)) {
2837
const validValues = RECOGNIZED_VALUES[key]
2938
const values = Array.isArray(query[key]) ? query[key] : [query[key]]
3039
if (values.some((value) => !validValues.includes(value))) {

src/shielding/tests/invalid-querystrings.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ describe('invalid query strings', () => {
5656
expect(res.statusCode).toBe(200)
5757
}
5858
})
59+
60+
test('query string keys with square brackets', async () => {
61+
const url = `/?constructor[foo][bar]=buz`
62+
const res = await get(url)
63+
expect(res.statusCode).toBe(302)
64+
expect(res.headers.location).toBe('/en')
65+
})
5966
})
6067

6168
function randomCharacters(length) {

0 commit comments

Comments
 (0)