Skip to content

caddyhttp: fix url_pattern authorization bypass via encoded-slash traversal - #7941

Merged
mholt merged 2 commits into
caddyserver:masterfrom
dunglas:fix/url-pattern-encoded-traversal
Aug 15, 2026
Merged

mholt merged 2 commits into
caddyserver:masterfrom
dunglas:fix/url-pattern-encoded-traversal

Conversation

@dunglas

@dunglas dunglas commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator

Advisory: GHSA-m8m5-v4jf-3wcm
Reported by @z3k0sec.

Affected versions

No released version is affected. url_pattern support was added in #7787 and has not been part of a tagged release; the bug only exists on master.

Problem

The http.matchers.url_pattern matcher evaluated the raw, percent-encoded request URI (r.URL.RequestURI()), while every path-consuming handler resolves the decoded, cleaned r.URL.Path. An encoded-slash payload like ..%2f stays a single opaque segment for the WHATWG URLPattern parser, so:

  • /public/..%2fadmin/secret matches an allow-list pattern of /public/*
  • handlers decode %2f to / and resolve /admin/secret

Matcher and handler ran two different path models on the same request, so any route ACL built with url_pattern could be bypassed by an unauthenticated request (file_server, reverse_proxy, php_fastcgi, internal routes).

The classic path matcher is unaffected; it already compares the cleaned, decoded path (#4407).

Fix

Match against the same path model the handlers resolve:

  1. decode via r.URL.Path
  2. normalizeWindowsPath + CleanPath (collapses .. and, per the pattern, doubled slashes, mirroring MatchPath)
  3. re-encode through url.URL to a canonical escaped form before Exec

mergeSlashes is derived once in Provision from the pattern's path part, matching the path matcher's // rule.

The github.com/dunglas/go-urlpattern library is spec-correct: keeping %2F encoded is required by RFC 3986 and matches browser URLPattern behavior. The defect is in the integration, so the fix stays in Caddy. This PR also bumps go-urlpattern from its pseudo-version to the first tagged release, v1.0.0.

Tests

Added regression cases: encoded-slash (..%2f, ..%2F), encoded dots (%2e%2e), raw dots (../), positive re-match on the real decoded target, slash collapsing, empty-segment preservation, and encoded-character decode. Verified against the advisory's live reproduction: all three payloads now return 403, control paths still serve.

Assistance Disclosure

Patched by Claude, reviewed by me.

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 caddyserver#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.
Moves off the pseudo-version to the first tagged release.

@mholt mholt 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.

Noice, thank you!

@mholt

mholt commented Aug 15, 2026

Copy link
Copy Markdown
Member

Hm, I know you have signed our CLA, but it's not showing up at all here. I will go ahead and merge since we know your contribution history already covers that.

@mholt
mholt merged commit 789f60e into caddyserver:master Aug 15, 2026
26 checks passed
@mholt mholt added the bug 🐞 Something isn't working label Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants