Commit d776066
committed
refactor(auth): one net/url pass for returnUrl safety + canonicalisation
Follow-up to the Copilot review. The previous fix had two helpers parsing
the same URL twice:
- safeRelativePath: url.Parse(s), reject if scheme/host/user set
- stripFragment: strings.Cut(s, "#"), throw away the tail
stripFragment was the embarrassing one — net/url already exposes
url.URL.Fragment = "" + url.URL.String(), no string fiddling required.
Collapse both helpers into a single sanitizeRelativePath(s) (string, bool)
that returns the canonical fragment-stripped form alongside the safety
verdict. One Parse, one set of checks, one rebuild.
Test suite merges the two matrices into a single table — including
fragment-stripping cases that the previous split missed (e.g. "/?x=1#frag"
must come back as "/?x=1", not "" + stray strings.Cut output).1 parent 8013320 commit d776066
2 files changed
Lines changed: 59 additions & 70 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
40 | 49 | | |
41 | | - | |
| 50 | + | |
42 | 51 | | |
43 | 52 | | |
44 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
| |||
203 | 216 | | |
204 | 217 | | |
205 | 218 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
210 | 224 | | |
211 | 225 | | |
212 | 226 | | |
| |||
301 | 315 | | |
302 | 316 | | |
303 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
304 | 321 | | |
305 | | - | |
306 | | - | |
| 322 | + | |
| 323 | + | |
307 | 324 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | 325 | | |
314 | 326 | | |
315 | 327 | | |
316 | 328 | | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | 329 | | |
326 | 330 | | |
327 | 331 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
8 | 14 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
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 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
53 | 38 | | |
54 | 39 | | |
55 | 40 | | |
0 commit comments