This commit is contained in:
alhuda 2026-06-22 19:28:04 +02:00 committed by GitHub
commit 1aaaebdcc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -640,6 +640,20 @@ func (MatchPath) matchPatternWithEscapeSequence(escapedPath, matchPath string) b
iPattern++
}
// if the pattern was fully consumed before the path, the remaining path
// bytes still have to be part of the string we match against; otherwise a
// pattern with no trailing wildcard (e.g. "/foo%2fbar") would behave like a
// prefix match and incorrectly match longer paths (e.g. "/foo%2fbarbaz").
// the pattern has no more escape hints here, so compare in normalised space.
if iPath < len(escapedPath) {
remaining := escapedPath[iPath:]
if unescaped, err := url.PathUnescape(remaining); err == nil {
sb.WriteString(unescaped)
} else {
sb.WriteString(remaining)
}
}
// we can now treat rawpath globs (%*) as regular globs (*)
matchPath = strings.ReplaceAll(matchPath, "%*", "*")

View file

@ -422,6 +422,21 @@ func TestPathMatcher(t *testing.T) {
input: "/ADMIN%2fPaAzZLm123NEL",
expect: true,
},
{
match: MatchPath{"/foo%2fbar"},
input: "/foo%2fbarbaz",
expect: false,
},
{
match: MatchPath{"/foo%2f"},
input: "/foo%2fx",
expect: false,
},
{
match: MatchPath{"/admin%2fpanel"},
input: "/admin%2fpanelX",
expect: false,
},
} {
err := tc.match.Provision(caddy.Context{})
if err == nil && tc.provisionErr {