caddy/modules
TowyTowy 7bf1b9057b
rewrite: fix strip_path_suffix ignoring percent-encoding (#7877)
StripPathSuffix is documented to behave like StripPathPrefix: the suffix
is matched in normalized (unescaped) space except where the pattern uses
an escape sequence. But suffix stripping was implemented as

    reverse(trimPathPrefix(reverse(escapedPath), reverse(suffix)))

Reversing the strings moves the '%' to the *end* of each "%xx" escape,
which defeats trimPathPrefix's escape detection (it expects '%' to
precede the two hex digits). As a result the escape-aware, normalized
comparison never happened for suffixes: a decoded pattern failed to
match a percent-encoded path.

Concretely, StripPathPrefix "/a/b/c" strips "/a%2Fb/c/d" to "/d", but the
mirror StripPathSuffix "/b/c" left "/a/b%2Fc" untouched instead of
producing "/a"; likewise StripPathSuffix "bc" did not strip "/a%62c".
This has been the behavior since #4948, which introduced both the
escape-aware trimPathPrefix and the reverse-based suffix trimming.

Replace the reverse trick with a dedicated trimPathSuffix that iterates
from the ends of both strings and applies the same escape-aware,
case-insensitive comparison as trimPathPrefix. An escape in the pattern
itself is still compared literally, so "%2fsuffix" continues to require
the path to contain that exact escape.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-28 19:44:05 +10:00
..
caddyevents refactor: replace HasPrefix+TrimPrefix with CutPrefix (#7095) 2025-06-27 22:04:09 +03:00
caddyfs
caddyhttp rewrite: fix strip_path_suffix ignoring percent-encoding (#7877) 2026-08-28 19:44:05 +10:00
caddypki pki: Handle error immediately after reading root from disk (#7896) 2026-07-19 23:59:46 -04:00
caddytls chore: fix lint errors from newer golangci-lint (#7958) 2026-08-25 13:12:10 +10:00
filestorage
internal/network network_proxy: reject proxy URLs that resolve to a port with no host (#7922) 2026-08-10 15:58:43 +10:00
logging fix: close resources on error paths (#7940) 2026-08-16 21:02:39 +10:00
metrics
standard