Skip to content

Commit 511eab3

Browse files
authored
docs(cloudfront): updates to CloudFront ResponseHeadersPolicy XSSProtection (#31301)
### Issue # (if applicable) Closes #20962 ### Reason for this change Update the documentation to have a deployable example. ### Description of changes Set `modeBlock` to false when `reportUri` is set. You cannot specify a ReportUri when ModeBlock is true. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-responseheaderspolicy-xssprotection.html ### Description of how you validated changes Updated the tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a3863a6 commit 511eab3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/aws-cdk-lib/aws-cloudfront/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ You can configure CloudFront to add one or more HTTP headers to the responses th
308308
To specify the headers that CloudFront adds to HTTP responses, you use a response headers policy. CloudFront adds the headers regardless of whether it serves the object from the cache or has to retrieve the object from the origin. If the origin response includes one or more of the headers that’s in a response headers policy, the policy can specify whether CloudFront uses the header it received from the origin or overwrites it with the one in the policy.
309309
See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-response-headers.html
310310

311+
> [!NOTE]
312+
> If xssProtection `reportUri` is specified, then `modeBlock` cannot be set to `true`.
313+
311314
```ts
312315
// Using an existing managed response headers policy
313316
declare const bucketOrigin: origins.S3Origin;
@@ -343,7 +346,7 @@ const myResponseHeadersPolicy = new cloudfront.ResponseHeadersPolicy(this, 'Resp
343346
frameOptions: { frameOption: cloudfront.HeadersFrameOption.DENY, override: true },
344347
referrerPolicy: { referrerPolicy: cloudfront.HeadersReferrerPolicy.NO_REFERRER, override: true },
345348
strictTransportSecurity: { accessControlMaxAge: Duration.seconds(600), includeSubdomains: true, override: true },
346-
xssProtection: { protection: true, modeBlock: true, reportUri: 'https://example.com/csp-report', override: true },
349+
xssProtection: { protection: true, modeBlock: false, reportUri: 'https://example.com/csp-report', override: true },
347350
},
348351
removeHeaders: ['Server'],
349352
serverTimingSamplingRate: 50,

packages/aws-cdk-lib/aws-cloudfront/test/response-headers-policy.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('ResponseHeadersPolicy', () => {
6262
frameOptions: { frameOption: HeadersFrameOption.DENY, override: true },
6363
referrerPolicy: { referrerPolicy: HeadersReferrerPolicy.NO_REFERRER, override: true },
6464
strictTransportSecurity: { accessControlMaxAge: Duration.seconds(600), includeSubdomains: true, override: true },
65-
xssProtection: { protection: true, modeBlock: true, reportUri: 'https://example.com/csp-report', override: true },
65+
xssProtection: { protection: true, modeBlock: false, reportUri: 'https://example.com/csp-report', override: true },
6666
},
6767
removeHeaders: ['Server'],
6868
serverTimingSamplingRate: 12.3456,
@@ -136,7 +136,7 @@ describe('ResponseHeadersPolicy', () => {
136136
Override: true,
137137
},
138138
XSSProtection: {
139-
ModeBlock: true,
139+
ModeBlock: false,
140140
Override: true,
141141
Protection: true,
142142
ReportUri: 'https://example.com/csp-report',

0 commit comments

Comments
 (0)