crbench//

← all cases

Fixing Re-authentication with passkeys

Tier 2 easy java · local · real merged PR from ai-code-review-evaluation/keycloak-greptile #1

Ground-truth defects

d1 · other · medium
ConditionalPasskeysEnabled() called without UserModel parameter
d2 · security · high
With isConditionalPasskeysEnabled(UserModel user) requiring user != null, authenticate(...) will not call webauthnAuth.fillContextForm(context) on the initial login page where context.getUser() is still null, so conditional passkey UI will not be set up for first-time passkey login. Consider whether this should also be enabled when no user has been selected yet so ID-less passkey authentication on the initial login form continues to work.

The change under review

diff (truncated — full diff)
diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java
index 48f6565551..0d4e80a14c 100755
--- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java
+++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java
@@ -55,7 +55,7 @@ public abstract class AbstractUsernameFormAuthenticator extends AbstractFormAuth
     public static final String SESSION_INVALID = "SESSION_INVALID";
 
     // Flag is true if user was already set in the authContext before this authenticator was triggered. In this case we skip clearing of the user after unsuccessful password authentication
-    protected static final String USER_SET_BEFORE_USERNAME_PASSWORD_AUTH = "USER_SET_BEFORE_USERNAME_PASSWORD_AUTH";
+    public static final String USER_SET_BEFORE_USERNAME_PASSWORD_AUTH = "USER_SET_BEFORE_USERNAME_PASSWORD_AUTH";
 
     @Override
     public void action(AuthenticationFlowContext context) {
@@ -219,11 +219,7 @@ public abstract class AbstractUsernameFormAuthenticator extends AbstractFormAuth
         context.getEvent().user(user);
         context.getEvent().error(Errors.INVALID_USER_CREDENTIALS);
 
-        if (isUserAlreadySetBeforeUsernamePasswordAuth(context)) {
-            LoginFormsProvider form = context.form();
-            form.setAttribute(LoginFormsProvider.USERNAME_HIDDEN, true);
-            form.setAttribute(LoginFormsProvider.REGISTRATION_DISABLED, true);
-        }
+        AuthenticatorUtils.setupReauthenticationInUsernamePasswordFormError(context);
 
         Response challengeResponse = challenge(context, getDefaultChallengeMessage(context), FIELD_PASSWORD);
         if(isEmptyPassword) {
diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java
index b8fc0eafd6..91c2a242c9 100755
--- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java
+++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java
@@ -44,7 +44,7 @@ public final class UsernameForm extends UsernamePasswordForm {
 
     @Override
     public void authenticate(AuthenticationFlowContext context) {
-        if (context.getUser() != null) {
+        if (context.getUser() != null && !isConditionalPasskeysEnabled()) {
             // We can skip the form when user is re-authenticating. Unless current user has some IDP set, so he can re-authenticate with that IDP
             if (!this.hasLinkedBrokers(context)) {
                 context.success();
diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java
index 7807ccf5fd..a695819cd7 100755
--- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java
+++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java
@@ -110,10 +110,10 @@ public class UsernamePasswordForm extends AbstractUsernameFormAuthenticator impl
                     formData.add("rememberMe", "on");
                 }
             }
-            // setup webauthn data when the user is not already selected
-            if (webauthnAuth != null && webauthnAuth.isPasskeysEnabled()) {
-                webauthnAuth.fillContextForm(context);
-            }
+        }
+        // setup webauthn data when passkeys enabled
+        if (isConditionalPasskeysEnabled(context.getUser())) {
+            webauthnAuth.fillContextForm(context);
         }
         Response challengeResponse = challenge(context, formData);
         context.challenge(challengeResponse);
@@ -134,8 +134,8 @@ public class UsernamePasswordForm extends AbstractUsernameFormAuthenticator impl
 
     @Override
     protected Response challenge(AuthenticationFlowContext context, String error, String field) {
-        if (context.getUser() == null && webauthnAuth != null && webauthnAuth.isPasskeysEnabled()) {
-            // setup webauthn data when the user is not already selected
+        if (isConditionalPasskeysEnabled(context.getUser())) {
+            // setup webauthn data when possible
             webauthnAuth.fillContextForm(context);
         }
         return super.challenge(context, error, field);
@@ -157,4 +157,8 @@ public class UsernamePasswordForm extends AbstractUsernameFormAuthenticator impl
 
     }
 
+    protected boolean isConditionalPasskeysEnabled(UserModel user) {
+        return webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user != null;
+    }
+
 }
diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java
index f1b53fc2d4..9b421fcb3e 100644
--- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java
+++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java
@@ -97,7 +97,8 @@ public class WebAuthnAuthenticator implements Authenticator, CredentialValidator
 
         UserModel user = context.getUser();
         boolean isUserIdentified = false;
-        if (user != null) {
+
+        if (shouldShowWebAuthnAuthenticators(context)) {
             // in 2 Factor Scenario where the user has already been identified
             WebAuthnAuthenticatorsBean authenticators = new WebAuthnAuthenticatorsBean(context.getSession(), context.getRealm(), user, getCredentialType());
             if (authenticators.getAuthenticators().isEmpty()) {
@@ -120,6 +121,14 @@ public class WebAuthnAuthenticator implements Authenticator, CredentialValidator
         return form;
     }
 
+    /**
+     * @param context authentication context
+     * @return true if the available webauthn authenticators should be shown on the screen. Typically during 2-factor authentication for example
+     */
+    protected boolean shouldShowWebAuthnAuthenticators(AuthenticationFlowContext context) {
+        return context.getUser() != null;
+    }
+
     protected WebAuthnPolicy getWebAuthnPolicy(AuthenticationFlowContext context) {
         return context.getRealm().getWebAuthnPolicy();
     }
diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnConditionalUIAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnConditionalUIAuthenticator.java
index 6f4578d5ce..3f94338b08 100644
--- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnConditionalUIAuthenticator.java
+++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnConditionalUIAuthenticator.java
@@ -20,6 +20,7 @@ import jakarta.ws.rs.core.Response;
 import java.util.function.Function;
 import org.keycloak.WebAuthnConstants;
 import org.keycloak.authentication.AuthenticationFlowContext;
+import org.keycloak.authentication.authenticators.util.AuthenticatorUtils;
 import org.keycloak.common.Profile;
 import org.keycloak.forms.login.LoginFormsProvider;
 import org.keycloak.models.KeycloakSession;
@@ -48,6 +49,9 @@ public class WebAuthnConditionalUIAuthenticator extends WebAuthnPasswordlessAuth
         // the passkey failed, show error and maintain passkeys
         context.form().setError(errorCase, "");
         context.form().setAttribute(WebAuthnConstants.ENABLE_WEBAUTHN_CONDITIONAL_UI, Boolean.TRUE);
+
+        AuthenticatorUtils.setupReauthenticationInUsernamePasswordFormError(context);
+
         fillContextForm(context);
         return errorChallenge.apply(context);
     }
@@ -56,4 +60,9 @@ public class WebAuthnConditionalUIAuthenticator extends WebAuthnPasswordlessAuth
         return Profile.isFeatureEnabled(Profile.Feature.PASSKEYS) &&
                 Boolean.TRUE.equals(session.getContext().getRealm().getWebAuthnPolicyPasswordless().isPasskeysEnabled());
     }
+
+    // Do not show authenticators during login with conditional passkeys (For example during username/password)
+    protected boolean shouldShowWebAuthnAuthenticators(AuthenticationFlowContext context) {
+        return false;
+    }
 }
diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/util/AuthenticatorUtils.java b/services/src/main/java/org/keycloak/authentication/authenticators/util/AuthenticatorUtils.java
index 0d140f1a32..8e2bfe8f62 100644
--- a/services/src/main/java/org/keycloak/authentication/authenticators/util/AuthenticatorUtils.java
+++ b/services/src/main/java/org/keycloak/authentication/authenticators/util/AuthenticatorUtils.java
@@ -23,6 +23,7 @@ import org.keycloak.authentication.AuthenticationFlowContext;
 import org.keycloak.common.util.Time;
 import org.keycloak.credential.hash.PasswordHashProvider;
 import org.keycloak.events.Errors;
+import org.keycloak.forms.login.LoginFormsProvider;
 import org.keycloak.models.*;
 import org.keycloak.services.managers.BruteForceProtector;
 import org.keycloak.sessions.AuthenticationSessionModel;
@@ -31,6 +32,8 @@ import org.keycloak.util.JsonSerialization;
 import java.io.IOException;
 import java.util.Map;
 
+import static org.keycloak.authentication.authenticators.browser.AbstractUsernameFormAuthenticator.USER_SET_BEFORE_USERNAME_PASSWORD_AUTH;
+
 /**
  * @author Vaclav Muzikar <vmuzikar@redhat.com>
  */
@@ -116,4 +119,17 @@ public final class AuthenticatorUtils {
             throw new IllegalStateException(e);
         }
     }
+
+
+    // Make sure that form is setup for "re-authentication" rather than regular authentication if some error happens during re-authentication
+    public static void setupReauthenticationInUsernamePasswordFormError(AuthenticationFlowContext context) {
+        String userAlreadySetBeforeUsernamePasswordAuth = context.getAuthenticationSession().getAuthNote(USER_SET_BEFORE_USERNAME_PASSWORD_AUTH);
+
+        if (Boolean.parseBoolean(userAlreadySetBeforeUsernamePasswordAuth)) {
+            LoginFormsProvider form = context.form();
+            form.setAttribute(LoginFormsProvider.USERNAME_HIDDEN, true);
+            form.setAttribute(LoginFormsProvider.REGISTRATION_DISABLED, true);
+        }
+    }
+
 }
diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysOrganizationAuthenticationTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysOrganizationAuthenticationTest.java
index 123bd3b493..007c4df7db 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysOrganizationAuthenticationTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysOrganizationAuthenticationTest.java
@@ -32,6 +32,7 @@ import org.keycloak.models.Constants;
 import org.keycloak.models.credential.WebAuthnCredentialModel;
 import org.keycloak.models.utils.KeycloakModelUtils;
 import org.keycloak.organization.authentication.authenticators.browser.OrganizationAuthenticatorFactory;
+import org.keycloak.protocol.oidc.OIDCLoginProtocol;
 import org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation;
 import org.keycloak.representations.idm.AuthenticatorConfigRepresentation;
 import org.keycloak.representations.idm.OrganizationDomainRepresentation;
@@ -193,10 +194,10 @@ public class PasskeysOrganizationAuthenticationTest extends AbstractWebAuthnVirt
             MatcherAssert.assertThat(driver.findElement(By.xpath("//form[@id='webauth']")), Matchers.notNullValue());
             loginPage.loginUsername(USERNAME);
 
-            // now the passkeys username password page should be presented with username selected and passkeys disabled
+            // now the passkeys username password page should be presented with username selected. Passkeys still enabled
             loginPage.assertCurrent();
             MatcherAssert.assertThat(loginPage.getAttemptedUsername(), Matchers.is("userwebauthn"));
-            Assert.assertThrows(NoSuchElementException.class, () -> driver.findElement(By.xpath("//form[@id='webauth']")));
+            MatcherAssert.assertThat(driver.findElement(By.xpath("//form[@id='webauth']")), Matchers.notNullValue());
             loginPage.login("invalid-password");
             loginPage.assertCurrent();
             MatcherAssert.assertThat(loginPage.getPasswordInputError(), Matchers.is("Invalid password."));
@@ -207,7 +208,7 @@ public class PasskeysOrganizationAuthenticationTest extends AbstractWebAuthnVirt
 
             // correct login now
             MatcherAssert.assertThat(loginPage.getAttemptedUsername(), Matchers.is("userwebauthn"));
-            Assert.assertThrows(NoSuchElementException.class, () -> driver.findElement(By.xpath("//form[@id='webauth']")));
+            MatcherAssert.assertThat(driver.findElement(By.xpath("//form[@id='webauth']")), Matchers.notNullValue());
             loginPage.login(getPassword(USERNAME));
             appPage.assertCurrent();
             events.expectLogin()
@@ -263,4 +264,59 @@ public class PasskeysOrganizationAuthenticationTest extends AbstractWebAuthnVirt
             logout();
         }
     }
