diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go index 02ef524df..a5a3a504b 100644 --- a/modules/caddyhttp/rewrite/rewrite.go +++ b/modules/caddyhttp/rewrite/rewrite.go @@ -432,7 +432,7 @@ func trimPathPrefix(escapedPath, prefix string) string { } // if we iterated through the entire prefix, we found it, so trim it - if iPath >= len(prefix) { + if iPrefix >= len(prefix) { return escapedPath[iPath:] } diff --git a/modules/caddyhttp/rewrite/rewrite_test.go b/modules/caddyhttp/rewrite/rewrite_test.go index e52a33256..923b164a3 100644 --- a/modules/caddyhttp/rewrite/rewrite_test.go +++ b/modules/caddyhttp/rewrite/rewrite_test.go @@ -267,6 +267,12 @@ func TestRewrite(t *testing.T) { input: newRequest(t, "GET", "/foo/prefix/bar"), expect: newRequest(t, "GET", "/foo/prefix/bar"), }, + { + // shorter (percent-encoded) path that is not the prefix must be left alone + rule: Rewrite{StripPathPrefix: "/aaaaaa"}, + input: newRequest(t, "GET", "/%61%61"), + expect: newRequest(t, "GET", "/%61%61"), + }, { rule: Rewrite{StripPathPrefix: "//prefix"}, // scheme and host needed for URL parser to succeed in setting up test