8000 Only disable login submit button on same-tab form submission by edewit · Pull Request #52315 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Only disable login submit button on same-tab form submission - #52315

Open
edewit wants to merge 5 commits into
keycloak:mainfrom
edewit:issue-52056-login-submit-disable
Open

edewit wants to merge 5 commits into
keycloak:mainfrom
edewit:issue-52056-login-submit-disable

Conversation

@edewit
@edewit edewit commented Sep 2, 2026
Copy link
Copy Markdown
Contributor

Summary

  • Fixes login pages leaving the Sign In button permanently disabled when the form is submitted in a new tab/window (e.g. Shift+Enter or Shift+click in Chrome)
  • Replaces inline handlers with a shared disableSubmitOnSameTab.js script that only disables the submit button for same-tab submissions
  • Applies the fix across base and keycloak.v2 login templates, including logout confirm

Closes #52056

Test plan

  • Open the login page and submit with Enter — Sign In button should disable while the request is in flight
  • Open the login page, focus the username field, and press Shift+Enter — auth should open in a new tab and the original tab's Sign In button should remain enabled
  • Shift+click the Sign In button — same as above, original tab stays usable
  • Verify OTP, password-only, username-only, and update-password steps still disable the button on normal submit
  • Verify logout confirm still disables the Logout button on normal submit

Copilot AI balanced review requested due to automatic review settings September 2, 2026 11:09
@edewit
edewit requested review from a team as code owners September 2, 2026 11:09
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

Modifier-click detection, stale keyboard state, and alternate submit-button handling contain functional defects.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates login themes to disable submit buttons only for same-tab submissions, addressing #52056.

Changes:

  • Adds a shared submit-handling module.
  • Migrates base, Keycloak v2, logout, and organization forms from inline handlers.
File summaries
File Description
themes/src/main/resources/theme/keycloak.v2/login/template.ftl Loads the shared module.
themes/src/main/resources/theme/keycloak.v2/login/login.ftl Migrates login form handling.
themes/src/main/resources/theme/keycloak.v2/login/login-username.ftl Migrates username form handling.
themes/src/main/resources/theme/keycloak.v2/login/login-update-password.ftl Migrates password-update handling.
themes/src/main/resources/theme/keycloak.v2/login/login-recovery-authn-code-input.ftl Migrates recovery-code handling.
themes/src/main/resources/theme/keycloak.v2/login/login-password.ftl Migrates password form handling.
themes/src/main/resources/theme/keycloak.v2/login/login-passkeys-conditional-authenticate.ftl Migrates conditional passkey form handling.
themes/src/main/resources/theme/keycloak.v2/login/login-otp.ftl Migrates OTP form handling.
themes/src/main/resources/theme/base/login/template.ftl Loads the shared module.
themes/src/main/resources/theme/base/login/resources/js/disableSubmitOnSameTab.js Implements submission detection and disabling.
themes/src/main/resources/theme/base/login/logout-confirm.ftl Migrates logout confirmation handling.
themes/src/main/resources/theme/base/login/login.ftl Migrates login form handling.
themes/src/main/resources/theme/base/login/login-username.ftl Migrates username form handling.
themes/src/main/resources/theme/base/login/login-update-password.ftl Migrates password-update handling.
themes/src/main/resources/theme/base/login/login-recovery-authn-code-input.ftl Migrates recovery-code handling.
themes/src/main/resources/theme/base/login/login-password.ftl Migrates password form handling.
themes/src/main/resources/theme/base/login/login-passkeys-conditional-authenticate.ftl Migrates conditional passkey form handling.
themes/src/main/resources/theme/base/login/login-otp.ftl Migrates OTP form handling.
testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/resources/theme/organization/login/login.ftl Migrates organization login handling.
testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/resources/theme/organization/login/login-username.ftl Migrates organization username handling.
Review details
  • Files reviewed: 20/20 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 2, 2026 12:00
@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.broker.KcOidcBrokerTest#loginWithExistingUserWithBruteForceEnabled

Keycloak CI - Java Distribution IT (windows-latest - temurin - 17)

org.opentest4j.AssertionFailedError: Expected page 'login-error' to be loaded, but currently on page 'null' after timeout
	at org.keycloak.testsuite.pages.AbstractPage.waitForPage(AbstractPage.java:62)
	at org.keycloak.testsuite.pages.AbstractPage.assertCurrent(AbstractPage.java:47)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.jboss.arquillian.graphene.proxy.GrapheneProxyHandler.invokeReal(GrapheneProxyHandler.java:143)
...

Report flaky test

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 canceled modified click can poison the next normal submission, and the behavior lacks regression coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 20/20 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 2, 2026 15:11
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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.

Copilot AI review requested due to automatic review settings September 3, 2026 05:53
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.

🔵 Needs a closer look

Submitter target precedence is implemented incorrectly, and the browser-specific behavior lacks regression coverage.

Review details

Suppressed comments (2)

themes/src/main/resources/theme/base/login/resources/js/disableSubmitOnSameTab.js:14

  • The form-level target is checked before the submitter override, but HTML gives formtarget on the submitter precedence. A form targeting _blank with a _self submit button will therefore leave that button enabled even though the current tab is submitted.
function opensInNewTab(form, event) {
    if (form.target && form.target !== "_self") {
        return true;
    }

    const submitter = event.submitter;
    if (submitter instanceof HTMLButtonElement || submitter instanceof HTMLInputElement) {
        const formTarget = submitter.formTarget || submitter.getAttribute("formtarget");

themes/src/main/resources/theme/base/login/resources/js/disableSubmitOnSameTab.js:74

  • This browser-event behavior has no automated regression coverage, despite the existing multi-tab login suite in testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/MultipleTabsLoginTest.java. Add coverage for normal submit disabling and modifier-key submit preserving the original tab's enabled button so browser-specific event-order regressions are caught.
    form.addEventListener("submit", (event) => {
        const newTabSubmit = modifierNewTabSubmit || opensInNewTab(form, event);
        modifierNewTabSubmit = false;

        if (newTabSubmit) {
  • Files reviewed: 20/20 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@edewit
edewit force-pushed the issue-52056-login-submit-disable branch from 5fcc2c1 to 5348bdc Compare November 27, 2026 12:29
Copilot AI balanced review requested due to automatic review settings November 27, 2026 12:29
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

@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.client.FAPI1Test#testFAPIAdvancedLoginWithPrivateKeyJWT

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.BadRequestException: HTTP 400 Bad Request
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:236)
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:216)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:59)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
...

Report flaky test

@edewit
edewit force-pushed the issue-52056-login-submit-disable branch from 5348bdc to a91c9db Compare December 4, 2026 14:09
Copilot AI balanced review requested due to automatic review settings December 4, 2026 14:09
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

The early return ignores the submitter’s formtarget override, so a same-tab submission can incorrectly skip disabling the submit button.

1 open issue

Review effort: Balanced

Shift+Enter or modifier-click can submit the login form in a new tab
while the original page stays open. The inline onsubmit handler disabled
the submit button unconditionally, leaving the page stuck with a disabled
Sign In button.

Replace the inline handlers with a shared script that skips disabling
when modifier keys are used or the form targets a new browsing context.

Closes keycloak#52056

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Capture modifier keys from click/keydown events instead of the submitter
element, clear stale keyboard modifier state when Enter does not submit,
and always disable the button named by data-kc-disable-submit.

Closes keycloak#52056

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Reset modifierNewTabSubmit in a microtask when a modified click on a
submit control does not produce a submit event, matching the keydown path.

Closes keycloak#52056

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Guard closest() when the click target is not an Element, defer modifier
flag cleanup with setTimeout to avoid racing submit, verify the named
control is disableable, and honor per-button formtarget overrides.

Closes keycloak#52056

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@edewit
edewit force-pushed the issue-52056-login-submit-disable branch from a91c9db to 6a1facf Compare December 4, 2026 15:04
Copilot AI balanced review requested due to automatic review settings December 4, 2026 15:04
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.

🔵 Needs a closer look

The target check ignores the submitter’s formtarget override, leaving the button enabled for same-tab submissions when the form targets _blank.

1 open issue

Review effort: Balanced

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 16: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.

🔵 Needs a closer look

The browser-event changes lack automated regression tests covering ordinary versus modified Enter/click submissions, including the logout form.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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.

Login page: Shift+Enter in username/email field opens a new login window with disabled "Sign In" button and stale auth flow

2 participants

0