Skip to content

caddyhttp: fix escaped path matcher over-matching longer paths - #7828

Merged
steadytao merged 2 commits into
caddyserver:masterfrom
alhudz:path-matcher-escape-overmatch
Jul 7, 2026
Merged

steadytao merged 2 commits into
caddyserver:masterfrom
alhudz:path-matcher-escape-overmatch

Conversation

@alhudz

@alhudz alhudz commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Repro: path /foo%2fbar (a %-escaped pattern with no trailing wildcard) matches a request to /foo%2fbarbaz. The plain pattern /foobar correctly does not match /foobarbaz, so escaped patterns silently behave like prefix matches.
Cause: matchPatternWithEscapeSequence walks the pattern and escaped path in lock-step and stops once the pattern is consumed, so trailing path bytes never make it into the string handed to path.Match; it then only ever sees the prefix.
Fix: append the remaining (normalised) path bytes after the loop so path.Match compares the whole path. Exact patterns now reject longer paths while wildcard patterns are unaffected.

Assistance Disclosure

This contribution was AI-assisted to a significant extent. The over-match in matchPatternWithEscapeSequence was surfaced by automated (LLM-assisted) analysis, and both the patch and the table-test cases were AI-generated. I have reviewed the change and verified it by running go test ./modules/caddyhttp/: the three new cases fail without the fix and pass with it, and the existing escaped/wildcard cases still pass.

@steadytao

Copy link
Copy Markdown
Member

@alhudz the code is fine but we really need the assistance disclosure mate...

@alhudz

alhudz commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Fair enough, sorry for leaving it off. Disclosure: this was AI-assisted to a significant extent. The over-match was surfaced by automated/LLM-assisted analysis, and the patch and the table tests were AI-generated. I reviewed the change and verified it with go test ./modules/caddyhttp/ (the three new cases fail without the fix and pass with it; existing escaped/wildcard cases still pass). I've added an Assistance Disclosure section to the PR description to match the template.

@alhudz

alhudz commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

any update?

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow follow-up here, I have had some personal matters I have been attending to. LGTM. The fix is narrow and the added tests cover the exact non-wildcard over-match cases.

@steadytao
steadytao merged commit 08ad064 into caddyserver:master Jul 7, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants