Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(cognito): reject missing SRP challenge session (#4578)

XuJianfbbbf244af1d
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java
index 626b71fdf0..ef7e7dc1a3 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java
@@ -578,7 +578,7 @@ final class CognitoAuthFlowHandler {
clientMetadata);
}
- SrpSession srp = srpSessions.get(session);
+ SrpSession srp = session == null ? null : srpSessions.get(session);
if (srp == null) throw new AwsException("NotAuthorizedException", "Session not found", 400);
if (sessionExpired(srp.expiresAt())) {
srpSessions.remove(session);
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
index 0a07a6cc7d..bd21ecae6b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
@@ -2498,6 +2498,25 @@ class CognitoServiceTest {
assertEquals("NotAuthorizedException", ex.getErrorCode());
}
+ @Test
+ void passwordVerifierWithoutSessionReturnsNotAuthorized() {
+ UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
+ UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+
+ AwsException userError = assertThrows(AwsException.class, () ->
+ service.respondToAuthChallenge(client.getClientId(), "PASSWORD_VERIFIER", null, Map.of()));
+ assertEquals("NotAuthorizedException", userError.getErrorCode());
+ assertEquals("Session not found", userError.getMessage());
+ assertEquals(400, userError.getHttpStatus());
+
+ AwsException adminError = assertThrows(AwsException.class, () ->
+ service.adminRespondToAuthChallenge(pool.getId(), client.getClientId(),
+ "PASSWORD_VERIFIER", null, Map.of()));
+ assertEquals("NotAuthorizedException", adminError.getErrorCode());
+ assertEquals("Session not found", adminError.getMessage());
+ assertEquals(400, adminError.getHttpStatus());
+ }
+
// =========================================================================
// Auth challenge session expiry
// =========================================================================