Skip to content

Commit 86b5a52

Browse files
authored
Query string abuse causing 5xxs (#23501)
1 parent f1f27cc commit 86b5a52

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

components/hooks/useQuery.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,33 @@ export const useQuery = (): QueryInfo => {
1111
? router.query.query[0]
1212
: router.query.query || ''
1313

14-
let debug = false
15-
if (router.query.debug) {
16-
// Now `router.query.debug` is either string or any array of strings
17-
debug = Boolean(
18-
JSON.parse(Array.isArray(router.query.debug) ? router.query.debug[0] : router.query.debug)
19-
)
20-
} else if (router.query.debug === '') {
21-
// E.g. `?query=foo&debug` should be treated as truthy
22-
debug = true
23-
}
14+
const debug = parseDebug(router.query.debug)
2415

2516
return {
2617
query,
2718
debug,
2819
}
2920
}
21+
22+
function parseDebug(debug: string | Array<string> | undefined) {
23+
if (debug === '') {
24+
// E.g. `?query=foo&debug` should be treated as truthy
25+
return true
26+
}
27+
28+
if (!debug) {
29+
return false
30+
}
31+
32+
// Now `router.query.debug` is either string or any array of strings
33+
if (Array.isArray(debug)) {
34+
debug = debug[0]
35+
}
36+
37+
try {
38+
debug = JSON.parse(debug)
39+
return Boolean(debug)
40+
} catch (e) {}
41+
42+
return false
43+
}

0 commit comments

Comments
 (0)