From 504c9d23bb18509ede53e00b860e26faef457ca7 Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Sat, 31 Oct 2026 13:05:03 -0500 Subject: [PATCH] fix(cognito): refuse a custom domain certificate from another partition or account (#7110) requireUsableCertificate checked only the certificate ARN's service, region and resource. ACM finds a certificate by its id in the caller's own account, so an ARN naming another partition or another account was accepted as the caller's certificate. Both now get the same InvalidParameterException as any other unusable certificate. Signed-off-by: Hector Ventura --- .../floci/services/cognito/CognitoService.java | 6 +++++- .../CognitoCustomDomainPartitionTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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.java index 20cc0b4686..dfe7e8e85e 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 @@ -2026,7 +2026,9 @@ public class CognitoService implements ResourceProvider { /** * AWS accepts only an issued ACM certificate from us-east-1 behind a custom domain, and answers - * anything else with this one message. + * anything else with this one message. ACM finds a certificate by its id alone, so the ARN's + * partition and account are checked here: a certificate in another partition or account is + * never the caller's. */ private void requireUsableCertificate(String certificateArn) { AwsArnUtils.Arn arn; @@ -2036,6 +2038,8 @@ public class CognitoService implements ResourceProvider { throw new AwsException("InvalidParameterException", CERTIFICATE_NOT_USABLE, 400); } if (!"acm".equals(arn.service()) || !CERTIFICATE_REGION.equals(arn.region()) + || !arn.partition().equals(regionResolver.getPartition()) + || !arn.accountId().equals(regionResolver.getAccountId()) || !arn.resource().startsWith("certificate/")) { throw new AwsException("InvalidParameterException", CERTIFICATE_NOT_USABLE, 400); } diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainPartitionTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainPartitionTest.java index 74d0611cf5..05a00b3ef9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainPartitionTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainPartitionTest.java @@ -109,4 +109,20 @@ class CognitoCustomDomainPartitionTest { UserPoolDomain updated = service.updateUserPoolDomain(CUSTOM_DOMAIN, poolId, replacement, null); assertEquals(replacement.get("CertificateArn"), updated.getCertificateArn()); } + + @ParameterizedTest + @ValueSource(strings = { + "arn:aws-cn:acm:us-east-1:000000000000:certificate/abc", + "arn:aws:acm:us-east-1:111111111111:certificate/abc"}) + void aCertificateFromAnotherPartitionOrAccountIsRefused(String certificateArn) { + CognitoService service = serviceIn("us-east-1"); + String poolId = createPool(service, "us-east-1"); + + AwsException error = assertThrows(AwsException.class, () -> service.createUserPoolDomain( + CUSTOM_DOMAIN, poolId, Map.of("CertificateArn", certificateArn), null)); + + assertEquals("InvalidParameterException", error.getErrorCode()); + assertThat(error.getMessage(), containsString("SSL certificate doesn't exist")); + assertTrue(service.findCustomDomain(CUSTOM_DOMAIN).isEmpty()); + } }