Repository navigation
caddyhttp: Sanitize the path before evaluating path matchers - #4407
Merged
Merged
Conversation
francislavoie
force-pushed
the
path-matching-safety
branch
from
November 8, 2021 20:39
2297aa4 to
f971b11
Compare
mholt
approved these changes
Nov 8, 2021
mholt
left a comment
Member
There was a problem hiding this comment.
Thanks for finding and fixing this. I'm hoping this won't break legitimate use cases, but I'm glad there's a workaround. Will release this today.
francislavoie
added a commit
that referenced
this pull request
Dec 30, 2021
This is a followup to #4407, in response to a report on the forums: https://caddy.community/t/php-fastcgi-phishing-redirection/14542 Turns out that doing `TrimRight` to remove trailing dots, _before_ cleaning the path, will cause double-dots at the end of the path to not be cleaned away as they should. We should instead remove the dots _after_ cleaning.
francislavoie
added a commit
that referenced
this pull request
Dec 30, 2021
This is a followup to #4407, in response to a report on the forums: https://caddy.community/t/php-fastcgi-phishing-redirection/14542 Turns out that doing `TrimRight` to remove trailing dots, _before_ cleaning the path, will cause double-dots at the end of the path to not be cleaned away as they should. We should instead remove the dots _after_ cleaning.
nordstern
pushed a commit
to uptimerobot/caddy
that referenced
this pull request
Jan 24, 2022
This is a followup to caddyserver#4407, in response to a report on the forums: https://caddy.community/t/php-fastcgi-phishing-redirection/14542 Turns out that doing `TrimRight` to remove trailing dots, _before_ cleaning the path, will cause double-dots at the end of the path to not be cleaned away as they should. We should instead remove the dots _after_ cleaning.
mholt
pushed a commit
that referenced
this pull request
Aug 15, 2026
…versal (#7941) * caddyhttp: match url_pattern against decoded, cleaned path The url_pattern matcher evaluated the raw, percent-encoded request URI while path-consuming handlers resolve the decoded, cleaned r.URL.Path. An encoded-slash payload such as "..%2f" stayed a single opaque segment for the WHATWG URLPattern parser, so "/public/..%2fadmin/secret" matched "/public/*" while handlers decoded it to "/admin/secret", bypassing any route-level access control built with url_pattern. Match the same path model handlers resolve: decode the path, normalize and clean it (mirroring the path matcher and #4407), then re-encode through url.URL to a canonical escaped form before running the pattern. The go-urlpattern library is spec-correct; the fix is in the integration. * build(deps): bump github.com/dunglas/go-urlpattern to v1.0.0 Moves off the pseudo-version to the first tagged release.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I found an issue where it's possible to bypass path matchers by crafting a request with a path that doubles up slashes, or uses URL-encoded characters to smuggle the request past the path matcher.
This becomes a security issue, because auth gates using
basicauthcan be bypassed 😬The solution is to unescape (convert URL-encoded characters) then clean the path, before matching.
This could be a breaking change if exact behaviour of the matcher is required (without cleaning the path). In that case, then it's possible to use the
expressionmatcher to do a direct string comparison or regexp on the{http.request.uri.path}placeholder (or simply{path}in the Caddyfile). For example:Example of an exploitable situation:
It's expected that the path matcher
/secret-files*will always requirebobto be authenticated before they're let through to thefile_server. But a request like//secret-files/uh-oh.txtwould punch through unmatched, reachingfile_server. Thefile_serverhandler does clean the path though (collapsing the doubled-up slashes), so it would serve/srv/secret-files/uh-oh.txtback to the client.