Skip to content

Commit 3e55092

Browse files
authored
fix(certificatemanager): domainName not checked for length (#21807)
## fix(AWS-CertificateManager) cap domain name to 64 characters *fix for*: #21777 *motivation*: if a domainName that is longer than 64 characters is provided, certification creation will fail - this implements a check for string length ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7472fa4 commit 3e55092

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ export class Certificate extends CertificateBase implements ICertificate {
227227
}
228228
}
229229

230+
// check if domain name is 64 characters or less
231+
if (props.domainName.length > 64) {
232+
throw new Error('Domain name must be 64 characters or less');
233+
}
234+
230235
const allDomainNames = [props.domainName].concat(props.subjectAlternativeNames || []);
231236

232237
let certificateTransparencyLoggingPreference: string | undefined;

packages/@aws-cdk/aws-certificatemanager/lib/dns-validated-certificate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ export class DnsValidatedCertificate extends CertificateBase implements ICertifi
8484
super(scope, id);
8585

8686
this.region = props.region;
87-
8887
this.domainName = props.domainName;
88+
// check if domain name is 64 characters or less
89+
if (this.domainName.length > 64) {
90+
throw new Error('Domain name must be 64 characters or less');
91+
}
8992
this.normalizedZoneName = props.hostedZone.zoneName;
9093
// Remove trailing `.` from zone name
9194
if (this.normalizedZoneName.endsWith('.')) {
9295
this.normalizedZoneName = this.normalizedZoneName.substring(0, this.normalizedZoneName.length - 1);
9396
}
94-
9597
// Remove any `/hostedzone/` prefix from the Hosted Zone ID
9698
this.hostedZoneId = props.hostedZone.hostedZoneId.replace(/^\/hostedzone\//, '');
9799
this.tags = new cdk.TagManager(cdk.TagType.MAP, 'AWS::CertificateManager::Certificate');

packages/@aws-cdk/aws-certificatemanager/test/certificate.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ test('can configure validation method', () => {
8181
});
8282
});
8383

84+
test('throws when domain name is longer than 64 characters', () => {
85+
const stack = new Stack();
86+
87+
expect(() => {
88+
new Certificate(stack, 'Certificate', {
89+
domainName: 'example.com'.repeat(7),
90+
});
91+
}).toThrow(/Domain name must be 64 characters or less/);
92+
});
93+
94+
8495
test('needs validation domain supplied if domain contains a token', () => {
8596
const stack = new Stack();
8697

@@ -363,4 +374,5 @@ describe('Transparency logging settings', () => {
363374
CertificateTransparencyLoggingPreference: 'DISABLED',
364375
});
365376
});
366-
});
377+
});
378+

packages/@aws-cdk/aws-certificatemanager/test/dns-validated-certificate.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,21 @@ test('works with imported role', () => {
225225
});
226226
});
227227

228+
229+
test('throws when domain name is longer than 64 characters', () => {
230+
const stack = new Stack();
231+
232+
const exampleDotComZone = new PublicHostedZone(stack, 'ExampleDotCom', {
233+
zoneName: 'example.com',
234+
});
235+
expect(() => {
236+
new DnsValidatedCertificate(stack, 'Cert', {
237+
domainName: 'example.com'.repeat(7),
238+
hostedZone: exampleDotComZone,
239+
});
240+
}).toThrow(/Domain name must be 64 characters or less/);
241+
}),
242+
228243
test('test transparency logging settings is passed to the custom resource', () => {
229244
const stack = new Stack();
230245

0 commit comments

Comments
 (0)