8000 Log out other sessions only after the passkey is saved by marsluca · Pull Request #54776 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Log out other sessions only after the passkey is saved - #54776

Open
marsluca wants to merge 1 commit into
keycloak:mainfrom
marsluca:webauthn-register-logout-after-success
Open

marsluca wants to merge 1 commit into
keycloak:mainfrom
marsluca:webauthn-register-logout-after-success

Conversation

@marsluca
@marsluca marsluca commented Nov 6, 2026 •
Copy link
Copy Markdown
Contributor

Closes #54352

WebAuthnRegister.processAction logged out the other sessions before it parsed and verified the attestation, so a failed registration still ended them. I moved the logout to right after createCredential, so it only runs once the passkey is saved. This also covers the passwordless register action, which extends this class.

After the review I did the same in UpdateTotp and UpdatePassword: a duplicate OTP label or a password rejected by the policy also ended the other sessions.

Testing:

  • New test AppInitiatedActionWebAuthnTest#failedSetupWebAuthnKeepsOtherSessions: two sessions, "sign out other devices" checked, and an invalid attestation object, so the server rejects the registration. It checks that both sessions are still there. It fails on main (2 sessions become 1) and passes with the fix. It also runs in AppInitiatedActionPwdLessTest and AppInitiatedActionWebAuthnSkipIfExistsTest.
  • I ran those three classes (13 tests) on headless Chrome, plus the tests/webauthn module (71 tests), locally.
  • New tests RequiredActionTotpSetupTest#failedTotpSetupKeepsOtherSessions (duplicate OTP label) and RequiredActionResetPasswordTest#rejectedPasswordKeepsOtherSessions (password shorter than the policy), both with the sign-out box checked. I ran both classes locally.

AI-assisted (Claude Code).

@marsluca
marsluca requested review from a team as code owners November 6, 2026 15:51
Copilot AI balanced review requested due to automatic review settings November 6, 2026 15:51
Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI 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.

🟡 Changes recommended

A moderate active issue remains because session revocation can occur even when credential creation returns null and no credential is persisted.

1 open issue

Review effort: Lite

@oleksii-udovychenko oleksii-udovychenko 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.

@marsluca, should UpdateTotp get the same move? It has the order this PR fixes in WebAuthnRegister, and I can hit it with a duplicate OTP label.

A user with one session in another browser and an OTP labelled phone sets up a second OTP, also labelled phone, with "Sign out from other devices" checked. The setup fails with "Device already exists with the same name", no second OTP is saved, and the other session is gone. With the box unchecked, the same attempt keeps both sessions.

In UpdateTotp.processAction, logoutOtherSessions runs before CredentialHelper.createOTPCredential, which can still return false or throw ModelDuplicateException. UpdatePassword also logs out before updateCredentialAndGet, which throws ModelException when the password breaks the policy. I only read that one, I didn't run it.

How I tested:

  1. Added three cases to RequiredActionTotpSetupTest on this branch: log in from a second browser, set up an OTP labelled phone, then set up a second OTP through CONFIGURE_TOTP.
  2. Ran them with -Pauth-server-quarkus and printed the session count and the result.
Second OTP Expected Actual
label tablet, sign-out checked (control) saved, other session ended saved, 2 sessions to 1
label phone, sign-out unchecked (control) label error, 2 sessions label error, 2 sessions
label phone, sign-out checked label error, 2 sessions label error, 2 sessions to 1

WebAuthn registration logged out the user's other sessions before it
checked the attestation. When the registration failed, the other
sessions were gone anyway. The logout now runs after the credential
is created.

The OTP setup and the password update had the same order: a duplicate
OTP label or a password rejected by the policy still ended the other
sessions. They now log out after the credential is saved too.

Closes keycloak#54352

Signed-off-by: Luca Marsella <34103646+marsluca@users.noreply.github.com>
@marsluca
marsluca force-pushed the webauthn-register-logout-after-success branch from db680e9 to cfd453e Compare November 12, 2026 08:41
Copilot AI lite review requested due to automatic review settings November 12, 2026 08:41
@marsluca
Copy link
Copy Markdown
Contributor Author

@oleksii-udovychenko good catch, thanks. UpdateTotp and UpdatePassword now log out after the credential is saved too, and I added a test for each (duplicate OTP label, password rejected by the policy).

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

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.

Failed WebAuthn Registration Revokes Other Sessions

3 participants

0