Repository navigation
Ignore request-supplied kc.* attributes in AuthZen evaluation - #55186
Open
JBoogieman wants to merge 1 commit into
Open
JBoogieman wants to merge 1 commit into
JBoogieman wants to merge 1 commit into
Conversation
JBoogieman
force-pushed
the
53325-authzen-kc-claims
branch
from
November 14, 2026 12:48
580b934 to
2c91d8f
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new tests cover only the overwritten kc.client.id key, leaving broader kc.* reservation enforcement unprotected against regressions through context and resource.properties.
1 open issue
What changed in this PR
This PR addresses #53325 by preventing request-supplied kc.* attributes from influencing AuthZen evaluation context while ensuring client policies use the authenticated caller.
Changes:
- Filter reserved attributes from copies of request context and resource properties for single and batch evaluations.
- Set
kc.client.idfrom the authenticated token and add five client-policy regression tests. - Document the reserved namespace and caller-based client identity.
| File | Description |
|---|---|
| docs/guides/securing-apps/authzen-authorization.adoc | Documents reserved attributes and authenticated-client behavior. |
| authzen/tests/base/src/test/java/org/keycloak/tests/authzen/AuthZenEvaluationTest.java | Adds client-policy fixtures and single/batch spoofing tests. |
| authzen/services/src/main/java/org/keycloak/authorization/authzen/AuthZenResource.java | Filters request-supplied kc.* keys and sets the caller’s client ID. |
Review effort: Balanced
AuthZen evaluation merged context and resource.properties into the policy evaluation context as-is, so a caller could send kc.client.id and impersonate another client towards client policies. Keys in the reserved kc. namespace are now dropped from both maps, and kc.client.id is set from the authenticated token's azp, since DefaultEvaluationContext only sets it for a KeycloakIdentity. Closes keycloak#53325 Signed-off-by: Justin Brueggemann <167224505+JBoogieman@users.noreply.github.com>
JBoogieman
force-pushed
the
53325-authzen-kc-claims
branch
from
November 14, 2026 13:40
2c91d8f to
8e68468
Compare
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.
Closes #53325
Following the approach agreed with @vramik on the issue: strip and set, not strip-only. Stripping alone would leave
kc.client.idabsent, becauseDefaultEvaluationContext.getBaseAttributes()only sets it for aKeycloakIdentity, and AuthZen evaluates withUserModelIdentity/ClientModelIdentity, so client policies would never match.The filter runs on the raw request maps in
evaluateSingle(), so it covers both the single and batch endpoints. It filters a copy becausemergeDefaults()shares the top-level context map across batch items.kc.client.idis set fromtoken.getIssuedFor()after the request values are merged. For aCLIENTsubject this is the same value, since the subject id must already equal the token'sazp.The whole
kc.prefix is reserved rather than only the keys the server currently overwrites. This also closes thekc.client.user_agentcase when the request has noUser-Agentheader, and covers anykc.*attribute added later. Matching is exact and case-sensitive, consistent with howAttributeslooks up names.subject.propertiesis left unchanged. It feeds the subject's identity attributes rather than the evaluation context, and is meant to carry caller-supplied attributes.Tests: seven new cases in
AuthZenEvaluationTest. Five cover the issue's three reproduction steps, the batch endpoint, and a positive case showing a client policy now matches the real caller; with the whole fix removed, four of them fail. Because the server also setskc.client.idafter filtering, those alone don't exercise the filter, so two more sendkc.test.reserved(a reserved key the server never sets) throughcontextandresource.properties, checked by a test-onlyReservedAttributePolicyProviderinauthzen/tests/providers. With only the filter disabled, exactly those two fail. All 123 AuthZen tests pass with the fix, and Spotless is clean.Docs: the "Context and Properties" section of the AuthZen guide now notes that
kc.*keys are reserved and thatkc.client.idis always the authenticated client.AI disclosure: AI was used in the testing of this fix and ensuring there was no regression.