@marcel91200 / caddy Mirror · read-only / commits / 52dc6709
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, 08:30 UTC

rewrite: fix wrong index check in trimPathPrefix (#7812)

alhuda committed Jun 13, 2026 at 01:41 UTC 52dc6709fbddd753d179ee1273e3059152827355
2 files changed +7 -1
modules/caddyhttp/rewrite/rewrite.go
+1 -1
@@ -432,7 +432,7 @@ func trimPathPrefix(escapedPath, prefix string) string {
432 }
433
434 // if we iterated through the entire prefix, we found it, so trim it
435 - if iPath >= len(prefix) {
435 + if iPrefix >= len(prefix) {
436 return escapedPath[iPath:]
437 }
438
modules/caddyhttp/rewrite/rewrite_test.go
+6
@@ -267,6 +267,12 @@ func TestRewrite(t *testing.T) {
267 input: newRequest(t, "GET", "/foo/prefix/bar"),
268 expect: newRequest(t, "GET", "/foo/prefix/bar"),
269 },
270 + {
271 + // shorter (percent-encoded) path that is not the prefix must be left alone
272 + rule: Rewrite{StripPathPrefix: "/aaaaaa"},
273 + input: newRequest(t, "GET", "/%61%61"),
274 + expect: newRequest(t, "GET", "/%61%61"),
275 + },
276 {
277 rule: Rewrite{StripPathPrefix: "//prefix"},
278 // scheme and host needed for URL parser to succeed in setting up test