Skip to content

Fix scope injection and bypass in token refresh client policy evaluation - #1

Closed
abhiyadav79 wants to merge 1 commit into
mainfrom
fix/53817-refresh-scope-manipulation
Closed

abhiyadav79 wants to merge 1 commit into
mainfrom
fix/53817-refresh-scope-manipulation

Conversation

@abhiyadav79

Copy link
Copy Markdown
Owner

Summary

  • During token refresh, RefreshTokenGrantType was forwarding the raw scope request parameter directly to client policy evaluation without intersecting it with the scopes originally granted in the session.
  • Bug Fix scope injection and bypass in token refresh client policy evaluation #1 (Phantom scope injection): A caller could inject a scope not active in the session to incorrectly trigger client policy executors (e.g. use-lightweight-access-token).
  • Bug more keycloak/keycloak#2 (Active scope bypass): Omitting the scope parameter on refresh silently suppressed client policies for scopes active in the session (violates RFC 6749 §6).

Fix

Verify the refresh token first (to get the session's originally granted scopes), then compute an effective scope before firing client policies:

  • No scope in request → use full session scope (RFC 6749 §6)
  • Scope in request → intersect with session scope (strip injected scopes)

Testing

Added two regression tests in LightWeightAccessTokenTest:

Closes keycloak#53817

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token refresh: Scope filter can be used to manipulate activation of client policies

1 participant