Repository navigation
Conversation
With UseRawPath or UseEscapedPath the router matches the escaped path, but redirectTrailingSlash built the Location from the decoded URL.Path. A request for /files/a%2Fb/ was redirected to /files/a/b, which no longer matches /files/:name. Build the redirect from the escaped path when routing used it, and keep URL.RawPath in sync so the encoding survives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4918 +/- ##
==========================================
+ Coverage 98.65% 98.71% +0.06%
==========================================
Files 48 48
Lines 3188 3195 +7
==========================================
+ Hits 3145 3154 +9
+ Misses 43 41 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Tales-of-zuna
left a comment
There was a problem hiding this comment.
Thanks for this! I reproduced the bug on master with a test of my own (route /files/:name, plus /dirs/:name/ for the other direction):
| Mode | Request | Location on master |
|---|---|---|
UseRawPath |
GET /files/a%2Fb/ |
/files/a/b |
UseRawPath |
GET /dirs/a%2Fb |
/dirs/a/b/ |
UseEscapedPath |
both of the above | same as UseRawPath |
UseRawPath + X-Forwarded-Prefix: /api |
GET /files/a%2Fb/ |
/api/files/a/b |
| default | GET /files/a%2Fb/ |
404, the route doesn't match the decoded path, so this PR doesn't touch it |
So the description is accurate, and the default configuration really is unaffected.
Suggestion: add an X-Forwarded-Prefix case to the test. The PR also changes the prefix line (p = prefix + "/" + p), but the new test doesn't go through it. From reading the code, I'd expect /api/files/a%2Fb:
sanitizePathCharsstrips%from the prefix, so theurl.PathUnescapestep can't decode anything in it.- The
//between prefix and path is collapsed byhttp.Redirect'spath.Clean, the same as on master.
I traced this by hand and didn't run it on the PR branch, so a test case would lock it in.
I also checked /x/%2F%2Fevil.com/ against a /x/:name route. It can't become a //host redirect on master (http.Redirect cleans it), and with this change the slashes stay encoded, so there's no open-redirect concern.
…irect Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for checking it so carefully. Added the |
With
UseRawPathorUseEscapedPathenabled, routing matches the escaped path, butredirectTrailingSlashbuilds theLocationfrom the decodedURL.Path. An encoded slash then becomes a real separator:The same happens in the other direction (
/dirs/a%2Fb->/dirs/a/b/for a/dirs/:name/route).This builds the redirect from the escaped path when routing used it and keeps
URL.RawPathin sync, so the encoding survives. The default configuration is unchanged.masterbranch.docs/doc.md.I used Claude Code to write this change.