mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cognito): reject unconfirmed users in SRP auth (#2027)
This commit is contained in:
1 parent
76f602fafa
commit
733c72d02a
2 files changed
+46
No files matched your search
@@ -328,6 +328,9 @@ final class CognitoAuthFlowHandler {
|
||||
if ("RESET_REQUIRED".equals(user.getUserStatus())) {
|
||||
throw new AwsException("PasswordResetRequiredException", "Password reset required", 400);
|
||||
}
|
||||
if ("UNCONFIRMED".equals(user.getUserStatus())) {
|
||||
throw new AwsException("UserNotConfirmedException", "User is not confirmed", 400);
|
||||
}
|
||||
if (user.getSrpVerifier() == null) {
|
||||
throw new AwsException("NotAuthorizedException", "User does not support SRP auth", 400);
|
||||
}
|
||||
@@ -386,6 +389,9 @@ final class CognitoAuthFlowHandler {
|
||||
if ("RESET_REQUIRED".equals(user.getUserStatus())) {
|
||||
throw new AwsException("PasswordResetRequiredException", "Password reset required", 400);
|
||||
}
|
||||
if ("UNCONFIRMED".equals(user.getUserStatus())) {
|
||||
throw new AwsException("UserNotConfirmedException", "User is not confirmed", 400);
|
||||
}
|
||||
if (user.getSrpVerifier() == null) {
|
||||
throw new AwsException("NotAuthorizedException", "User does not support SRP auth", 400);
|
||||
}
|
||||
|
||||
@@ -1313,6 +1313,46 @@ class CognitoServiceTest {
|
||||
assertEquals("bob", params.get("USERNAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void initiateAuthWithUserSrpAuthRejectsUnconfirmedUser() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
|
||||
service.signUp(client.getClientId(), "bob", "Password123!", Map.of("email", "bob@example.com"));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.initiateAuth(client.getClientId(), "USER_SRP_AUTH",
|
||||
Map.of("USERNAME", "bob", "SRP_A", "ABCDEF1234567890")));
|
||||
|
||||
assertEquals("UserNotConfirmedException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void respondToAuthChallengeWithUserSrpAuthRejectsNewlyUnconfirmedUser() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
String password = "Password123!";
|
||||
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "bob@example.com"), null);
|
||||
service.adminSetUserPassword(pool.getId(), "bob", password, true);
|
||||
UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
|
||||
|
||||
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_SRP_AUTH",
|
||||
Map.of("USERNAME", "bob", "SRP_A", "ABCDEF1234567890"));
|
||||
String session = (String) initResult.get("Session");
|
||||
// Simulate the user becoming unconfirmed after the SRP session is created.
|
||||
CognitoUser user = service.adminGetUser(pool.getId(), "bob");
|
||||
user.setUserStatus("UNCONFIRMED");
|
||||
userStore.put(pool.getId() + "::" + user.getUsername(), user);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.respondToAuthChallenge(client.getClientId(), "PASSWORD_VERIFIER", session,
|
||||
Map.of(
|
||||
"USERNAME", "bob",
|
||||
"PASSWORD_CLAIM_SIGNATURE", "invalid-sig",
|
||||
"TIMESTAMP", "Wed Apr 8 12:00:00 UTC 2026"
|
||||
)));
|
||||
|
||||
assertEquals("UserNotConfirmedException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void respondToAuthChallengeWithInvalidSrpSignatureRejects() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
|
||||
|
||||
Reference in new issue
Block a user