+
+    // Test users is able to authenticate with passkey during re-authentication (for example when OIDC parameter prompt=login is used)
+    @Test
+    public void webauthnLoginWithDiscoverableKey_reauthentication() throws IOException {
+        getVirtualAuthManager().useAuthenticator(DefaultVirtualAuthOptions.PASSKEYS.getOptions());
+
+        // set passwordless policy for discoverable keys
+        try (Closeable c = getWebAuthnRealmUpdater()
+                .setWebAuthnPolicyRpEntityName("localhost")
+                .setWebAuthnPolicyRequireResidentKey(Constants.WEBAUTHN_POLICY_OPTION_YES)
+                .setWebAuthnPolicyUserVerificationRequirement(Constants.WEBAUTHN_POLICY_OPTION_REQUIRED)
+                .setWebAuthnPolicyPasskeysEnabled(Boolean.TRUE)
+                .update()) {
+
+            checkWebAuthnConfiguration(Constants.WEBAUTHN_POLICY_OPTION_YES, Constants.WEBAUTHN_POLICY_OPTION_REQUIRED);
+
+            registerDefaultUser();
+
+            UserRepresentation user = userResource().toRepresentation();
+            MatcherAssert.assertThat(user, Matchers.notNullValue());
+
+            logout();
+            events.clear();
+
+            // the user should be automatically logged in using the discoverable key
+            oauth.openLoginForm();
+            WaitUtils.waitForPageToLoad();
+
+            appPage.assertCurrent();
+
+            events.expectLogin()
+                    .user(user.getId())
+                    .detail(Details.USERNAME, user.getUsername())
+                    .detail(Details.CREDENTIAL_TYPE, WebAuthnCredentialModel.TYPE_PASSWORDLESS)
+                    .detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true")
+                    .assertEvent();
+
+            // Re-authentication now with prompt=login. Passkeys login should be possible.
+            oauth.loginForm()
+                    .prompt(OIDCLoginProtocol.PROMPT_VALUE_LOGIN)
+                    .open();
+            WaitUtils.waitForPageToLoad();
+
+            appPage.assertCurrent();
+
+            events.expectLogin()
+                    .user(user.getId())
+                    .detail(Details.USERNAME, user.getUsername())
+                    .detail(Details.CREDENTIAL_TYPE, WebAuthnCredentialModel.TYPE_PASSWORDLESS)
+                    .detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true")
+                    .assertEvent();
+
+            logout();
+        }
+    }
 }
diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java
index aa7e4d8166..82faa8572d 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java
@@ -34,6 +34,7 @@ import org.keycloak.models.AuthenticationExecutionModel;
 import org.keycloak.models.Constants;
 import org.keycloak.models.credential.PasswordCredentialModel;
 import org.keycloak.models.credential.WebAuthnCredentialModel;
+import org.keycloak.protocol.oidc.OIDCLoginProtocol;
 import org.keycloak.representations.idm.AuthenticationExecutionExportRepresentation;
 import org.keycloak.representations.idm.AuthenticationFlowRepresentation;
 import org.keycloak.representations.idm.CredentialRepresentation;
@@ -254,4 +255,68 @@ public class PasskeysUsernameFormTest extends AbstractWebAuthnVirtualTest {
             logout();
         }
     }
