Repository navigation
Fix scope injection and bypass in token refresh client policy evaluation - #1
Closed
abhiyadav79 wants to merge 1 commit into
Closed
abhiyadav79 wants to merge 1 commit into
abhiyadav79 wants to merge 1 commit into
Conversation
During token refresh, RefreshTokenGrantType was forwarding the raw scope request parameter directly to client policy evaluation without first intersecting it with the scopes originally granted in the session. This caused two observable problems: 1. Phantom scope injection: a caller could include a scope not active in the session (e.g. use-lightweight-access-token) in the refresh request, causing client policy conditions keyed on that scope to fire and activating executors that should not apply to the session. 2. Active scope bypass: omitting the scope parameter on a refresh request prevented client policy conditions from firing for scopes that were genuinely active in the session, silently suppressing policies that should apply (RFC 6749 §6 requires treating an absent scope as equal to the originally granted scope). Fix: verify the refresh token first to obtain the session's original granted scopes, then compute an effective scope before firing client policies: - If no scope was requested, use the full session scope. - If a scope was requested, intersect it with the session scope to strip any scope not originally granted. Token content (claims, roles, permissions) is not affected as AbstractRefreshTokenProvider already performs scope intersection for token generation; this fix ensures client policy conditions see the same sanitized scope. Closes keycloak#53817 Signed-off-by: Abhishek Yadav <ay798.yadav@gmail.com>
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.
Summary
RefreshTokenGrantTypewas forwarding the rawscoperequest parameter directly to client policy evaluation without intersecting it with the scopes originally granted in the session.use-lightweight-access-token).Fix
Verify the refresh token first (to get the session's originally granted scopes), then compute an effective scope before firing client policies:
Testing
Added two regression tests in
LightWeightAccessTokenTest:testClientScopeConditionPhantomScopeInjectionPrevented— Bug Fix scope injection and bypass in token refresh client policy evaluation #1testClientScopeConditionActiveScopeNotBypassed— Bug more keycloak/keycloak#2Closes keycloak#53817