Skip to content

Commit

Permalink
feat: security headers by default (#186)
Browse files Browse the repository at this point in the history
* feat: security headers by default

* chore: self mutation

Signed-off-by: github-actions <[email protected]>

---------

Signed-off-by: github-actions <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
bestickley and github-actions authored Dec 15, 2023
1 parent 988dac7 commit a8b5c4a
Show file tree
Hide file tree
Showing 10 changed files with 1,062 additions and 136 deletions.
1,153 changes: 1,025 additions & 128 deletions API.md

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/NextjsDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,35 @@ export class NextjsDistribution extends Construct {
override: false,
// by default tell browser to cache static files for this long
// this is separate from the origin cache policy
// copied from: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#caching_static_assets_with_cache_busting
value: `public,max-age=${Duration.days(30).toSeconds()},immutable`,
},
// below security headers copied from: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html#managed-response-headers-policies-security
{
header: 'referrer-policy',
override: false,
value: 'strict-origin-when-cross-origin',
},
{
header: 'strict-transport-security',
override: false,
value: 'max-age=31536000',
},
{
header: 'x-content-type-options',
override: true,
value: 'nosniff',
},
{
header: 'x-frame-options',
override: false,
value: 'SAMEORIGIN',
},
{
header: 'x-xss-protection',
override: false,
value: '1; mode=block',
},
],
},
});
Expand Down Expand Up @@ -248,6 +275,7 @@ export class NextjsDistribution extends Construct {
cachePolicy,
edgeLambdas: this.edgeLambdas.length ? this.edgeLambdas : undefined,
functionAssociations: this.createCloudFrontFnAssociations(),
responseHeadersPolicy: ResponseHeadersPolicy.SECURITY_HEADERS,
...this.props.overrides?.serverBehaviorOptions,
};
}
Expand Down Expand Up @@ -295,6 +323,7 @@ export class NextjsDistribution extends Construct {
cachePolicy,
originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
edgeLambdas: this.edgeLambdas,
responseHeadersPolicy: ResponseHeadersPolicy.SECURITY_HEADERS,
...this.props.overrides?.imageBehaviorOptions,
};
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsDistributionProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsDomainProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsImageProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsInvalidationProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsRevalidationProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsServerProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/generated-structs/OptionalNextjsStaticAssetsProps.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a8b5c4a

Please sign in to comment.