+
+    // Test that user is able to authenticate with passkeys even during re-authentication (For example when OIDC parameter prompt=login is used)
+    @Test
+    public void webauthnLoginWithDiscoverableKey_reauthentication() throws IOException {
+        getVirtualAuthManager().useAuthenticator(DefaultVirtualAuthOptions.PASSKEYS.getOptions());
+
+        // set passwordless policy for discoverable keys
+        try (Closeable c = getWebAuthnRealmUpdater()
+                .setWebAuthnPolicyRpEntityName("localhost")
+                .setWebAuthnPolicyRequireResidentKey(Constants.WEBAUTHN_POLICY_OPTION_YES)
+                .setWebAuthnPolicyUserVerificationRequirement(Constants.WEBAUTHN_POLICY_OPTION_REQUIRED)
+                .setWebAuthnPolicyPasskeysEnabled(Boolean.TRUE)
+                .update()) {
+
+            checkWebAuthnConfiguration(Constants.WEBAUTHN_POLICY_OPTION_YES, Constants.WEBAUTHN_POLICY_OPTION_REQUIRED);
+
+            registerDefaultUser();
+
+            UserRepresentation user = userResource().toRepresentation();
+            MatcherAssert.assertThat(user, Matchers.notNullValue());
+
+            logout();
+
+            // remove the password, so passkeys are the only credential in the user
+            final CredentialRepresentation passwordCredRep = userResource().credentials().stream()
+                    .filter(cred -> PasswordCredentialModel.TYPE.equals(cred.getType()))
+                    .findAny()
+                    .orElse(null);
+            Assert.assertNotNull("User has no password credential", passwordCredRep);
+            userResource().removeCredential(passwordCredRep.getId());
+
+            events.clear();
+
+            // the user should be automatically logged in using the discoverable key
+            oauth.openLoginForm();
+            WaitUtils.waitForPageToLoad();
+
+            appPage.assertCurrent();
+
+            events.expectLogin()
+                    .user(user.getId())
+                    .detail(Details.USERNAME, user.getUsername())
+                    .detail(Details.CREDENTIAL_TYPE, WebAuthnCredentialModel.TYPE_PASSWORDLESS)
+                    .detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true")
+                    .assertEvent();
+
+            // Re-authentication now with prompt=login. Passkeys login should be possible.
+            oauth.loginForm()
+                    .prompt(OIDCLoginProtocol.PROMPT_VALUE_LOGIN)
+                    .open();
+            WaitUtils.waitForPageToLoad();
+
+            appPage.assertCurrent();
+
+            events.expectLogin()
+                    .user(user.getId())
+                    .detail(Details.USERNAME, user.getUsername())
+                    .detail(Details.CREDENTIAL_TYPE, WebAuthnCredentialModel.TYPE_PASSWORDLESS)
+                    .detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true")
+                    .assertEvent();
+
+            logout();
+        }
+    }
 }
diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java
index 9af2787ec2..e089a9e875 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java
+++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java
@@ -23,6 +23,7 @@ import java.util.List;
 import org.hamcrest.MatcherAssert;
 import org.hamcrest.Matchers;
 import org.jboss.arquillian.graphene.page.Page;
+import org.junit.Assert;
 import org.junit.Test;
 import org.keycloak.WebAuthnConstants;
 import org.keycloak.authentication.authenticators.browser.UsernamePasswordFormFactory;
@@ -31,10 +32,13 @@ import org.keycloak.events.Details;
 import org.keycloak.events.Errors;
 import org.keycloak.events.EventType;
 import org.keycloak.models.Constants;
+import org.keycloak.models.credential.PasswordCredentialModel;
 import org.keycloak.models.credential.WebAuthnCredentialModel;
+import org.keycloak.protocol.oidc.OIDCLoginProtocol;
 import org.keycloak.representations.idm.RealmRepresentation;
 import org.keycloak.representations.idm.UserRepresentation;
 import org.keycloak.testsuite.admin.AbstractAdminTest;
+import org.keycloak.testsuite.admin.ApiUtil;
 import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
 import org.keycloak.testsuite.arquillian.annotation.IgnoreBrowserDriver;
 import org.keycloak.testsuite.pages.SelectOrganizationPage;
