Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove root auth session on first offline_access to prevent cross-user session contamination#46578

Open
federicobartoli wants to merge 1 commit intokeycloak:mainfrom
federicobartoli:fix/offline-access-root-auth-session-cleanup
Open

Remove root auth session on first offline_access to prevent cross-user session contamination#46578
federicobartoli wants to merge 1 commit intokeycloak:mainfrom
federicobartoli:fix/offline-access-root-auth-session-cleanup

Conversation

@federicobartoli
Copy link

Summary

When a user authenticates with scope=offline_access, the FIRST_OFFLINE_ACCESS path removes the online user session but not the associated root authentication session. This leaves the AUTH_SESSION_ID cookie pointing to a still-valid root auth session. If a second user authenticates from the same browser within the session TTL, Keycloak reuses the stale root auth session and creates a new user session with the same ID, allowing the second user to inherit the first user's session.

This PR removes the root authentication session together with the online user session in the FIRST_OFFLINE_ACCESS code path, consistent with backchannel logout and the logout endpoint.

Closes #46239

Changes

  • OAuth2GrantTypeBase.java — After removing the online user session, also remove the root authentication session to prevent AUTH_SESSION_ID cookie reuse
  • OfflineTokenTest.java — Regression test that verifies the root auth session is cleaned up and a second user gets an isolated session

Test plan

  • OfflineTokenTest#offlineTokenCrossUserSessionIsolation passes with the fix
  • Same test fails without the fix (genuine regression detector)
  • Spotless formatting passes
  • Rebased on latest main

…r session contamination

When a user authenticates with scope=offline_access, the FIRST_OFFLINE_ACCESS path removes
the online user session but not the associated root authentication session. This leaves the
AUTH_SESSION_ID cookie pointing to a still-valid root auth session. If a second user
authenticates from the same browser within the session TTL, Keycloak reuses the stale root
auth session and creates a new user session with the same ID, allowing the second user to
inherit the first user's session.

Remove the root authentication session together with the online user session in the
FIRST_OFFLINE_ACCESS code path, consistent with backchannel logout and the logout endpoint.

Closes keycloak#46239

Signed-off-by: Federico Bartoli <[email protected]>
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.

AUTH_SESSION_ID cookie reuse causes cross-user session contamination on re-authentication

2 participants