Response Headers

Response Headers

In this section, you add security headers to the responses that your CloudFront distribution returns to viewers. CloudFront response headers policies let you do this without changing the origin and without writing Lambda@Edge or CloudFront Functions code.

  1. Select Distributions, then select your distribution ID.
  • On the Behaviors tab, select the Default (*) behavior and click Edit.

CloudFront Lab

  1. Open the Response headers policy - optional drop-down list and select SecurityHeadersPolicy.

CloudFront Lab

SecurityHeadersPolicy is an AWS managed policy that adds headers such as Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, X-XSS-Protection and Referrer-Policy. CloudFront always adds X-Content-Type-Options: nosniff, even if the origin response already contains this header. For the other headers in the policy, if the origin response already contains the header, CloudFront keeps the origin’s header and value instead of the one in the policy.

  1. Wait until the distribution finishes deploying. Then open your CloudFront URL, open the browser’s developer tools, go to the Network tab and reload the page.
  • Select the request to your CloudFront domain and look at the Response Headers section. The security headers added by the policy, such as X-Frame-Options: SAMEORIGIN and X-Xss-Protection: 1; mode=block, appear in the list.

CloudFront Lab