8000 CVE-2026-133537 Fix PathMatcher suffix wildcard ignoring the literal … by sguilhen · Pull Request #55492 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

CVE-2026-133537 Fix PathMatcher suffix wildcard ignoring the literal … - #55492

Open
sguilhen wants to merge 1 commit into
keycloak:mainfrom
sguilhen:55466-pathmatcher-suffix-prefix
Open

sguilhen wants to merge 1 commit into
keycloak:mainfrom
sguilhen:55466-pathmatcher-suffix-prefix

Conversation

@sguilhen
Copy link
Copy Markdown
Contributor

…URI prefix

Closes CVE-2026-133537
Closes #55466

@sguilhen
sguilhen requested a review from a team as a code owner November 24, 2026 18:09
Copilot AI balanced review requested due to automatic review settings November 24, 2026 18:09
@sguilhen
sguilhen commented Nov 24, 2026 •
Copy link
Copy Markdown
Contributor Author

A resource URI using an extension-suffix wildcard, such as "/public/.json", was compared only from the '' onward, so it matched any URI with the same extension whatever its prefix. A request for "/admin/secret.json" resolved to the public resource and was evaluated against its policies instead of the ones guarding /admin.

The fix:

  • exactMatch() now requires the literal prefix as well as the extension, which also covers the scheme and authority of an absolute pattern. This closes the templated case for free: a prefix holding "{id}" no longer matches literally, so "/api/{id}/*.json" is left to the template branch, which already enforces the prefix, rather than matching totally/unrelated/evil.json" through the raw pattern.
  • Trailing "/" and suffix "/.ext" patterns now compete under one specificity rule (longest literal prefix wins) instead of suffix patterns outranking trailing ones structurally. Enforcing the prefix alone was not enough: a broad "/public/.json" still answered for "/public/private/secret.json" over the "/public/private/" resource that guards it.
  • A template is no longer filtered by a segment and parameter count carried over from entries visited earlier in the loop. That made a template's eligibility depend on iteration order, so for "/api/admin/secret" the broad "/api/{a}/{b}" suppressed the narrower "/api/admin/{b}" when it happened to be visited first. Every template that resolves now competes on its own merits.
  • Candidates are ranked by how much of the URI they actually pin down. A parameter matches any segment and so constrains nothing, which means fewer parameters wins and a literal path beats one reached by substituting a parameter: "/api/admin/secret.json" resolves to "/api/admin/" rather than "/api/{id}/.json", and "/admin/secret" to "/admin/secret/*" rather than "/{a}/{b}". Patterns that are duplicates of each other, differing only in parameter names, fall back to a stable tie-break so the choice cannot vary between deployments.

Resolution is now independent of the order resources are visited in. Both call sites build the matcher's path collection from a HashMap, so the previous behaviour could resolve the same request differently from one deployment to the next.

Behavior changes worth noting: a path-only suffix pattern no longer matches an absolute target URI, and "/public/.json" no longer matches the bare prefix "/public". Both align suffix patterns with every other pattern kind. The documented bare form is unaffected - "/.html" has prefix "/", so it still matches "/page.html" and "/some/path/report.html".

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved path-matching specificity defects can select broader authorization resources over more-specific ones, causing the wrong policies to be evaluated.

3 open issues
What changed in this PR

This PR addresses CVE-2026-133537 by tightening Authorization Services URI matching so suffix wildcards respect the full URI pattern rather than just the extension.

Changes:

  • Require suffix-wildcard prefixes to match and introduce unified wildcard specificity ranking.
  • Add unit and UMA integration regression tests for resource selection and normalized URIs.
  • Document matching changes and extend the permission-request test helper.
File Description
tests/​utils-shared/​src/​main/​java/​org/​keycloak/​testsuite/​util/​oauth/​PermissionGrantRequest.java Corrects the fluent return type and adds arbitrary request parameters.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​authz/​services/​uma/​UmaGrantTypeTest.java Adds URI-based permission tests asserting selected resource identities.
docs/​documentation/​upgrading/​topics/​changes/​changes-next-cve-2026-133537.adoc Explains matching compatibility changes and wildcard precedence.
docs/​documentation/​authorization_services/​topics/​resource-create.adoc Documents full-pattern suffix matching and resource selection rules.
common/​src/​test/​java/​org/​keycloak/​common/​util/​PathMatcherTest.java Adds prefix, authority, normalization, and ordering regression tests.
common/​src/​main/​java/​org/​keycloak/​common/​util/​PathMatcher.java Enforces suffix prefixes and revises match ranking.

Review effort: Balanced

@sguilhen
8000 sguilhen force-pushed the 55466-pathmatcher-suffix-prefix branch from 1f42d83 to ea52292 Compare November 24, 2026 19:12
Copilot AI balanced review requested due to automatic review settings November 24, 2026 19:12
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved URI-matching flaws treat request-supplied parameters as wildcards and let catch-all grants override deny policies, potentially granting permissions outside registered templates.

3 open issues
3 resolved since last review

Review effort: Balanced

@sguilhen
sguilhen force-pushed the 55466-pathmatcher-suffix-prefix branch from ea52292 to 6872d18 Compare November 25, 2026 15:11
Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:11
@sguilhen
sguilhen force-pushed the 55466-pathmatcher-suffix-prefix branch from 6872d18 to 0428f54 Compare November 25, 2026 15:12
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The path matcher ignores the fewer-parameters tie-break for equal literal prefixes, allowing a broader template’s policies to override the suffix resource’s policies.

1 open issue
3 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:16
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical PathMatcher specificity errors allow broader routes’ grant policies to override narrower admin resources’ deny policies.

2 open issues

Review effort: Balanced

8BD0
@sguilhen
sguilhen force-pushed the 55466-pathmatcher-suffix-prefix branch 2 times, most recently from 0ef5fb4 to 6c585cf Compare November 25, 2026 16:43
Copilot AI balanced review requested due to automatic review settings November 25, 2026 16:43
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical path-matching flaw interprets request-supplied parameter values as wildcards, allowing an unrelated resource’s grant to override the protecting resource’s deny policy.

1 open issue
2 resolved since last review

Review effort: Balanced

@sguilhen
sguilhen force-pushed the 55466-pathmatcher-suffix-prefix branch from 6c585cf to c7b8ba7 Compare November 25, 2026 17:22
Copilot AI balanced review requested due to automatic review settings November 25, 2026 17:22
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The fix changes authorization precedence across URI pattern types beyond suffix matching, requiring maintainer and security review of compatibility and policy-selection risks.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

…URI prefix

Also take the wildcard a template declares from the registered pattern rather than from its resolved form, so a "*" supplied in a request parameter cannot be read back as one the resource declared.

Closes CVE-2026-133537
Closes keycloak#55466

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
@sguilhen
sguilhen force-pushed the 55466-pathmatcher-suffix-prefix branch from c7b8ba7 to 119c5ca Compare November 25, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CVE-2026-133537] Keycloak 26.8.2 UMA URI suffix matching authorization bypass

2 participants

0