Repository navigation
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
Closes keycloak#55149 Signed-off-by: rmartinc <rmartinc@redhat.com>
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) |
| userSession = session.sessions().getUserSession(realm, authSession.getParentSession().getId()); | ||
| // check if user session can be retrieved using cookie | ||
| if (isCookie) { | ||
| AuthenticationManager.AuthResult result = AuthenticationManager.authenticateIdentityCookie(session, realm, true); |
There was a problem hiding this comment.
Now we are attempting a session from the cookie, we should consider checking whether its state is LOGGED_IN.
We have a similar check in TokenManager that throws an exception if it is not the case.
The scenario I have in mind is a session in a state other than LOGGED_IN, for instance, LOGGING_OUT, and this change changes its state back to LOGGED_IN, whereas it should just stop and not accept the session.
Wdyt?
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.