mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(cognito): default ExplicitAuthFlows to refresh, SRP and custom auth (#4081)
A user pool client created without ExplicitAuthFlows was treated as allowing every auth flow, where AWS defaults such a client to ALLOW_REFRESH_TOKEN_AUTH, ALLOW_USER_SRP_AUTH and ALLOW_CUSTOM_AUTH. USER_PASSWORD_AUTH against a no-list client succeeded on Floci and is refused on AWS. Apply that default at auth time, in the existing gate added by #3974. CreateUserPoolClient, UpdateUserPoolClient and DescribeUserPoolClient keep storing and returning exactly what was normalized, empty when unset, matching AWS: Terraform's Cognito acceptance tests confirm the empty read-back for both an omitted list and an explicit empty one, and materialising the default into storage would fail Terraform apply with an inconsistent-result error. Tests and compatibility fixtures that created a no-list client and then signed in with a flow outside the default now enable that flow on their client.
This commit is contained in:
1 parent
eca5a1bb14
commit
06007deea8
13 files changed
+219
-103
No files matched your search
+13
-9
@@ -172,15 +172,11 @@ final class CognitoAuthFlowHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforces the app client's {@code ExplicitAuthFlows}. A client with no explicit list is left
|
||||
* ungated so clients created without one keep working; once a list is set, the flow must be
|
||||
* covered by one of {@code acceptedValues}.
|
||||
* Enforces the app client's {@code ExplicitAuthFlows}: the flow must be covered by one of
|
||||
* {@code acceptedValues}.
|
||||
*/
|
||||
private static void requireFlowEnabled(UserPoolClient client, String authFlow, String... acceptedValues) {
|
||||
List<String> enabled = client.getExplicitAuthFlows();
|
||||
if (enabled == null || enabled.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<String> enabled = enabledAuthFlows(client);
|
||||
for (String accepted : acceptedValues) {
|
||||
if (enabled.contains(accepted)) {
|
||||
return;
|
||||
@@ -189,13 +185,21 @@ final class CognitoAuthFlowHandler {
|
||||
throw new AwsException("InvalidParameterException", authFlow + " flow not enabled for this client", 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* A client with no stored list, as one persisted before the default was materialised, gets the
|
||||
* AWS default rather than every flow.
|
||||
*/
|
||||
private static List<String> enabledAuthFlows(UserPoolClient client) {
|
||||
List<String> enabled = client.getExplicitAuthFlows();
|
||||
return enabled == null || enabled.isEmpty() ? CognitoService.DEFAULT_EXPLICIT_AUTH_FLOWS : enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh has to be listed explicitly via {@code ALLOW_REFRESH_TOKEN_AUTH}, except on clients that
|
||||
* only use legacy (non {@code ALLOW_}) values, where refresh was never gated.
|
||||
*/
|
||||
private static void requireRefreshEnabled(UserPoolClient client, String authFlow) {
|
||||
List<String> enabled = client.getExplicitAuthFlows();
|
||||
if (enabled == null || enabled.stream().noneMatch(flow -> flow.startsWith("ALLOW_"))) {
|
||||
if (enabledAuthFlows(client).stream().noneMatch(flow -> flow.startsWith("ALLOW_"))) {
|
||||
return;
|
||||
}
|
||||
requireFlowEnabled(client, authFlow, "ALLOW_REFRESH_TOKEN_AUTH");
|
||||
|
||||
@@ -84,6 +84,8 @@ import static io.github.hectorvent.floci.core.common.ReservedTags.rejectUnknownR
|
||||
@ApplicationScoped
|
||||
public class CognitoService implements ResourceProvider {
|
||||
private static final int DEFAULT_REFRESH_TOKEN_VALIDITY_DAYS = 30;
|
||||
static final List<String> DEFAULT_EXPLICIT_AUTH_FLOWS =
|
||||
List.of("ALLOW_REFRESH_TOKEN_AUTH", "ALLOW_USER_SRP_AUTH", "ALLOW_CUSTOM_AUTH");
|
||||
private static final String COGNITO_PASSWORD_SYMBOLS =
|
||||
"^$*.[]{}()?\"!@#%&/\\,><':;|_~`=+-";
|
||||
// JVM-local stripes bound lock memory without retaining one lock for every user key.
|
||||
|
||||
Reference in new issue
Block a user