Skip to content

Commit

Permalink
Invalidate authentication session on repeated OTP failures
Browse files Browse the repository at this point in the history
Closes keycloak#26177
Signed-off-by: Douglas Palmer <[email protected]>
  • Loading branch information
douglaspalmer authored and pedroigor committed Jan 19, 2024
1 parent 972d198 commit 18d0105
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.credential.OTPCredentialModel;
import org.keycloak.services.managers.AuthenticationSessionManager;
import org.keycloak.services.messages.Messages;
import org.keycloak.services.validation.Validation;
import org.keycloak.sessions.AuthenticationSessionModel;
Expand Down Expand Up @@ -89,6 +90,7 @@ public void validateOTP(AuthenticationFlowContext context) {
UserModel userModel = context.getUser();
if (!enabledUser(context, userModel)) {
// error in context is set in enabledUser/isDisabledByBruteForce
new AuthenticationSessionManager(context.getSession()).removeAuthenticationSession(context.getRealm(), context.getAuthenticationSession(), true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,6 @@ public void testBrowserInvalidTotp() throws Exception {
loginInvalidPassword();
loginWithTotpFailure();
continueLoginWithCorrectTotpExpectFailure();
continueLoginWithInvalidTotp();
clearUserFailures();
continueLoginWithTotp();
}

@Test
Expand All @@ -466,13 +463,14 @@ public void testBrowserMissingTotp() throws Exception {
loginWithMissingTotp();
loginWithMissingTotp();
continueLoginWithMissingTotp();
continueLoginWithCorrectTotpExpectFailure();
// wait to unlock
testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(6)));

continueLoginWithTotp();
}

testingClient.testing().setTimeOffset(Collections.singletonMap("offset", String.valueOf(0)));
@Test
public void testBrowserTotpSessionClosedAfterLockout() throws Exception {
long start = System.currentTimeMillis();
loginWithTotpFailure();
continueLoginWithInvalidTotp();
loginPage.assertCurrent();
}

@Test
Expand Down

0 comments on commit 18d0105

Please sign in to comment.