Commit 9cab5c7
committed
fix(security): tighten ?return=... allowlist on login + logout
The post-login redirect honored an arbitrary ?return= query value as
long as it wasn't literally /login or /logout. An attacker phishing a
victim to https://gearbox.example.com/login?return=https://attacker
would land them on the attacker's harvest page immediately after a
successful login, with the URL bar showing only the moment of redirect
from a legitimate origin. The Logout handler had the same shape and
could relay the value back to the login page.
Replace the two-string blocklist with a same-origin allowlist:
isSafeReturnURL accepts only relative paths starting with `/`, rejects
protocol-relative `//host`, rejects `/\…` (some browsers normalize the
backslash to a forward slash, opening another protocol-relative path),
rejects any embedded backslash, and rejects schemed URIs entirely.
Applies to both LoginPost and Logout.
Test pins down the accept/reject matrix including the textbook bypasses
(`//evil.example.com`, `/\evil.example.com`, `javascript:`, `data:`).
P0-4 from the 2026-05 security audit.1 parent 63d6bca commit 9cab5c7
2 files changed
Lines changed: 83 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
13 | 44 | | |
14 | 45 | | |
15 | 46 | | |
| |||
124 | 155 | | |
125 | 156 | | |
126 | 157 | | |
127 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
128 | 163 | | |
129 | | - | |
| 164 | + | |
130 | 165 | | |
131 | 166 | | |
132 | 167 | | |
| |||
178 | 213 | | |
179 | 214 | | |
180 | 215 | | |
181 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
182 | 220 | | |
183 | | - | |
| 221 | + | |
184 | 222 | | |
185 | 223 | | |
186 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments