Commit f4cf7b6
authored
Guard OAuth return pages against prototype pollution (#281)
* Guard query-param parsing against prototype pollution
oauthReturn.html and mockOAuthAuthorization.html built a queryParams
object by writing map[name] = value for every URL parameter, where the
name is user-controlled. A parameter named __proto__ (or constructor /
prototype) could therefore pollute Object.prototype (CodeQL
js/remote-property-injection, CWE-1321).
Skip those reserved names when populating the map. Legitimate parameters
(state, code, redirect_uri) are unaffected.
* Read OAuth query parameters by name (CodeQL js/remote-property-injection)
The __proto__/constructor/prototype blocklist added earlier is not
recognized as a sanitizer by CodeQL, and the alert covers any property
write keyed by user input, not just prototype pollution. Replace the
query-parameter map with a getQueryParam(name) helper so the pages only
read the parameters they use (state, code, redirect_uri) and never write
a property under a user-controlled name.
* Restrict mock OAuth redirect_uri to the current origin (CodeQL js/xss, js/client-side-unvalidated-url-redirection)
* Parse redirect_uri with the URL API instead of an anchor element
CodeQL flags assigning user input to an anchor's href as an XSS and
unvalidated-redirect sink (js/xss, js/client-side-unvalidated-url-redirection)
even though the element is detached and only used to parse the URL.
Use new URL() for parsing so no sink is involved, and reject a missing
redirect_uri explicitly instead of letting it resolve to "/undefined".
* Rebuild the mock redirect target from url.origin
The origin equality check has already passed at this point, so
url.origin + url.pathname is equivalent to the manual protocol/host
concatenation and reads clearer. Also document that any query or
fragment on the incoming redirect_uri is dropped deliberately - the
caller appends its own ?code=...&state=... parameters.1 parent 27487bc commit f4cf7b6
2 files changed
Lines changed: 63 additions & 13 deletions
File tree
- ui
- commons/src/main/resources
- mock/src/main/resources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
17 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
18 | 25 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | 33 | | |
24 | | - | |
| 34 | + | |
25 | 35 | | |
26 | | - | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
18 | 27 | | |
19 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
20 | 54 | | |
21 | 55 | | |
22 | 56 | | |
23 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
24 | 64 | | |
25 | 65 | | |
26 | 66 | | |
| |||
0 commit comments