@marcel91200 / caddy Mirror · read-only / commits / fbfb8fc5
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 13:30 UTC

rewrite: Force recomputing path when escaped path matches rewrite target

Thank you for the report by @MaherAzzouzi, and the suggested fix!

Matthew Holt committed Mar 4, 2026 at 16:18 UTC fbfb8fc517728f85890cd46559c01bec9495bf17
2 files changed +6
modules/caddyhttp/rewrite/rewrite.go
+1
@@ -247,6 +247,7 @@ func (rewr Rewrite) Rewrite(r *http.Request, repl *caddy.Replacer) bool {
247 } else {
248 r.URL.Path = path
249 }
250 + r.URL.RawPath = "" // force recomputing when EscapedPath() is called
251 }
252 if qsStart >= 0 {
253 r.URL.RawQuery = newQuery
modules/caddyhttp/rewrite/rewrite_test.go
+5
@@ -224,6 +224,11 @@ func TestRewrite(t *testing.T) {
224 input: newRequest(t, "GET", "/foo#fragFirst?c=d"),
225 expect: newRequest(t, "GET", "/bar#fragFirst?c=d"),
226 },
227 + {
228 + rule: Rewrite{URI: "/api/admin/panel"},
229 + input: newRequest(t, "GET", "/api/admin%2Fpanel"),
230 + expect: newRequest(t, "GET", "/api/admin/panel"),
231 + },
232
233 {
234 rule: Rewrite{StripPathPrefix: "/prefix"},