rewrite: Force recomputing path when escaped path matches rewrite target

Thank you for the report by @MaherAzzouzi, and the suggested fix!
This commit is contained in:
Matthew Holt 2026-03-04 16:18:33 -07:00
parent e06dfcf6ed
commit fbfb8fc517
No known key found for this signature in database
2 changed files with 6 additions and 0 deletions

View File

@ -247,6 +247,7 @@ func (rewr Rewrite) Rewrite(r *http.Request, repl *caddy.Replacer) bool {
} else {
r.URL.Path = path
}
r.URL.RawPath = "" // force recomputing when EscapedPath() is called
}
if qsStart >= 0 {
r.URL.RawQuery = newQuery

View File

@ -224,6 +224,11 @@ func TestRewrite(t *testing.T) {
input: newRequest(t, "GET", "/foo#fragFirst?c=d"),
expect: newRequest(t, "GET", "/bar#fragFirst?c=d"),
},
{
rule: Rewrite{URI: "/api/admin/panel"},
input: newRequest(t, "GET", "/api/admin%2Fpanel"),
expect: newRequest(t, "GET", "/api/admin/panel"),
},
{
rule: Rewrite{StripPathPrefix: "/prefix"},