mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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 <hectorvent@gmail.com>
This commit is contained in:
1 parent
bc237ae980
commit
504c9d23bb
2 files changed
+21
-1
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
+16
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user