caddy/modules/caddyhttp/rewrite
Matthew Holt 7591cff1fb
rewrite: escape regexp captures in rewritten paths
The rewrite handler percent-decodes the path after expanding placeholders.
Regexp captures, usually taken from the already-decoded request path by
path_regexp, were inserted verbatim, so a double-encoded "../" or "?"
became a real separator or query string after path guards had run.

{http.regexp.*} values are now escaped like the other path-derived
placeholders (slashes preserved) when used in the path part of a rewrite.
Captures intentionally used to inject "?" into the path from a header or
other source must now set the query explicitly.

Based on a patch by Adel Assakaf.
Reviewed by mholt.

Code written by GitHub Copilot (Claude Opus 5.5), adapting the
contributor's patch.

Co-authored-by: Adel Assakaf <212399165+assakafpix@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-11 12:25:23 -07:00
..
caddyfile.go chore: Dumb prealloc lint fix (#7430) 2026-01-13 14:13:43 -05:00
rewrite.go rewrite: escape regexp captures in rewritten paths 2026-11-11 12:25:23 -07:00
rewrite_bench_test.go caddyhttp: presize buffers in hot paths to reduce allocations (#7842) 2026-11-04 20:26:53 +00:00
rewrite_regexp_clean_test.go rewrite: clean paths before regexp replacement changes depth 2026-11-11 11:06:41 -07:00
rewrite_test.go rewrite: escape regexp captures in rewritten paths 2026-11-11 12:25:23 -07:00