8000 IdP backchannel logout: read sid claim from ID token to support backchannel logout by kfaseela · Pull Request #48674 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

IdP backchannel logout: read sid claim from ID token to support backchannel logout - #48674

Merged
mposolda merged 1 commit into
keycloak:mainfrom
Nordix:fix/idp-backchannel-logout-sid-claim
May 18, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
Nordix:fix/idp-backchannel-logout-sid-claim

Conversation

@kfaseela
@kfaseela kfaseela commented May 4, 2026 •
Copy link
Copy Markdown
Contributor

Fixes #12142

<Fix is as well suggested by @mposolda on the above issue>

Description:

When an external IdP includes a sid claim in the ID token (as required by the OIDC Back-Channel Logout spec), Keycloak was ignoring it and only reading session_state from the token response. This left brokerSessionId as null, causing backchannel logout requests to silently no-op, the session was never found and never terminated.

This fix reads sid from the ID token and prefers it over session_state when setting brokerSessionId. A WARN is logged if both are present but differ.

Manual verification:

Inspired from and updated on top of: #12142 (comment)

  • Setup: Keycloak + navikt/mock-oauth2-server running in Docker, configured to issue sid in the ID token. Realm target federated via the mock IdP.
  • Logged in as a federated user via the mock IdP, entering session-id (which the mock IdP embeds as the sid claim in the ID token, simulating the real-world scenario described in the issue)
  • Confirmed active session visible in the Keycloak Admin UI under Sessions for the user
  • Confirmed broker_session_id = mock-idp.{session-id} in the offline_user_session table (Postgres)
  • Triggered backchannel logout via POST /realms/target/protocol/openid-connect/logout/backchannel-logout with a logout token carrying sid={session-id}
  • Confirmed HTTP 200 response, session gone from the Admin UI, and session row deleted from Postgres
  • Server logs showed corresponding events

(Issue was also reproduced in the same setup without the fix: broker_session_id was NULL in Postgres, backchannel logout returned 200 but the session remained active in the Admin UI.)

@kfaseela
kfaseela requested a review from a team as a code owner May 4, 2026 12:19
Signed-off-by: Faseela K <faseela.k@est.tech>
@keycloak-github-bot keycloak-github-bot Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.BruteForceTest#testNoFailureResetForPermanentLockout

Keycloak CI - Base IT (5)

org.opentest4j.AssertionFailedError: Expected error event ==> expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

@mposolda mposolda 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.

@kfaseela Thanks for the PR.

The OIDCIdentityProviderTest in the services module is not ideal, however I am accepting this since it is very hard to properly test this in automated way due the fact that Keycloak adds the sessionState to the token response.

@mposolda
mposolda merged commit f9e2753 into keycloak:main May 18, 2026
85 checks passed
@stianst stianst mentioned this pull request Jun 1, 2026
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
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.

IdP backchannel logout does not work with session id in logout

3 participants

0