Hardening a CloudFront origin with a secret custom header and WAF
Short answer
A Store a rotated secret in Secrets Manager, have CloudFront inject it as an origin custom header, and require that header with an AWS WAF rule on the ALB.
Question
Key Takeaways
A secret, rotated custom header injected by CloudFront plus an AWS WAF string-match rule on the ALB restricts origin access to CloudFront only, because direct ALB requests will not carry the secret header.
With CloudFront as the only origin for an ALB, an attacker could hit the ALB directly. Storing a random string in Secrets Manager (with rotation), injecting it as a CloudFront origin-request custom header, and requiring that header via an AWS WAF rule on the ALB ensures only CloudFront-sourced requests reach the origin.
Common mistake: Trying to allowlist CloudFront IP ranges (Options B/D) — the ranges change frequently and are not a robust secret-based control; a secret header is the recommended pattern.
Expert Analysis
Why the Answer Is Correct
Option A stores a random string in Secrets Manager with automatic rotation, configures CloudFront to add it as a custom origin-request header, and attaches an AWS WAF string-match rule to the ALB that allows only requests carrying that header. Direct hits to the ALB without the secret header are blocked, hardening the origin.
Why the Other Options Are Wrong
Option B's text is malformed and relies on CloudFront IP allowlisting, which is brittle because the IP ranges change. Option C uses Parameter Store but only 'inspects' the header at the ALB without a WAF enforcement rule. Option D uses Shield Advanced and security-group IP allowlisting, again dependent on changing CloudFront IP ranges rather than a shared secret.
Community Comment Notes
kejam (likes 6) links the AWS blog on using CloudFront custom headers, WAF, and Secrets Manager to restrict origin access. Win007 argues for D, but Shield Advanced does not by itself enforce the secret-header origin restriction.
Official Reference
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/restrict-access-to-origin.html
This link opens the official vendor documentation in a new tab.
Community Votes
100% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 8 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 8
-
kejam 👍 6 Answered AIn this blog post, you’ll see how to use CloudFront custom headers, AWS WAF, and AWS Secrets Manager to restrict viewer requests from accessing your CloudFront origin resources directly. https://aws.amazon.com/blogs/security/how-to-enhance-amazon-cloudfront-origin-security-with-aws-waf-and-aws-secrets-manager/
-
HunkyBunky 👍 2 Answered AA - is a proper answer https://aws.amazon.com/blogs/security/how-to-enhance-amazon-cloudfront-origin-security-with-aws-waf-and-aws-secrets-manager/
-
AzureDP900 👍 1Option A is right Store a random string in Secrets Manager: This provides a secure way to store sensitive data, such as a token or secret key. Create an AWS Lambda function for automatic secret rotation: This ensures that the secret is regularly rotated and updated to prevent unauthorized access. Configure CloudFront to inject the random string as a custom HTTP header for the origin request: This adds an additional layer of protection by requiring the ALB to verify the custom header before allowing access. Create an AWS WAF web ACL rule with a string match rule for the custom header: This checks that the custom header matches the expected value, preventing unauthorized access if it doesn't. Associate the web ACL with the ALB: This ensures that the security rules are enforced at the edge of the network, protecting against malicious traffic. The other options don't provide sufficient protection:
-
SIJUTHOMASP 👍 1 Answered BWhile secret manager can auto rotate the secrets why to use Lamda to rotate? The choice B is neater than A?
-
alexis123456 👍 4Correct Answer is A
Show 3 more comments
-
Win007 👍 1D is the correct Answer
-
TheCloudGuruu 👍 1 Answered AAnswer is A
-
career360guru 👍 1 Answered AOption A
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All SAP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full SAP-C02 Practice Test →