Description
To reject viewer HTTP, set viewer_protocol_policy to https-only for each CloudFront cache behavior. Use redirect-to-https where viewers should be redirected.
Potential impact
Even with a redirect, the first HTTP request exposes any parameters, credentials or session information it carries.
Remediation
Update clients and links to start with HTTPS. Check the certificate and TLS policy, and test HTTP rejection or redirection for the default and any additional cache behaviors. Protect the connection from CloudFront to the origin separately.
Examples
The excerpts compare the default cache behavior only. Supply the actual origin configuration, cache policy and other settings needed for deployment.
Before
- name: Create a CloudFront distribution
community.aws.cloudfront_distribution:
state: present
caller_reference: unique-test-distribution-id
origins:
- id: my-test-origin
domain_name: www.example.com
default_cache_behavior:
target_origin_id: my-test-origin
viewer_protocol_policy: allow-all
allow-all accepts both HTTP and HTTPS.
After
- name: Create a CloudFront distribution
community.aws.cloudfront_distribution:
state: present
caller_reference: unique-test-distribution-id
origins:
- id: my-test-origin
domain_name: www.example.com
default_cache_behavior:
target_origin_id: my-test-origin
viewer_protocol_policy: https-only
https-only rejects HTTP requests that match this default behavior.