mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 17:33:03 -05:00
fix(cognito): reject unrecognized AuthFlow instead of issuing tokens (#3923)
The default arm of InitiateAuth and AdminInitiateAuth looked the user up by name and issued signed tokens for any AuthFlow value it did not recognize, with no credential check. Reject those values with InvalidParameterException. ADMIN_NO_SRP_AUTH is a valid AdminInitiateAuth flow that previously only worked through that arm, so it now goes through password authentication.
This commit is contained in:
1 parent
15ed62f8cb
commit
61f67cc834
5 files changed
+136
-21
No files matched your search
@@ -134,6 +134,77 @@ class CognitoIntegrationTest {
|
||||
.body("AuthenticationResult.RefreshToken", org.hamcrest.Matchers.notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void initiateAuthRejectsUnrecognizedAuthFlow() {
|
||||
cognitoAction("InitiateAuth", """
|
||||
{
|
||||
"ClientId": "%s",
|
||||
"AuthFlow": "UNKNOWN_FLOW",
|
||||
"AuthParameters": {
|
||||
"USERNAME": "%s"
|
||||
}
|
||||
}
|
||||
""".formatted(clientId, USERNAME))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("AuthenticationResult", org.hamcrest.Matchers.nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void adminInitiateAuthRejectsUnrecognizedAuthFlow() {
|
||||
cognitoAction("AdminInitiateAuth", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"AuthFlow": "UNKNOWN_FLOW",
|
||||
"AuthParameters": {
|
||||
"USERNAME": "%s"
|
||||
}
|
||||
}
|
||||
""".formatted(poolId, clientId, USERNAME))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"))
|
||||
.body("AuthenticationResult", org.hamcrest.Matchers.nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void adminInitiateAuthNoSrpFlowRequiresThePassword() {
|
||||
cognitoAction("AdminInitiateAuth", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"AuthFlow": "ADMIN_NO_SRP_AUTH",
|
||||
"AuthParameters": {
|
||||
"USERNAME": "%s",
|
||||
"PASSWORD": "wrong-password"
|
||||
}
|
||||
}
|
||||
""".formatted(poolId, clientId, USERNAME))
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("NotAuthorizedException"));
|
||||
|
||||
cognitoAction("AdminInitiateAuth", """
|
||||
{
|
||||
"UserPoolId": "%s",
|
||||
"ClientId": "%s",
|
||||
"AuthFlow": "ADMIN_NO_SRP_AUTH",
|
||||
"AuthParameters": {
|
||||
"USERNAME": "%s",
|
||||
"PASSWORD": "%s"
|
||||
}
|
||||
}
|
||||
""".formatted(poolId, clientId, USERNAME, PASSWORD))
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("AuthenticationResult.AccessToken", org.hamcrest.Matchers.notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void authTokensAreSignedWithPublishedRsaJwksKey() throws Exception {
|
||||
|
||||
@@ -147,6 +147,47 @@ class CognitoServiceTest {
|
||||
assertEquals(List.of("email"), pool.getUsernameAttributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void initiateAuthRejectsUnrecognizedAuthFlowWithoutIssuingTokens() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
UserPoolClient client = service.createUserPoolClient(
|
||||
pool.getId(), "client", false, false, List.of(), List.of());
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
service.initiateAuth(client.getClientId(), "UNKNOWN_FLOW", Map.of("USERNAME", "alice")));
|
||||
|
||||
assertEquals("InvalidParameterException", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminInitiateAuthRejectsUnrecognizedAuthFlowWithoutIssuingTokens() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
UserPoolClient client = service.createUserPoolClient(
|
||||
pool.getId(), "client", false, false, List.of(), List.of());
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
service.adminInitiateAuth(pool.getId(), client.getClientId(), "UNKNOWN_FLOW",
|
||||
Map.of("USERNAME", "alice")));
|
||||
|
||||
assertEquals("InvalidParameterException", exception.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminInitiateAuthNoSrpFlowRequiresTheCorrectPassword() {
|
||||
UserPool pool = createPoolAndUser();
|
||||
UserPoolClient client = service.createUserPoolClient(
|
||||
pool.getId(), "client", false, false, List.of(), List.of());
|
||||
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
service.adminInitiateAuth(pool.getId(), client.getClientId(), "ADMIN_NO_SRP_AUTH",
|
||||
Map.of("USERNAME", "alice", "PASSWORD", "wrong")));
|
||||
assertEquals("NotAuthorizedException", exception.getErrorCode());
|
||||
|
||||
Map<String, Object> result = service.adminInitiateAuth(pool.getId(), client.getClientId(),
|
||||
"ADMIN_NO_SRP_AUTH", Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!"));
|
||||
assertTrue(result.containsKey("AuthenticationResult"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"Short1!a",
|
||||
|
||||
Reference in new issue
Block a user