Repository navigation
caddyhttp: fix escaped path matcher over-matching longer paths - #7828
Conversation
|
@alhudz the code is fine but we really need the assistance disclosure mate... |
|
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 |
|
any update? |
steadytao
left a comment
There was a problem hiding this comment.
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.
Repro:
path /foo%2fbar(a%-escaped pattern with no trailing wildcard) matches a request to/foo%2fbarbaz. The plain pattern/foobarcorrectly does not match/foobarbaz, so escaped patterns silently behave like prefix matches.Cause:
matchPatternWithEscapeSequencewalks 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 topath.Match; it then only ever sees the prefix.Fix: append the remaining (normalised) path bytes after the loop so
path.Matchcompares 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
matchPatternWithEscapeSequencewas 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 runninggo test ./modules/caddyhttp/: the three new cases fail without the fix and pass with it, and the existing escaped/wildcard cases still pass.