Skip to content

Commit

Permalink
Add security-related options to CDN construct
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Mar 16, 2024
1 parent 177e081 commit bdf437f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cdk/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class Stack extends cdk.Stack {
const staticBehaviorOptions: cdk.aws_cloudfront.BehaviorOptions = {
origin: new cdk.aws_cloudfront_origins.S3Origin(bucket),
cachePolicy: cdk.aws_cloudfront.CachePolicy.CACHING_OPTIMIZED,
viewerProtocolPolicy:
cdk.aws_cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
};

const distribution = new cdk.aws_cloudfront.Distribution(this, `cdn`, {
Expand Down Expand Up @@ -99,6 +101,25 @@ export class Stack extends cdk.Stack {
}),
originRequestPolicy:
cdk.aws_cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
viewerProtocolPolicy:
cdk.aws_cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
responseHeadersPolicy: new cdk.aws_cloudfront.ResponseHeadersPolicy(
this,
`response-headers-policy`,
{
securityHeadersBehavior: {
frameOptions: {
frameOption: cdk.aws_cloudfront.HeadersFrameOption.DENY,
override: true,
},
strictTransportSecurity: {
accessControlMaxAge: cdk.Duration.days(365),
includeSubdomains: true,
override: true,
},
},
},
),
},
additionalBehaviors: {
'/favicon.ico': staticBehaviorOptions,
Expand Down

0 comments on commit bdf437f

Please sign in to comment.