aws-solutions-constructs icon indicating copy to clipboard operation
aws-solutions-constructs copied to clipboard

(CloudFrontToS3): defaults - use cloudfront function instead of lambda@edge for response security headers

Open naseemkullah opened this issue 5 years ago • 7 comments

Use https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/add-security-headers/index.js for the response security header configuration default instead of lambda@edge

Use Case

See https://github.com/aws-samples/amazon-cloudfront-functions#overview for why this is an improved approach.

Proposed Solution

Replace the default lambda at edge function with the following cloudfront function https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/add-security-headers/index.js

Other

  • [ ] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

naseemkullah avatar Jun 25 '21 14:06 naseemkullah

We agree - we already have an internal task looking at making this replacement! :-)

biffgaut avatar Jun 25 '21 14:06 biffgaut

Great to hear @biffgaut!

naseemkullah avatar Jun 25 '21 14:06 naseemkullah

@biffgaut can you confirm that the function would be appended to any user defined functions in defaultBehavior.functionAssociations ?

naseemkullah avatar Jun 26 '21 15:06 naseemkullah

One more request 😄 ... that the CSP header values be configurable as mentioned in https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/add-security-headers#add-http-security-headers

Important: Adjust the CSP policy to your specific needs.

Same goes for X-Frame-Options and X-XSS-Protection, though if this is out of scope for the insertHttpSecurityHeaders option, one can merely disable the option and copy paste and adjust https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/add-security-headers/index.js to suit one's needs.

naseemkullah avatar Jun 26 '21 18:06 naseemkullah

Hitendra Nishar is looking at this on our end, I've pinged him to ensure he sees your notes. Our primary goal is to not break existing code, but adding additional optional props is possible.

biffgaut avatar Jun 28 '21 13:06 biffgaut

Hi @hnishar!

For some context, we had to disable the default function (and pass in our own custom security headers cloudfront function based on https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/add-security-headers/index.js), I expect the same for other organizations.

What would make this truly usable is a nice interface for adjusting the various headers, in particular those that https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/add-security-headers#add-http-security-headers mention important to adjust to one's specific needs.

naseemkullah avatar Jun 28 '21 19:06 naseemkullah

I'm not sure if this should be a separate issue, but it would be great to be able to leverage CloudFront Functions for re-writing vanity URLs (such as example.com/about or example.com/about/) to reference a valid key when fetching via the REST API from S3 as required when using CloudFront Origin Access Identity.

ranrotx avatar Jul 21 '21 15:07 ranrotx