@@ -44,6 +48,10 @@ import org.keycloak.testsuite.webauthn.authenticators.DefaultVirtualAuthOptions;
 import org.openqa.selenium.By;
 import org.openqa.selenium.firefox.FirefoxDriver;
 
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 /**
  *
  * @author rmartinc
@@ -62,6 +70,7 @@ public class PasskeysUsernamePasswordFormTest extends AbstractWebAuthnVirtualTes
         makePasswordlessRequiredActionDefault(realmRepresentation);
         switchExecutionInBrowserFormToProvider(realmRepresentation, UsernamePasswordFormFactory.PROVIDER_ID);
 
+        configureTestRealm(realmRepresentation);
         testRealms.add(realmRepresentation);
     }
 
@@ -140,7 +149,7 @@ public class PasskeysUsernamePasswordFormTest extends AbstractWebAuthnVirtualTes
             loginPage.login(USERNAME, "invalid-password");
             loginPage.assertCurrent();
             MatcherAssert.assertThat(loginPage.getUsernameInputError(), Matchers.is("Invalid username or password."));
-            MatcherAssert.assertThat(loginPage.getPasswordInputError(), Matchers.nullValue());
+            MatcherAssert.assertThat(loginPage.getPasswordInputError(), nullValue());
             events.expect(EventType.LOGIN_ERROR)
                     .detail(Details.USERNAME, USERNAME)
                     .error(Errors.INVALID_USER_CREDENTIALS)
@@ -153,8 +162,10 @@ public class PasskeysUsernamePasswordFormTest extends AbstractWebAuthnVirtualTes
             events.expectLogin()
                     .user(user.getId())
                     .detail(Details.USERNAME, USERNAME)
-                    .detail(Details.CREDENTIAL_TYPE, Matchers.nullValue())
+                    .detail(Details.CREDENTIAL_TYPE, nullValue())
                     .assertEvent();
+
+            logout();
         }
     }
 
@@ -163,14 +174,174 @@ public class PasskeysUsernamePasswordFormTest extends AbstractWebAuthnVirtualTes
         // use a default resident key which is not shown in conditional UI
         getVirtualAuthManager().useAuthenticator(DefaultVirtualAuthOptions.DEFAULT_RESIDENT_KEY.getOptions());
 
+        // set passwordless policy for discoverable keys
+        try (Closeable c = setPasswordlessPolicyForExternalKey()) {
+
+            checkWebAuthnConfiguration(Constants.WEBAUTHN_POLICY_OPTION_YES, Constants.WEBAUTHN_POLICY_OPTION_REQUIRED);
+
+            registerDefaultUser();
+
+            UserRepresentation user = userResource().toRepresentation();
+            MatcherAssert.assertThat(user, Matchers.notNullValue());
+
+            logout();
+            events.clear();
+
+            // open login page, the key is not internal so not opened by default
+            oauth.openLoginForm();
+            WaitUtils.waitForPageToLoad();
+
+            loginPage.assertCurrent();
+            MatcherAssert.assertThat(loginPage.getUsernameAutocomplete(), Matchers.is("username webauthn"));
+            MatcherAssert.assertThat(driver.findElement(By.xpath("//form[@id='webauth']")), Matchers.notNullValue());
+
+            // force login using webauthn link
+            webAuthnLoginPage.clickAuthenticate();
+            appPage.assertCurrent();
+
+            events.expectLogin()
+                    .user(user.getId())
+                    .detail(Details.USERNAME, user.getUsername())
+                    .detail(Details.CREDENTIAL_TYPE, WebAuthnCredentialModel.TYPE_PASSWORDLESS)
+                    .detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true")
+                    .assertEvent();
+            logout();
+        }
+    }
+
+
+    // Test users is able to authenticate with passkey during re-authentication (for example when OIDC parameter prompt=login is used)
+    @Test
+    public void webauthnLoginWithExternalKey_reauthentication() throws Exception {
+        // use a default resident key which is not shown in conditional UI
+        getVirtualAuthManager().useAuthenticator(DefaultVirtualAuthOptions.DEFAULT_RESIDENT_KEY.getOptions());
+
+        // set passwordless policy for discoverable keys
+        try (Closeable c = setPasswordlessPolicyForExternalKey()) {
+
+            checkWebAuthnConfiguration(Constants.WEBAUTHN_POLICY_OPTION_YES, Constants.WEBAUTHN_POLICY_OPTION_REQUIRED);
+
+            registerDefaultUser();
+
+            UserRepresentation user = userResource().toRepresentation();
+            MatcherAssert.assertThat(user, Matchers.notNullValue());
+
+            logout();
+            events.clear();
+
+            // open login page, the key is not internal so not opened by default
+            oauth.openLoginForm();
+            WaitUtils.waitForPageToLoad();
+
+            loginPage.assertCurrent();
+            MatcherAssert.assertThat(loginPage.getUsernameAutocomplete(), Matchers.is("username webauthn"));
+            MatcherAssert.assertThat(driver.findElement(By.xpath("//form[@id='webauth']")), Matchers.notNullValue());
+
+            // force login using webauthn link
+            webAuthnLoginPage.clickAuthenticate();
+            appPage.assertCurrent();
+
+            events.expectLogin()
+                    .user(user.getId())
+                    .detail(Details.USERNAME, user.getUsername())
+                    .detail(Details.CREDENTIAL_TYPE, WebAuthnCredentialModel.TYPE_PASSWORDLESS)
+                    .detail(WebAuthnConstants.USER_VERIFICATION_CHECKED, "true")
+                    .assertEvent();
+
+            // Re-authentication now with prompt=login. Passkeys login should be possible.
+            oauth.loginForm()
+                    .prompt(OIDCLoginProtocol.PROMPT_VALUE_LOGIN)

Leaderboard for this case

easy · 6 of 9 bots fully caught it (67% solve rate) · 83% avg coverage.

#BotResultCaughtCoverageFindingsFalse alarms
1 Claude Code (Opus 5.5) solved 2/2 100.0% 3 0
2 Drape (Deep Review) solved 2/2 100.0% 3 0
3 greptile solved 2/2 100.0% 2 0
4 Mjolnir (Opus 5.5) solved 2/2 100.0% 4 0
5 Mjolnir (Sonnet 5.5) solved 2/2 100.0% 4 0
6 qodo solved 2/2 100.0% 3 0
7 Cubic partial 1/2 66.7% 3 0
8 cursor partial 1/2 66.7% 1 0
9 Drape (Review) partial 1/2 66.7% 1 0

Bot results

Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ off by one
d2 high ✓ exact
valid · matches d1 · impact medium
valid · matches d2 · impact high
valid · impact low
The new `isConditionalPasskeysEnabled(user)` only checks that passkeys are enabled for the realm and that a user is set. It never checks whether that user has a passwordless WebAuthn credential. So during re-authentication, a user with no passkey still gets the passkey UI and `fillContextForm`. The finding overstates the harm: the password field is still on the form, so the user is not stuck. The effect is a passkey option that cannot succeed for them. The new test `reauthenticationOfUserWithoutPasskey` turns passkeys off for the whole realm, so it does not cover this case. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
`isConditionalPasskeysEnabled()` is called with no arguments, but the only definition is `UsernamePasswordForm.isConditionalPasskeysEnabled(UserModel)`. There is no no-arg overload, so this file will not compile and the services module build fails. It should probably pass `context.getUser()`.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161
`isConditionalPasskeysEnabled` requires `user != null`, which reverses the old behavior. Before this change, webauthn/passkey data was filled exactly when no user was selected yet (`context.getUser() == null`). Now `fillContextForm` only runs after a user is already known, so conditional-UI passkey login on the normal first login screen (no user yet) is never set up, in both `authenticate()` and the error `challenge()`. The condition should allow `user == null`, and probably also allow a known user who has a passkey credential configured, e.g. `user == null || user.credentialManager().isConfiguredFor(webauthnAuth.getCredentialType())`.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161
During re-authentication, passkey conditional UI is now enabled for any user who is already set, without checking that the user actually has a webauthn-passwordless credential. Users with no passkey get a passkey challenge they cannot complete, and the form shows passkey UI that does not apply to them. The check should confirm the user has the credential type configured.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
d2 high ✓ exact
valid · matches d2 · impact high
valid · impact low
The old code called the protected, overridable isUserAlreadySetBeforeUsernamePasswordAuth(context). The new static utility reads the auth note directly, so a subclass that overrides that hook no longer affects whether the form is set up for re-authentication. I searched the repo and found no class that overrides the method, so this only affects third-party extensions of a public SPI class. The impact is low. [grounded: diff] [consensus 5/5: valid=5]
minor
This asks for duplicated test setup to be moved into a helper. It does not claim the code misbehaves, so it is a style preference. [consensus 5/5: minor=5]
raw comments (4)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161
<!-- cubic:v=d06d9c1b-a657-4527-95a9-8735f1be3b67 --> <!-- cubic:review-run=2c141132-56b3-5dde-9b71-675c2cb53db2 --> <!-- metadata:{"confidence":10} --> P1: When the initial browser login has no selected user, this predicate is false, so `fillContextForm` never enables the conditional-passkey form. Preserve the anonymous-user path by checking `user == null` here. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java, line 161: <comment>When the initial browser login has no selected user, this predicate is false, so `fillContextForm` never enables the conditional-passkey form. Preserve the anonymous-user path by checking `user == null` here.</comment> <file context> @@ -157,4 +157,8 @@ public void close() { } + protected boolean isConditionalPasskeysEnabled(UserModel user) { + return webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user != null; + } + </file context> ``` </details> ```suggestion return webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user == null; ```
services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java:222
<!-- cubic:v=ccd2ab76-13c7-41cc-9b01-71cad1e59e24 --> <!-- cubic:review-run=2c141132-56b3-5dde-9b71-675c2cb53db2 --> <!-- metadata:{"confidence":7} --> P2: When a custom authenticator overrides `isUserAlreadySetBeforeUsernamePasswordAuth`, this call bypasses that override and can render a failed reauthentication form as a normal login. Preserve the polymorphic check here or pass its result into the utility. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java, line 222: <comment>When a custom authenticator overrides `isUserAlreadySetBeforeUsernamePasswordAuth`, this call bypasses that override and can render a failed reauthentication form as a normal login. Preserve the polymorphic check here or pass its result into the utility.</comment> <file context> @@ -219,11 +219,7 @@ private boolean badPasswordHandler(AuthenticationFlowContext context, UserModel - form.setAttribute(LoginFormsProvider.USERNAME_HIDDEN, true); - form.setAttribute(LoginFormsProvider.REGISTRATION_DISABLED, true); - } + AuthenticatorUtils.setupReauthenticationInUsernamePasswordFormError(context); Response challengeResponse = challenge(context, getDefaultChallengeMessage(context), FIELD_PASSWORD); </file context> ``` </details>
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java:261
<!-- cubic:v=dae09d60-6c91-4462-a144-dfac63497450 --> <!-- cubic:review-run=2c141132-56b3-5dde-9b71-675c2cb53db2 --> <!-- metadata:{"confidence":7} --> P3: This method near-verbatim duplicates `webauthnLoginWithDiscoverableKey` in the same file (identical setup, register, password removal, first login assertions) and the full `webauthnLoginWithDiscoverableKey_reauthentication` already present in `PasskeysOrganizationAuthenticationTest`, differing only by removing the password so passkeys are the sole credential. The duplicated block makes future adjustments to the passkeys/register/setup code need to be applied in multiple places. If the password-removal scenario is the point, factor the shared steps into a helper rather than copying the whole body. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java, line 261: <comment>This method near-verbatim duplicates `webauthnLoginWithDiscoverableKey` in the same file (identical setup, register, password removal, first login assertions) and the full `webauthnLoginWithDiscoverableKey_reauthentication` already present in `PasskeysOrganizationAuthenticationTest`, differing only by removing the password so passkeys are the sole credential. The duplicated block makes future adjustments to the passkeys/register/setup code need to be applied in multiple places. If the password-removal scenario is the point, factor the shared steps into a helper rather than copying the whole body.</comment> <file context> @@ -254,4 +255,68 @@ public void passwordLoginWithExternalKey() throws Exception { + + // Test that user is able to authenticate with passkeys even during re-authentication (For example when OIDC parameter prompt=login is used) + @Test + public void webauthnLoginWithDiscoverableKey_reauthentication() throws IOException { + getVirtualAuthManager().useAuthenticator(DefaultVirtualAuthOptions.PASSKEYS.getOptions()); + </file context> ``` </details>
PR-level
<!-- cubic:review-summary:start --> **3 issues found** across 9 files <!-- cubic:review-summary:end --> <details> <summary>Prompt for AI agents (unresolved issues)</summary> ```text Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately. <file name="services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java"> <violation number="1" location="services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161"> P1: When the initial browser login has no selected user, this predicate is false, so `fillContextForm` never enables the conditional-passkey form. Preserve the anonymous-user path by checking `user == null` here.</violation> </file> <file name="services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java"> <violation number="1" location="services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java:222"> P2: When a custom authenticator overrides `isUserAlreadySetBeforeUsernamePasswordAuth`, this call bypasses that override and can render a failed reauthentication form as a normal login. Preserve the polymorphic check here or pass its result into the utility.</violation> </file> <file name="testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java"> <violation number="1" location="testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java:261"> P3: This method near-verbatim duplicates `webauthnLoginWithDiscoverableKey` in the same file (identical setup, register, password removal, first login assertions) and the full `webauthnLoginWithDiscoverableKey_reauthentication` already present in `PasskeysOrganizationAuthenticationTest`, differing only by removing the password so passkeys are the sole credential. The duplicated block makes future adjustments to the passkeys/register/setup code need to be applied in multiple places. If the password-removal scenario is the point, factor the shared steps into a helper rather than copying the whole body.</violation> </file> ``` </details> <sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/57/ai_pr_review_github_delivery_4f7a126056ef80095963079b975cf34d6857ddc8f3d6c9b27585a5a4b1cd01bc?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F57)</sub> <!-- cubic:review-post:ai_pr_review_github_delivery_4f7a126056ef80095963079b975cf34d6857ddc8f3d6c9b27585a5a4b1cd01bc:f01f8cb5835a684f90efb6a7504d59c1c5b85bba:2c141132-56b3-5dde-9b71-675c2cb53db2 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
d2 high ✓ exact
valid · matches d2 · impact high
raw comments (2)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:162
### Passkeys skipped on initial login **High Severity** <!-- DESCRIPTION START --> `isConditionalPasskeysEnabled` now requires a non-null `user`, so `fillContextForm` no longer runs on the initial login page or after a failed password when the user is not in context. Conditional passkeys UI was previously set up precisely when the user was unidentified. Existing login tests still expect the WebAuthn form on first paint, and discoverable-key auto-login depends on that setup. <!-- DESCRIPTION END --> <!-- BUGBOT_BUG_ID: 084e4941-c6a7-4d7c-a8f0-08f2ce9dc6cc --> <!-- LOCATIONS START services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L159-L162 services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L113-L117 services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L135-L140 LOCATIONS END --> <details> <summary>Additional Locations (2)</summary> - [`services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L113-L117`](https://github.com/drape-io/crbench-cursor-2026-09/blob/4f104536b16bfe5c0745a2061c11cbcf3a440866/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L113-L117) - [`services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L135-L140`](https://github.com/drape-io/crbench-cursor-2026-09/blob/4f104536b16bfe5c0745a2061c11cbcf3a440866/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java#L135-L140) </details> <div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjA1MmM0NTM3LWI4NzEtNGYxZC1hM2E4LTUxNjlmZGZhZWZkMiIsImVuY3J5cHRpb25LZXkiOiJweFhIOUFEQ1dscExYRDlhZ1FBVGszUFhoQXkyeFZPR3VYdGo2bG9UQThrIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstZ3JlcHRpbGUtMSIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjA1MmM0NTM3LWI4NzEtNGYxZC1hM2E4LTUxNjlmZGZhZWZkMiIsImVuY3J5cHRpb25LZXkiOiJweFhIOUFEQ1dscExYRDlhZ1FBVGszUFhoQXkyeFZPR3VYdGo2bG9UQThrIiwiYnJhbmNoIjoidDIta2V5Y2xvYWstZ3JlcHRpbGUtMSIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjU5LCJjb21taXRTaGEiOiI0ZjEwNDUzNmIxNmJmZTVjMDc0NWEyMDYxYzExY2JjZjNhNDQwODY2IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4f104536b16bfe5c0745a2061c11cbcf3a440866. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
PR-level
<!-- BUGBOT_REVIEW --> Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue. <!-- BUGBOT_FIX_ALL --> <a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTpiMjM0ZjQwZS1lZTQ3LTQ4YjctODU0Ni04Mjc1OTA1MDFjMTYiLCJlbmNyeXB0aW9uS2V5IjoiTmQ4TldVdVJYS1ozeThocl9CUENCSmNxejhTMDlwQ1VweUdnOWtEalVmYyIsImJyYW5jaCI6InQyLWtleWNsb2FrLWdyZXB0aWxlLTEiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <!-- /BUGBOT_FIX_ALL --> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN --> <sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END --> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4f104536b16bfe5c0745a2061c11cbcf3a440866. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ off by one
d2 high ✓ exact
valid · impact low
The new helper only checks that the realm has passkeys enabled and that a user is set. It never checks whether the user has a passwordless credential. During re-authentication, `authenticate()` and `challenge()` therefore call `fillContextForm` and show the passkey UI to password-only users. The new test's own comment says passkeys should not appear for users without a passkey, but it only covers the realm-disabled case, so this path is untested. [grounded: diff] [consensus 3/3: valid=3]
valid · matches d2 · impact high
valid · matches d1 · impact medium
raw comments (3)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161
**Passkey prompt offered to users without passkeys** On re-authentication, isConditionalPasskeysEnabled sets up the conditional passkey challenge for any already-identified user. It never checks whether that user has a passkey, so password-only users are offered passkey sign-in. Return true only when the user is null or user.credentialManager().isConfiguredFor(webauthnAuth.getCredentialType()). ``` services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:160 protected boolean isConditionalPasskeysEnabled(UserModel user) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161 return webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user != null; services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:162 } services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47 if (context.getUser() != null && !isConditionalPasskeysEnabled()) { ```
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161
**Passkey login disappears from normal login page** `isConditionalPasskeysEnabled` now requires a user to already be set. On a first login no user is set, so the passkey challenge is never added. The old code did the opposite. Return true when the user is null, or when the user has a passwordless credential. ``` services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:114 // setup webauthn data when passkeys enabled services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:115 if (isConditionalPasskeysEnabled(context.getUser())) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:116 webauthnAuth.fillContextForm(context); services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:117 } services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:113 (base) // setup webauthn data when the user is not already selected services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:114 (base) if (webauthnAuth != null && webauthnAuth.isPasskeysEnabled()) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:115 (base) webauthnAuth.fillContextForm(context); services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:116 (base) } services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:137 (base) if (context.getUser() == null && webauthnAuth != null && webauthnAuth.isPasskeysEnabled()) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:138 (base) // setup webauthn data when the user is not already selected ```
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
**UsernameForm calls a method that doesn't exist** UsernameForm.authenticate calls isConditionalPasskeysEnabled() with no arguments, but the only declaration takes a UserModel, so the services module does not compile. Pass context.getUser(), and fix the method so users without passkeys still skip the username step. ``` services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47 if (context.getUser() != null && !isConditionalPasskeysEnabled()) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47 (base) if (context.getUser() != null) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:48 (base) // We can skip the form when user is re-authenticating. Unless current user has some IDP set, so he can re-authenticate with that IDP services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:49 (base) if (!this.hasLinkedBrokers(context)) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:50 (base) context.success(); services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:51 (base) return; services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:52 (base) } services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:53 (base) } ```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
d2 high ✓ exact
valid · matches d2 · impact high
raw comments (1)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161
**Passkey setup skipped when no user is selected** `isConditionalPasskeysEnabled` requires `user != null`, the opposite of the old `getUser() == null` check. On a fresh login passkey data is never added to the form; it is added only on re-authentication. Require `user == null`, and make `UsernameForm.authenticate` pass `context.getUser()`. ``` services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:114 // setup webauthn data when passkeys enabled services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:115 if (isConditionalPasskeysEnabled(context.getUser())) { services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:116 webauthnAuth.fillContextForm(context); services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:117 } services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:161 return webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user != null; ```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ off by one
d2 high ✓ exact
valid · matches d1 · impact medium
valid · matches d2 · impact high
raw comments (3)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Method call cannot compile** During compilation, this call cannot be resolved because the only `isConditionalPasskeysEnabled` method in the class hierarchy requires a `UserModel`. This prevents the services module from building; pass `context.getUser()` to the method. ```suggestion if (context.getUser() != null && !isConditionalPasskeysEnabled(context.getUser())) { ```
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:162
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Passkeys disabled before identification** On an ordinary first-factor login, no user has been selected yet, so the new `user != null` requirement prevents `fillContextForm()` from running. The conditional WebAuthn attributes and challenge remain unset, causing the login template to omit the passkey form and disabling conditional passkey login. This also conflicts with the changed test that expects the WebAuthn form on a fresh login page. ```suggestion protected boolean isConditionalPasskeysEnabled(UserModel user) { return webauthnAuth != null && webauthnAuth.isPasskeysEnabled(); } ```
PR-level
<h3>Greptile Summary</h3> This PR extends conditional passkey support to reauthentication flows and adds integration coverage for password and passkey reauthentication. However, the implementation currently contains a compilation error and reverses the condition needed to initialize passkeys on an ordinary login page. - Exposes and centralizes username/password reauthentication form setup. - Enables conditional passkey form initialization when a user is already selected. - Adds passkey reauthentication coverage across username, username/password, and organization flows. <h3>Confidence Score: 3/5</h3> This PR is not safe to merge because it fails to compile and disables conditional passkeys on ordinary username/password login. Two independent blocking failures remain: an unresolved zero-argument method invocation and a user-presence predicate that prevents required WebAuthn form initialization before a user is selected. **Files Needing Attention:** services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java; services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java <details><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java | Changes reauthentication form skipping but invokes a nonexistent zero-argument method, preventing compilation. | | services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java | Enables passkeys for selected-user reauthentication but accidentally disables their initialization on ordinary login. | | services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java | Introduces an overridable decision for including user-specific WebAuthn authenticators. | | services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnConditionalUIAuthenticator.java | Configures conditional UI to use discoverable credentials and preserves reauthentication form state after errors. | | services/src/main/java/org/keycloak/authentication/authenticators/util/AuthenticatorUtils.java | Centralizes restoration of hidden-username and disabled-registration attributes for reauthentication errors. | | testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java | Adds broad reauthentication coverage and contains an expectation exposing the ordinary-login passkey regression. | </details> <details open><summary><h3>Flowchart</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart TD A[Username/password authenticator] --> B{Context user selected?} B -->|No: ordinary login| C[New predicate returns false] C --> D[Skip fillContextForm] D --> E[Conditional WebAuthn attributes absent] E --> F[Passkey form and browser mediation unavailable] B -->|Yes: reauthentication| G[Populate conditional passkey form] ``` </details> <!-- greptile_other_comments_section --> <sub>Reviews (1): Last reviewed commit: ["Update services/src/main/java/org/keyclo..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/0b8b6ce6c998cd2d7a9995b74ecb9cf5f88ec697) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284649)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ wrong severity
d2 high ✓ exact
valid · impact critical
A repo-wide grep finds only one declaration, isConditionalPasskeysEnabled(UserModel). There is no no-arg overload, so the new call in UsernameForm does not compile. [grounded: diff] [consensus 3/3: valid=3]
valid · matches d2 · impact high
valid · matches d1 · impact medium
valid · impact high
Before this change, fillContextForm ran only when no user was set (first login). Both call sites now require user != null, so the initial login form no longer sets up conditional passkey UI. [grounded: diff] [consensus 3/3: valid=3]
raw comments (4)
PR-level
[P0] UsernameForm calls a no-argument `isConditionalPasskeysEnabled()` that doesn't exist, so the module won't compile services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47-47 `UsernamePasswordForm` declares only `isConditionalPasskeysEnabled(UserModel user)` (line 160), and no superclass declares a no-argument overload. The new call `!isConditionalPasskeysEnabled()` in `UsernameForm.authenticate` therefore fails to compile, which breaks the `services` module build. Passing the user, as in `isConditionalPasskeysEnabled(context.getUser())`, is probably what was intended.
PR-level
[P1] Passkeys conditional UI is no longer set up on a normal first login with no user selected services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:160-162 The new helper returns `webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user != null`. The old code did the opposite: it called `fillContextForm` only when `context.getUser() == null`. Both `authenticate()` and `challenge(context, error, field)` now use this helper. On a fresh login with passkeys enabled and no user identified yet, `webauthnAuth.fillContextForm(context)` is never called, so the login page loses the passkey/conditional UI. This applies to the initial page and to the error re-render after a bad username or password. It breaks the main passkeys login path, and the new tests depend on that path, for example "the user should be automatically logged in using the discoverable key" after `oauth.openLoginForm()`. The check should allow `user == null` as well as the re-authentication case, not require `user != null`.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
[P0] Call to an undefined no-arg `isConditionalPasskeysEnabled()` breaks the build. `UsernameForm.authenticate` calls `isConditionalPasskeysEnabled()` with no arguments. The only declaration in the codebase is `UsernamePasswordForm.isConditionalPasskeysEnabled(UserModel user)` at `UsernamePasswordForm.java:160`, and no zero-arg overload exists in this class or any superclass. The `services` module therefore won't compile. The likely fix is to pass `context.getUser()`.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:160
[P1] Conditional passkeys are no longer set up on a normal login, when no user is known yet. The new helper returns `webauthnAuth != null && webauthnAuth.isPasskeysEnabled() && user != null`. Both `authenticate()` (line 115) and `challenge(context, error, field)` (line 137) now call `fillContextForm` only when a user is already set. Before this change, the form was filled exactly when `context.getUser() == null`, which is the standard first-login case where conditional UI (passkey autofill) is most needed. With passkeys enabled in the realm, the initial username/password or username form no longer gets the WebAuthn challenge or `ENABLE_WEBAUTHN_CONDITIONAL_UI`, so users can't sign in with a passkey unless they are re-authenticating. The `user != null` condition looks inverted. If the goal was to also support re-authentication, the check needs to allow a null user too, for example by checking `user == null` or by checking whether the user has passkey credentials configured.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ wrong severity
d2 high ✓ exact
valid · matches d1 · impact medium
valid · matches d2 · impact high
valid · impact critical
The only definition is isConditionalPasskeysEnabled(UserModel user) in UsernamePasswordForm, and a repo-wide grep finds no no-arg overload. The no-arg call in UsernameForm therefore fails to compile. [grounded: diff] [consensus 3/3: valid=3]
valid · impact high
The old code filled webauthn data only when the user was null, i.e. on the initial login screen. The new helper requires user != null, so the initial username/password form no longer sets up conditional-UI passkey data. That breaks the main passkey login path, which the tests in this same diff still expect to work. [grounded: diff] [consensus 3/3: valid=3]
raw comments (4)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
[P0] Undefined no-arg isConditionalPasskeysEnabled() call breaks compilation `UsernameForm.authenticate` calls `isConditionalPasskeysEnabled()` with no arguments. The only definition is `UsernamePasswordForm.isConditionalPasskeysEnabled(UserModel user)`, and I found no other overload in the repo. The `services` module therefore fails to compile, which blocks every build and test of the module. It needs to pass `context.getUser()`.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:160
[P1] Passkey helper requires a non-null user, which inverts the old "user not yet selected" condition The old code called `webauthnAuth.fillContextForm` only when `context.getUser() == null`, so the conditional-UI passkey setup ran on the initial username form. The new helper ends with `&& user != null`. In `authenticate()` and `challenge(...)`, the passkey data is now set up only when a user is already known, such as re-authentication. It is no longer set up on the initial username or username-password form. With passkeys enabled, the first login page loses conditional-UI passkey support, and error re-renders on that page lose it too. The comment "setup webauthn data when possible" and the new test names suggest the check was meant to be `user == null`. If so, the `UsernameForm` skip-form guard is also wrong: it should skip the form only when passkeys are not enabled for a fresh login, not when a user is present.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
[P0] Call to nonexistent no-arg `isConditionalPasskeysEnabled()` breaks compilation The only definition is `isConditionalPasskeysEnabled(UserModel user)` in `UsernamePasswordForm`. The no-arg call in `UsernameForm.authenticate` doesn't resolve, so the `services` module won't compile.
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:160
[P1] Passkey condition requires a user, which is the opposite of the previous behavior The old code called `webauthnAuth.fillContextForm(context)` only when the user was not yet selected (`context.getUser() == null`). The new helper returns true only when `user != null`. In `authenticate()` and `challenge(...)`, the conditional-UI passkey data is therefore no longer set up on the initial username/password or username form, where no user is set. That is the main passkey login case. The data is now set up only on re-authentication, where a user is already set. Conditional passkey login on the first screen stops working, and an error challenge for an unknown user no longer keeps passkeys. The condition probably should not require a non-null user, or the null check is inverted.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ off by one
d2 high ✓ exact
valid · matches d1 · impact medium
valid · matches d2 · impact high
valid · impact low
The new test wraps findElement in a try/catch over all Exceptions. fail() throws an AssertionError, which is not caught, so a form that is present still fails the test. But a WebDriverException, such as a session or transport failure, is swallowed and treated as proof that the form is absent. That is a real weakness in the test, though a minor one. [grounded: diff] [consensus 3/3: valid=3]
raw comments (5)
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java:47
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required"> 1\. The services module no longer compiles <code>🐞 Bug</code> <code>≡ Correctness</code> <pre> <b><i>UsernameForm.authenticate()</i></b> invokes <b><i>isConditionalPasskeysEnabled()</i></b> without an argument, but the only inherited declaration requires a <b><i>UserModel</i></b> and no zero-argument overload exists. Compiling the services module reaches this class through <b><i>UsernameFormFactory</i></b> and cannot resolve the invocation, blocking login and reauthentication flows before authentication can run. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` ## Issue description `UsernameForm.authenticate()` calls a nonexistent zero-argument overload of `isConditionalPasskeysEnabled()`, preventing the services module from compiling. ## Fix Focus Areas - services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[47-47] - services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[160-162] ## Recommended Fix Make the helper signature and all call sites consistent. Prefer changing the helper to a no-argument method that checks whether the conditional WebAuthn authenticator exists and passkeys are enabled, because availability does not depend on whether a user has already been selected; alternatively, preserve the existing signature and pass `context.getUser()` at the call site. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java:116
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required"> 2\. Initial login no longer offers passkeys <code>🐞 Bug</code> <code>≡ Correctness</code> <pre> <b><i>UsernamePasswordForm.authenticate()</i></b> now calls <b><i>fillContextForm()</i></b> only when <b><i>isConditionalPasskeysEnabled(context.getUser())</i></b> succeeds, and that helper explicitly rejects a null user. Initial login and login-hint requests have no context user at form-render time, so the conditional WebAuthn attributes and form are omitted even though passkeys are enabled. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` ## Issue description Conditional passkey form initialization is now restricted to requests with an already-selected user, disabling passkeys during ordinary initial login. ## Fix Focus Areas - services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[114-116] - services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[160-162] - services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[47-47] ## Recommended Fix Define conditional passkey availability using only the authenticator's presence and realm passkey configuration, without requiring a non-null user. Use that check for both initial login and reauthentication while retaining the separate user check that controls whether `UsernameForm` may skip its form. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java:295
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> 3\. Browser failures can pass the new test <code>🐞 Bug</code> <code>☼ Reliability</code> <pre> <b><i>reauthenticationOfUserWithoutPasskey()</i></b> catches every <b><i>Exception</i></b> emitted while locating the WebAuthn form instead of only the expected missing-element exception. WebDriver session, transport, selector, or page-state failures at either assertion are therefore treated as evidence that the form is absent, and the test continues into the login flow. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` ## Issue description The new negative WebAuthn checks swallow all browser exceptions, allowing unrelated Selenium failures to satisfy the test. ## Fix Focus Areas - testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[291-296] - testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[312-317] ## Recommended Fix Replace each broad try/catch with `Assert.assertThrows(NoSuchElementException.class, () -> driver.findElement(...))`, importing Selenium's `NoSuchElementException`. This preserves the intended absence assertion while allowing every unrelated browser failure to fail the test. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
PR-level
<h3>PR Summary by Qodo</h3> Enable passkey reauthentication in username-based login flows <code>🐞 Bug fix</code> <code>✨ Enhancement</code> <code>🧪 Tests</code> <code>🕐 40+ Minutes</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <details> <summary>AI Description</summary> <dl> <dd> <br/> ><pre> >• Keeps conditional passkeys available when reauthenticating an identified user. >• Preserves reauthentication form state after password or passkey failures. >• Adds integration coverage for passkey, password, and organization reauthentication flows. ></pre> </dd> </dl> </details> <details> <summary>Diagram</summary> <dl> <dd> <br/> ```mermaid graph TD A["OIDC prompt login"] --> B["Known user"] --> C{"Passkeys enabled"} C -->|Yes| E["Combined login form"] --> F{"Credential valid"} C -->|No| D["Password form"] --> F F -->|Success| G["Complete login"] F -->|Error| H["Preserve reauth state"] H -.->|Passkeys| E H -.->|Password| D ``` </dd> </dl> </details> <details> <summary>High-Level Assessment</summary> <dl> <dd> <br/> >The current approach is appropriate: it reuses the existing conditional WebAuthn authenticator, introduces a focused display-policy hook, and centralizes reauthentication error-state restoration. A separate reauthentication authenticator or duplicated form logic would increase flow configuration and maintenance complexity without improving behavior. </dd> </dl> </details> <details> <summary> Files changed (9) <code> +407 / -24 </code> </summary> <dl> <dd> <br/> <details> <summary>Enhancement (2) <code> +26 / -6 </code></summary> <dl> <dd> <details> <summary>UsernamePasswordForm.java<code>Populate conditional passkeys for identified users</code> <code>+10/-6</code></summary> <br/> >Populate conditional passkeys for identified users > ><pre> >• Populates conditional WebAuthn form data when passkeys are enabled and the context contains a user, including error challenges. Adds a helper that centralizes this eligibility check. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-02966e54a0fc761c5cad7239051b9bf47d6a450140f2d15463e21fa24b7380e7'>services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java</a> </details> <details> <summary>AuthenticatorUtils.java<code>Centralize reauthentication error-form configuration</code> <code>+16/-0</code></summary> <br/> >Centralize reauthentication error-form configuration > ><pre> >• Adds a shared helper that detects an existing reauthentication user from the authentication-session note. It configures login forms to hide the username and disable registration after credential errors. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-54d321d4ec0cb77edc62ca16aaabdf4fbadab2dbf7cd436a428002fcf86cead3'>services/src/main/java/org/keycloak/authentication/authenticators/util/AuthenticatorUtils.java</a> </details> </dd> </dl> </details> <details> <summary>Bug fix (3) <code> +12 / -7 </code></summary> <dl> <dd> <details> <summary>AbstractUsernameFormAuthenticator.java<code>Restore reauthentication form state after password failures</code> <code>+2/-6</code></summary> <br/> >Restore reauthentication form state after password failures > ><pre> >• Exposes the authentication-session note used to identify reauthentication and delegates error-form restoration to the shared utility. Password failures now consistently retain the hidden username and disabled registration state. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-7868413639a878442407ec04374badcd7ee6abe2d4fe13315db437d6b7ea9c8b'>services/src/main/java/org/keycloak/authentication/authenticators/browser/AbstractUsernameFormAuthenticator.java</a> </details> <details> <summary>UsernameForm.java<code>Retain username form during passkey reauthentication</code> <code>+1/-1</code></summary> <br/> >Retain username form during passkey reauthentication > ><pre> >• Prevents the username form execution from being skipped when a user is already identified and conditional passkeys are enabled. This allows passkeys to remain available during reauthentication. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-60b039f18a7df86c74ea871b765458ecbb6a1fbe6f737f8cc026f615e75c6755'>services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java</a> </details> <details> <summary>WebAuthnConditionalUIAuthenticator.java<code>Preserve conditional passkeys across reauthentication errors</code> <code>+9/-0</code></summary> <br/> >Preserve conditional passkeys across reauthentication errors > ><pre> >• Restores reauthentication form attributes after conditional WebAuthn failures. Overrides authenticator-list behavior so conditional username/password forms do not expose explicit registered-authenticator choices. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-f5b0708095981e6131ace946c7d103d94c4829028283f4bc1987302c457a1e55'>services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnConditionalUIAuthenticator.java</a> </details> </dd> </dl> </details> <details> <summary>Refactor (1) <code> +10 / -1 </code></summary> <dl> <dd> <details> <summary>WebAuthnAuthenticator.java<code>Add a hook for displaying registered WebAuthn credentials</code> <code>+10/-1</code></summary> <br/> >Add a hook for displaying registered WebAuthn credentials > ><pre> >• Extracts the decision to expose a user&#x27;s available WebAuthn authenticators into an overridable method. Standard WebAuthn flows retain their existing identified-user behavior. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-6dc319037c4a9a0d86c5a36f26403222ded602c6257ed318b8c3e0e97774623b'>services/src/main/java/org/keycloak/authentication/authenticators/browser/WebAuthnAuthenticator.java</a> </details> </dd> </dl> </details> <details> <summary>Tests (3) <code> +359 / -10 </code></summary> <dl> <dd> <details> <summary>PasskeysOrganizationAuthenticationTest.java<code>Cover organization passkey reauthentication</code> <code>+59/-3</code></summary> <br/> >Cover organization passkey reauthentication > ><pre> >• Updates expectations so passkeys remain visible after username selection and password failures. Adds coverage proving discoverable passkeys work with OIDC prompt=login in an organization authentication flow. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-4785bfa8f1f045c2901957341b93a3823493759ab28aa9739e20480cb60452c6'>testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysOrganizationAuthenticationTest.java</a> </details> <details> <summary>PasskeysUsernameFormTest.java<code>Cover passkey reauthentication through the username form</code> <code>+65/-0</code></summary> <br/> >Cover passkey reauthentication through the username form > ><pre> >• Adds an integration test for initial discoverable-passkey login followed by OIDC prompt=login reauthentication. The scenario removes the password to ensure the passkey path is independently functional. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-5a08042a92b7ecbfb8ead6b81695939c69bdf20dd54a1d1fbbec4f357e8b5717'>testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernameFormTest.java</a> </details> <details> <summary>PasskeysUsernamePasswordFormTest.java<code>Expand combined password and passkey reauthentication coverage</code> <code>+235/-7</code></summary> <br/> >Expand combined password and passkey reauthentication coverage > ><pre> >• Adds scenarios for external passkeys, disabled passkey policy, password-only users, and users with both credential types. Verifies passkeys survive invalid-password errors and that either credential can complete reauthentication. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-d10f272adb4bd0288f8ff278ce9d2eef9bbff1051818141d65869ef003b9a7f5'>testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java</a> </details> </dd> </dl> </details> </dd> </dl> </details>
PR-level
<h3>Code Review by Qodo</h3> <code>🐞 Bugs (3)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <br/> <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required"> <details> <summary> 1. The services module no longer compiles <code>🐞 Bug</code> <code>≡ Correctness</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>UsernameForm.authenticate()</i></b> invokes <b><i>isConditionalPasskeysEnabled()</i></b> without an argument, but the >only inherited declaration requires a <b><i>UserModel</i></b> and no zero-argument overload exists. Compiling >the services module reaches this class through <b><i>UsernameFormFactory</i></b> and cannot resolve the >invocation, blocking login and reauthentication flows before authentication can run. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[47]](https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-60b039f18a7df86c74ea871b765458ecbb6a1fbe6f737f8cc026f615e75c6755R47-R47)</code> > >```diff >+ if (context.getUser() != null && !isConditionalPasskeysEnabled()) { >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >The changed call in <b><i>UsernameForm</i></b> supplies no arguments, while the sole declaration inherited from ><b><i>UsernamePasswordForm</i></b> accepts one <b><i>UserModel</i></b>; a repository-wide usage search finds no >zero-argument overload anywhere in the inheritance chain. ></pre> > > <code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[45-54]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java/#L45-L54)</code> > <code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[160-162]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java/#L160-L162)</code> > <code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameFormFactory.java[39-45]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameFormFactory.java/#L39-L45)</code> > <code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[46-54]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java/#L46-L54)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >`UsernameForm.authenticate()` calls a nonexistent zero-argument overload of `isConditionalPasskeysEnabled()`, preventing the services module from compiling. > >## Fix Focus Areas >- services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[47-47] >- services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[160-162] > >## Recommended Fix >Make the helper signature and all call sites consistent. Prefer changing the helper to a no-argument method that checks whether the conditional WebAuthn authenticator exists and passkeys are enabled, because availability does not depend on whether a user has already been selected; alternatively, preserve the existing signature and pass `context.getUser()` at the call site. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <details> <summary> 2. Initial login no longer offers passkeys <code>🐞 Bug</code> <code>≡ Correctness</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>UsernamePasswordForm.authenticate()</i></b> now calls <b><i>fillContextForm()</i></b> only when ><b><i>isConditionalPasskeysEnabled(context.getUser())</i></b> succeeds, and that helper explicitly rejects a >null user. Initial login and login-hint requests have no context user at form-render time, so the >conditional WebAuthn attributes and form are omitted even though passkeys are enabled. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[R114-116]](https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-02966e54a0fc761c5cad7239051b9bf47d6a450140f2d15463e21fa24b7380e7R114-R116)</code> > >```diff >+ // setup webauthn data when passkeys enabled >+ if (isConditionalPasskeysEnabled(context.getUser())) { >+ webauthnAuth.fillContextForm(context); >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >The new helper returns false for a null user, but initial-login tests open the login page before >selecting a user and require both WebAuthn autocomplete and the WebAuthn form. The login template >derives those elements from state populated by <b><i>fillContextForm()</i></b>. ></pre> > > <code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[86-118]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java/#L86-L118)</code> > <code>[services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[160-162]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java/#L160-L162)</code> > <code>[themes/src/main/resources/theme/base/login/login-username.ftl[17-23]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/themes/src/main/resources/theme/base/login/login-username.ftl/#L17-L23)</code> > <code>[testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[141-146]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java/#L141-L146)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >Conditional passkey form initialization is now restricted to requests with an already-selected user, disabling passkeys during ordinary initial login. > >## Fix Focus Areas >- services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[114-116] >- services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernamePasswordForm.java[160-162] >- services/src/main/java/org/keycloak/authentication/authenticators/browser/UsernameForm.java[47-47] > >## Recommended Fix >Define conditional passkey availability using only the authenticator's presence and realm passkey configuration, without requiring a non-null user. Use that check for both initial login and reauthentication while retaining the separate user check that controls whether `UsernameForm` may skip its form. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <br/> <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> <details> <summary> 3. Browser failures can pass the new test <code>🐞 Bug</code> <code>☼ Reliability</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>reauthenticationOfUserWithoutPasskey()</i></b> catches every <b><i>Exception</i></b> emitted while locating the >WebAuthn form instead of only the expected missing-element exception. WebDriver session, transport, >selector, or page-state failures at either assertion are therefore treated as evidence that the form >is absent, and the test continues into the login flow. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[R292-295]](https://github.com/drape-io/crbench-qodo-2026-09/pull/55/files#diff-d10f272adb4bd0288f8ff278ce9d2eef9bbff1051818141d65869ef003b9a7f5R292-R295)</code> > >```diff >+ MatcherAssert.assertThat(driver.findElement(By.xpath("//form[@id='webauth']")), nullValue()); >+ fail("Not expected to have webauthn button"); >+ } catch (Exception nsee) { >+ // expected >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >Both newly added checks catch <b><i>Exception</i></b> around <b><i>driver.findElement</i></b>, then proceed with password >login and event assertions, so unexpected WebDriver exceptions are silently accepted at these >checkpoints. ></pre> > > <code>[testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[289-300]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java/#L289-L300)</code> > <code>[testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[310-321]](https://github.com/drape-io/crbench-qodo-2026-09/blob/ad31ed8ab5e62232708edb001694e3b2f46c385d/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java/#L310-L321)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >The new negative WebAuthn checks swallow all browser exceptions, allowing unrelated Selenium failures to satisfy the test. > >## Fix Focus Areas >- testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[291-296] >- testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/webauthn/passwordless/PasskeysUsernamePasswordFormTest.java[312-317] > >## Recommended Fix >Replace each broad try/catch with `Assert.assertThrows(NoSuchElementException.class, () -> driver.findElement(...))`, importing Selenium's `NoSuchElementException`. This preserves the intended absence assertion while allowing every unrelated browser failure to fail the test. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-context:start --> <details><summary><strong>Context sources</strong></summary> <div>Review mode: <code>🧠 Deep</code>: This security-sensitive authentication/passkeys change spans multiple production code paths with 29 edit sites and substantial new re-authentication behavior, creating a high density of independently missable defects.</div> <!-- qodo-context:end --> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:start --> <details> <summary><strong>Tip of the day</strong></summary> <br/> <pre>💡 Did you know, you can reply &#x27;qodo&#x27; on any finding to push back, ask questions, or dig deeper</pre> <a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:end --> <!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/ad31ed8ab5e62232708edb001694e3b2f46c385d --> <a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>