mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(cognito): reject self-managed verification status (#2532)
This commit is contained in:
1 parent
2e8cbc13d7
commit
f8597bdef9
2 files changed
+42
-1
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user