Repository navigation
Recover correct user session when auth session expired - #55269
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The session-recovery change can reject valid browser logins when the identity cookie is missing and cause password grants to fail when a browser cookie belongs to another user.
2 open issues
What changed in this PR
This PR addresses #55149 by recovering the browser’s user session from the identity cookie when the authentication-session root no longer matches it.
Changes:
- Uses identity-cookie validation to recover an unattached user session.
- Adds regression coverage for same-browser email verification followed by a password update, and for expired cookie-and-password login flows.
- Extends test helpers to select required actions and configure login timeouts.
| File | Description |
|---|---|
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/actions/AppInitiatedActionUpdateEmailWithVerificationTest.java |
Tests password updates after same-browser email verification. |
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/actions/AbstractAppInitiatedActionTest.java |
Allows tests to request a specific required action. |
tests/base/src/test/java/org/keycloak/tests/forms/AuthCookieAndPasswordLoginTest.java |
Tests recovery after a cookie-and-password login expires. |
test-framework/builders/src/main/java/org/keycloak/testframework/realm/RealmBuilder.java |
Adds a login-timeout configuration helper. |
services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java |
Replaces root-ID session lookup with identity-cookie recovery. |
Review effort: Balanced
ccb7d56 to
bbaefc2
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A critical session-handling flaw can reuse a deleted authentication root’s ID when SSO expires during reauthentication, bypassing fresh-ID protection and requiring a fix with regression coverage.
1 open issue
2 resolved since last review
Review effort: Balanced
Unreported flaky test detectedIf 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.MultipleTabsLoginTest#testInjectRedirectUriInClientDataAfterAuthSessionExpirationKeycloak CI - Forms IT (chrome) |
Closes keycloak#55149 Signed-off-by: rmartinc <rmartinc@redhat.com>
bbaefc2 to
15d42b6
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The pre-creation guard still checks only the root session ID, allowing first-broker-login to create an account before a divergent identity-cookie session causes rejection; it needs matching session-selection logic and regression coverage.
1 open issue
1 resolved since last review
Review effort: Balanced
pedroigor
left a comment
There was a problem hiding this comment.
LGTM.
The GH copilot comment around brokering is valid but it seems to be a corner case. I agree it can be handled as a separate issue.


Closes #55149
There was a corner case regression in #54688 when auth session is expired. The user session was not correctly selected and the login failed. I can only detect this in update email and using a very specific authentication flow that uses cookie and after that another authenticator (password for example). Tests added for both cases.