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:
Priamo Germosen authored and GitHub committed 2026-09-19 19:38:40 -05:00
1 parent 15ed62f8cb
commit 61f67cc834
5 files changed
+136 -21

No files matched your search

@@ -88,17 +88,7 @@ final class CognitoAuthFlowHandler {
case "REFRESH_TOKEN_AUTH", "REFRESH_TOKEN" -> handleRefreshToken(pool, client, authParameters, clientMetadata);
case "USER_SRP_AUTH" -> handleUserSrpAuth(pool, client, authParameters, clientMetadata);
case "CUSTOM_AUTH" -> handleCustomAuth(pool, client, authParameters, clientMetadata);
default -> {
String username = authParameters.get("USERNAME");
if (username == null) {
throw new AwsException("InvalidParameterException", "USERNAME is required", 400);
}
CognitoUser user = service.adminGetUser(pool.getId(), username);
Map<String, Object> result = new HashMap<>();
result.put("AuthenticationResult",
issueTokens(pool, client, user, "TokenGeneration_Authentication", clientMetadata));
yield result;
}
default -> throw unsupportedAuthFlow(authFlow);
};
}
@@ -121,21 +111,19 @@ final class CognitoAuthFlowHandler {
}
return switch (authFlow) {
case "ADMIN_USER_PASSWORD_AUTH", "USER_PASSWORD_AUTH" ->
case "ADMIN_USER_PASSWORD_AUTH", "ADMIN_NO_SRP_AUTH", "USER_PASSWORD_AUTH" ->
authenticateWithPassword(pool, client, authParameters, clientMetadata);
case "REFRESH_TOKEN_AUTH", "REFRESH_TOKEN" -> handleRefreshToken(pool, client, authParameters, clientMetadata);
case "ADMIN_USER_SRP_AUTH" -> handleUserSrpAuth(pool, client, authParameters, clientMetadata);
case "CUSTOM_AUTH" -> handleCustomAuth(pool, client, authParameters, clientMetadata);
default -> {
CognitoUser user = service.adminGetUser(userPoolId, username);
Map<String, Object> result = new HashMap<>();
result.put("AuthenticationResult",
issueTokens(pool, client, user, "TokenGeneration_Authentication", clientMetadata));
yield result;
}
default -> throw unsupportedAuthFlow(authFlow);
};
}
private static AwsException unsupportedAuthFlow(String authFlow) {
return new AwsException("InvalidParameterException", "Unsupported AuthFlow: " + authFlow, 400);
}
Map<String, Object> respondToAuthChallenge(String clientId, String challengeName, String session,
Map<String, String> responses, Map<String, String> clientMetadata) {
UserPoolClient client = service.findClientById(clientId);