8000 Restart client-initiated registration after the email is verified in another browser by gdsmith · Pull Request #55292 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Restart client-initiated registration after the email is verified in another browser - #55292

Open
gdsmith wants to merge 3 commits into
keycloak:mainfrom
gdsmith:issue-55287-registrations-restart-cookie
Open

gdsmith wants to merge 3 commits into
keycloak:mainfrom
gdsmith:issue-55287-registrations-restart-cookie

Conversation

@gdsmith
@gdsmith gdsmith commented Nov 17, 2026 •
Copy link
Copy Markdown

Closes #55287

Since #47538 (fix for #45568), verifying the email in another browser deliberately removes the original browser's authentication session, so an attacker waiting in that browser can't be logged in once the victim verifies. This PR keeps that and does not restore the 26.6 behaviour of the original browser completing the login. Instead, the original browser restarts to the login page within the client's original authorization request, so a native app still gets a code it can redeem with its PKCE verifier.

The 400 came from the restart cookie: registrations started with /registrations or prompt=create never set KC_RESTART, unlike /auth. buildRegister() now sets it, after APP_INITIATED_FLOW, so an expired registration form restarts to the registration form, the same as a live restart (BrowserButtonsTest.appInitiatedRegistrationWithBackButton).

Once the user is registered, VerifyEmail rewrites the restart cookie to go to the login page. The action is set to AUTHENTICATE explicitly, because the session is in REQUIRED_ACTIONS at that point and would otherwise restart to "page expired". The cookie carries only client notes, no user or aut 8000 h notes, so the restarted browser gets nothing beyond the username the registrant typed. The username is pre-filled from the login_hint client note that RegistrationUserCreation already sets; it is the username rather than the email, which always works on the login form and matches that existing note. This also applies when registration started from the login page.

The restarted login page used to say "Your login attempt timed out", which is wrong here and confusing for a user who has just verified their email. The cookie now also carries a client note marking a registration that is waiting for email verification. When the browser restarts from it and that user's email is verified, the login page shows the existing emailVerifiedMessage as a success message, and no EXPIRED_CODE error event is logged, since nothing expired. The marker is removed on that restart. If the email isn't verified yet (the session expired, or Keycloak restarted), it is still a timeout.

The last commit adds an option Continue as registered user to the Verify Email required action, off by default. With it, the restart sets the registered user on the new authentication session, the same way re-authentication does, so an identity-first flow skips the username step and the combined form asks only for the password. It chooses the same user the pre-filled username would, and only when that user is enabled and has just verified their email; the browser flow still authenticates them as configured. It is opt-in because it changes what the restarted login looks like.

Decisions worth a look: if the session is lost after the user is created but before the verify-email page is shown (e.g. another required action comes first), the restart goes to the registration form rather than the login page. With organizations, the pre-filled username takes the user into identity-first, the same as a client-supplied login_hint. With Continue as registered user, the passkey shortcut in UsernamePasswordForm can't skip the password, because a restarted session has no authenticated credentials yet. The "Always set password on register form" switch never restored the old cross-browser behaviour, so the 26.7.0 upgrade note now says so, and points to the new option. buildForgotCredential() has the same missing restart cookie; I left it out of scope.

Tested with the parameterized tests in RegisterWithEmailVerificationTest, which cover the three registration entry points, combined and identity-first browser flows, and the new option on and off, plus a test that a session lost before the email is verified still restarts as a timeout. Each commit's tests fail without that commit. On the rebased branch I also ran LoginTest, ResetPasswordTest, RefreshTokenTest and AcrAuthFlowTest, which go through the restart-from-cookie path. The first commit was also tested locally with RegisterTest, RequiredActionEmailVerificationTest, MultipleTabsLoginTest, BrowserButtonsTest, AppInitiatedRegistrationTest, OIDCAdvancedRequestParamsTest, RestartCookieTest, OID4VCAuthorizationCodeFlowWithPARTest and the WebAuthn registration tests.

@gdsmith
gdsmith marked this pull request as ready for review November 17, 2026 20:28
@gdsmith
gdsmith requested a review from a team as a code owner November 17, 2026 20:28
Copilot AI balanced review requested due to automatic review settings November 17, 2026 20:28
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.

🟢 Approval recommended

No active review issues are identified for the cross-browser registration restart changes.

No open issues 🎉

What changed in this PR

Fixes #55287 by letting the original registration browser restart at login after email verification in another browser, preserving the client’s authorization request and PKCE parameters without restoring automatic login.

Changes:

  • Sets restart cookies for client-initiated registration and updates them to restart at login once email verification is required.
  • Adds parameterized tests for cross-browser verification, PKCE code redemption, and expired registration sessions.
  • Clarifies that the legacy password-on-registration switch does not restore cross-browser login continuation.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​forms/​RegisterWithEmailVerificationTest.java Tests registration restart behavior across entry points and password configurations.
services/​src/​main/​java/​org/​keycloak/​protocol/​oidc/​endpoints/​AuthorizationEndpoint.java Sets the restart cookie for client-initiated registration.
services/​src/​main/​java/​org/​keycloak/​authentication/​requiredactions/​VerifyEmail.java Updates newly registered users’ restart cookies to return to login.
docs/​documentation/​upgrading/​topics/​changes/​changes-26_7_0.adoc Clarifies cross-browser behavior with the legacy registration switch.

Review effort: Balanced

@gdsmith
gdsmith commented Nov 18, 2026
Copy link
Copy Markdown
Author

@mposolda @rmartinc could one of you take a look when you have a moment? It fixes the 400 "Restart login cookie not found" from #55287, which is a side effect of #47538. It keeps the original browser's session removal but the original browser now restarts to the login page in the client's original authorization request, with the username filled in, instead of hitting the 400.

…another browser

Closes keycloak#55287

Signed-off-by: George McGinley Smith <george@mukuru.com>
…ation restarts after verification in another browser

The restart cookie set while a newly registered user waits for email verification now carries a marker. When the
original browser restarts from it, and the registered user's email has since been verified, the login page shows
"Your email address has been verified." as a success message, instead of the login timeout error and its
EXPIRED_CODE event. A restart before the email is verified is still a timeout.

Closes keycloak#55287

Signed-off-by: George McGinley Smith <george@mukuru.com>
…n another browser

New option "Continue as registered user" on the Verify Email required action, off by default. When a user registers,
then verifies their email in another browser, the login restarted in the browser used for the registration has the
registered user already chosen, so it doesn't ask for the username again. The user still authenticates as the browser
flow requires: with the combined form or the password form, they enter their password.

Closes keycloak#55287

Signed-off-by: George McGinley Smith <george@mukuru.com>
@gdsmith
gdsmith force-pushed the issue-55287-registrations-restart-cookie branch from 2b979ad to 5b8bd39 Compare November 18, 2026 11:24
Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:24
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.

🟢 Approval recommended

No active review issues remain for the registration restart changes following cross-browser email verification.

No open issues 🎉

Review effort: Balanced

@gdsmith
gdsmith commented Nov 18, 2026
Copy link
Copy Markdown
Author

I've rebased onto main and added two commits after trying this end to end in an iOS app. The restarted page said the login had timed out, which reads badly straight after verifying your email, so it now says the email is verified instead. The second is an opt-in Continue as registered user option on Verify Email, so the restart goes straight to the password rather than asking for the username again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes a PR related to a bug team/core-authn

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Since 26.7.0, the original tab can't continue after the verification email is confirmed in another browser (400 "Restart login cookie not found")

3 participants

0