From 013b5103527cb1646dc717cadf48ad34aceaa77e Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 28 Sep 2022 00:13:12 -0600 Subject: rewrite: Only trim prefix if matched See #5073 --- modules/caddyhttp/rewrite/rewrite.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'modules/caddyhttp/rewrite/rewrite.go') diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go index 95bc504..31c9778 100644 --- a/modules/caddyhttp/rewrite/rewrite.go +++ b/modules/caddyhttp/rewrite/rewrite.go @@ -383,8 +383,13 @@ func trimPathPrefix(escapedPath, prefix string) string { iPrefix++ } - // found matching prefix, trim it - return escapedPath[iPath:] + // if we iterated through the entire prefix, we found it, so trim it + if iPath >= len(prefix) { + return escapedPath[iPath:] + } + + // otherwise we did not find the prefix + return escapedPath } func reverse(s string) string { -- cgit v1.2.3