Light, fluffy, and always free - The AWS Local Emulator alternative
fix(cognito): reject self-managed verification status (#2532)
Daniel Zwickerf8597bdef91e
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.javaindex 7d40eed1c4..3f9c06865f 100644--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java@@ -1734,7 +1734,17 @@ public class CognitoService implements ResourceProvider {validateOriginJtiNotRevoked(accessToken, poolId);Long iat = extractIatFromToken(accessToken);validateUserNotGloballySignedOut(username, poolId, "access", iat != null ? iat : 0L);-++ String verificationStatusAttribute = attributes.containsKey("email_verified")+ ? "email_verified"+ : attributes.containsKey("phone_number_verified") ? "phone_number_verified" : null;+ if (verificationStatusAttribute != null) {+ throw new AwsException("InvalidParameterException",+ "Invalid user attributes: " + verificationStatusAttribute+ + ": Attribute cannot be updated.",+ 400);+ }+adminUpdateUserAttributes(poolId, username, attributes);}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.javaindex 07ac758492..bb86ab5ea2 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@@ -1291,6 +1291,37 @@ class CognitoServiceTest {assertEquals(400, ex.getHttpStatus());}+ @ParameterizedTest+ @CsvSource({"email_verified", "phone_number_verified"})+ @SuppressWarnings("unchecked")+ void updateUserAttributesRejectsSelfManagedVerificationStatusWithoutPartialPersistence(+ String verificationStatusAttribute) {+ UserPool pool = createPoolAndUser();+ UserPoolClient client = service.createUserPoolClient(+ pool.getId(), "verification-status-client", false, false, List.of(), List.of());+ Map<String, Object> authResult = service.initiateAuth(+ client.getClientId(), "USER_PASSWORD_AUTH",+ Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!"));+ String accessToken = (String) ((Map<String, Object>) authResult.get("AuthenticationResult"))+ .get("AccessToken");++ AwsException error = assertThrows(AwsException.class,+ () -> service.updateUserAttributes(accessToken, Map.of(+ verificationStatusAttribute, "true",+ "name", "must-not-be-persisted")));++ assertEquals("InvalidParameterException", error.getErrorCode());+ assertEquals(400, error.getHttpStatus());+ CognitoUser unchanged = service.adminGetUser(pool.getId(), "alice");+ assertFalse(unchanged.getAttributes().containsKey(verificationStatusAttribute));+ assertFalse(unchanged.getAttributes().containsKey("name"));++ service.adminUpdateUserAttributes(+ pool.getId(), "alice", Map.of(verificationStatusAttribute, "true"));+ assertEquals("true", service.adminGetUser(pool.getId(), "alice")+ .getAttributes().get(verificationStatusAttribute));+ }+@Test@SuppressWarnings("unchecked")void jwtSubMatchesStoredSubAttribute() {