Repository navigation
caddyhttp: fix path_regexp (MatchPathRE) Windows backslash bypass - #7858
Conversation
steadytao
left a comment
There was a problem hiding this comment.
I think this still needs one more pass before merge. The same Windows normalisation should probably be shared by path and path_regexp and it should handle trailing dots/spaces per path component, not only at the end of the whole path.
Could you also add the required AI disclosure to your PR body.
… path matcher Apply the same Windows path normalization to MatchPathRE that MatchPath already had, and factor it into a shared normalizeWindowsPath helper so both matchers use one implementation. Also strip trailing dots and spaces per path component (not only at the end of the whole path), matching how Windows resolves paths; this fixes the same gap in the path matcher too. Adds regression tests for both matchers. See caddyserver#5613.
65d3a9f to
b0db936
Compare
|
Thanks for the review — all three points are addressed in the latest push:
Tests: added per-component cases to |
steadytao
left a comment
There was a problem hiding this comment.
Thanks, the decoded-path cases are addressed, but the escaped-path branch still bypasses the new per-component normalisation whenever a matcher contains %. MatchPath switches to EscapedPath() and only normalises backslash separators there so a pattern such as /private%2f* can still miss /private.%5csecret.txt.
Please apply equivalent trailing-dot/space normalisation in escaped space and add a regression test with a %-containing matcher.
The MatchPath escaped-path branch (taken when a matcher pattern contains
'%') only folded backslash separators via windowsEscapedPathSeparatorRepl;
it skipped the per-component trailing dot/space normalization now applied
on the decoded branch. On Windows this left a bypass: a matcher such as
`path /private%2f*` could be evaded by GET /private.%5csecret.txt, since
`private.` and `private` resolve to the same directory on NTFS.
Add normalizeWindowsEscapedPath, which trims trailing dots and spaces —
literal ("." / " ") and percent-encoded ("%2e" / "%20") — from every
component in raw/escaped space, splitting on both '/' and encoded '%2f'
separators while preserving them, and leaving "." / ".." for CleanPath.
Regression tests cover the literal and percent-encoded variants against a
'%'-containing matcher.
|
Thanks — addressed in fac502c. The escaped-path branch (the one taken when a matcher pattern contains %) now runs the same per-component trailing dot/space normalization as the decoded branch, via a new normalizeWindowsEscapedPath helper called right after the backslash-separator fold: It walks the escaped path splitting on both literal / and encoded %2f/%2F separators, and trims each component's trailing dots and spaces — literal (. / space) and percent-encoded (%2e / %20) — while preserving the separators so the escaped-space comparison still lines up. . and .. segments are left intact for CleanPath to resolve. |
mholt
left a comment
There was a problem hiding this comment.
I don't know much about Windows but overall I think the change LGTM, I am going by the additional tests 😅
MatchPath was fixed in #7763 to normalize Windows path separators, but its sibling MatchPathRE (the
path_regexpmatcher) was missed. On Windows a guard likepath_regexp ^/private/is therefore bypassed byGET /private\secret.txt(or/private%5csecret.txt, which decodes to the samer.URL.Path), while the OS still resolves the file, sofile_serverends up serving the protected content.The Windows normalization is now a single shared helper,
normalizeWindowsPath, called by bothMatchPathandMatchPathRE(no duplicated logic). It converts\to/and trims trailing dots/spaces per path component — not only at the end of the whole path — leaving./..forcleanPathto resolve. This also closes the same per-component trailing-dot/space gap that remained in thepathmatcher after #7763.Verified on native Windows 11 (arm64) with a
path_regexp ^/private/guard in front offile_server:GET /private\secret.txt,GET /private%5csecret.txt, andGET /private./secret.txtreturn 200 and leak the fileGET /private/...and public paths are unaffectedTestPathMatcherWindowsandTestPathREMatcherWindowsfail on the unpatched matchers and pass with the fix;go vetclean; cross-compiles for windows/amd64 and windows/arm64Refs #5613, #4407, #7763. Addresses GHSA-c293-7rw2-3gwv (incomplete fix of CVE-2026-52844).
Assistance Disclosure
AI (Anthropic Claude) was used substantially for this PR: it helped identify the missed
path_regexpcall-site, drafted thenormalizeWindowsPathhelper and the regression tests, and ran the dynamic verification on native Windows. I directed the work, reviewed all changes, and verified correctness (Windows 11 arm64: all path/path_regexp Windows tests pass;go vetclean; cross-compiles for windows/amd64 and windows/arm64).