CloudFront Response Headers Deployer
What this skill does
Provisions CloudFront response headers policies with secure defaults —
security headers (CSP, HSTS, X-Frame-Options, X-Content-Type-Options,
Referrer-Policy, Permissions-Policy), CORS configuration (origins,
methods, headers, credentials, preflight), custom headers (Cache-Control,
X-Custom), and removal headers (Server, X-Powered-By). Picks between
managed policies (SecurityHeadersPolicy, CORSAndHTTPSecurityHeadersPolicy,
SimpleCORS, CORS-with-preflight-and-SecurityHeadersPolicy) and custom
policies based on the operator's requirements. Runs deterministic
requirement checks before emitting the template — if all checks pass, the
verdict is READY_TO_DEPLOY with the populated CloudFormation / Terraform
template and the distribution update plan. If a requirement is missing
(no distribution to attach, conflicting managed policy reference, custom
origin not reachable), the verdict is PREREQUISITES_MISSING with the
specific gap and the exact CLI / IaC snippet that closes it.
Quick navigation
| Section |
What it covers |
When to read it |
| § Quick reference |
Verdict thresholds + requirement checklist + capability matrix |
Before any build |
| § Mindset |
Why response headers policies, the attach-vs-embed distinction, managed vs custom |
Understanding the design model |
| § Pre-flight |
Requirement gate — distribution exists, origin reachable, cache policy compatibility |
Before emitting any template |
| § Process |
Per-header design: security, CORS, custom, removal, managed |
When designing each layer |
| § STRICT output contract |
Required labels + FORBIDDEN patterns + self-check |
Before emitting any block |
| § Expert heuristic |
The 5 non-obvious failure modes that miss naive header setups |
Defense-in-depth |
| § Anti-Patterns |
NEVER list — common mistakes that silently break headers |
Review before emitting |
Quick reference — verdict thresholds
| Verdict |
Trigger condition |
Action |
READY_TO_DEPLOY |
All requirements satisfied (distribution exists or will be created alongside, origin reachable, no conflicting policy reference, managed policy ARN valid if used, CORS origin list consistent with cert SAN). Template generated. |
Emit complete response headers policy template + distribution update plan |
PREREQUISITES_MISSING |
One or more requirements missing (distribution does not exist; managed policy does not exist in this account/region; CORS origin uses * with AllowCredentials: true; CSP conflicts with inline scripts; origin not reachable). |
Emit the specific gap and the exact CLI / IaC snippet to close it. Hold the partial template as a draft. |
Requirement checklist (all must be satisfied for READY_TO_DEPLOY):
- Target distribution — exists (for attach-to-existing) or will be
created alongside the policy (for greenfield). Verify via
aws cloudfront get-distribution-config --id <id>.
- Cache behavior target —
DefaultCacheBehavior or a specific
CacheBehavior (matched by PathPattern). The policy attaches at
the behavior level, not the distribution level.
- Origin reachable — for CORS with credentials, the origin must be
HTTPS (not HTTP). CloudFront rejects
Access-Control-Allow-Origin: *
combined with Access-Control-Allow-Credentials: true.
- Managed policy ARN (if used) —
SecurityHeadersPolicy,
CORSAndHTTPSecurityHeadersPolicy, SimpleCORS, or
CORS-with-preflight-and-SecurityHeadersPolicy exist as AWS-managed
policies with fixed IDs (0857826db9cffff310d5ad62955c9c26 etc.).
- CORS origin list — specific origins or
*. If *, the policy
MUST NOT set Access-ControlAllowCredentials: true (browser rejects).
- CSP compatibility — if CSP includes
script-src 'self', no
inline <script> tags are allowed on the origin. If the site uses
inline scripts, CSP must include 'unsafe-inline' or nonces.
- HSTS includesubdomains — must match the actual domain scope. If
subdomains are served by a different CDN,
IncludeSubDomains will
pin them to HTTPS irreversibly for the HSTS duration.
- Removal header list —
Server, X-Powered-By, and any custom
fingerprint headers. CloudFront adds its own Server: CloudFront
and Via headers — these cannot be removed.
- Distribution state — must be
Deployed to attach a policy. A
distribution in InProgress state rejects updates.
- Cache policy compatibility — response headers policies are
orthogonal to cache policies (one controls what CloudFront sends to
viewers; the other controls what CloudFront caches from origins).
No conflict possible, but the operator should know both are set.
Capability matrix (which AWS service handles each layer):
| Layer |
Service |
Common pitfalls |
| Security headers |
CloudFront response headers policy |
CSP too strict breaks site; HSTS too long is irreversible |
| CORS |
CloudFront response headers policy |
* + credentials = browser reject; preflight missing |
| Custom headers |
CloudFront response headers policy |
Cannot override Server, Via (CloudFront-injected) |
| Removal headers |
CloudFront response headers policy |
Removal list MUST match exact header names (case-sensitive) |
| Managed policies |
AWS-managed, fixed IDs |
Cannot modify; fork to custom if extension needed |
| Attachment |
Distribution cache behavior |
Policy attaches at behavior level; distribution update required |
Mindset
One-line takeaway: a response headers policy is the only CloudFront
configuration surface that lets you add, modify, or remove HTTP response
headers without writing Lambda@Edge or CloudFront Functions. It is a
managed feature (no compute, no cost beyond the policy object storage).
Driven by three realities:
→ The three realities (Lambda@Edge replacement, wildcard+credentials silent rejection, fixed managed IDs) — references/advanced-patterns.md.
Pre-flight: requirement gate
Run before emitting any template. Missing requirements produce
PREREQUISITES_MISSING with the exact gap.
Live-account pre-flight (skip if offline plan audit):
→ Full 6-check CLI listing (distribution Deployed state, policy inventory + snapshot, origin HTTPS, cache-policy conflict, managed ID) — references/diagnostic-commands.md.
Malformed input: if the input scenario is missing required fields
(distribution ID or "create new", target behavior, header requirements),
emit VERDICT: PREREQUISITES_MISSING with GAP: Scenario missing required field <field>. Provide <field> to proceed.
| Requirement |
Effect on automation |
| Distribution does not exist |
PREREQUISITES_MISSING — emit create-distribution snippet or operator confirms "create alongside". |
Distribution state is InProgress |
PREREQUISITES_MISSING — wait for deployment; emit wait-and-retry note. |
| Policy name already exists |
AUTOMATED (the template updates in place; emit CONFIRM gate). |
CORS * with credentials |
PREREQUISITES_MISSING — emit specific-origin-list or disable-credentials snippet. |
| CSP conflicts with known site scripts |
PREREQUISITES_MISSING — emit CSP with 'unsafe-inline' or nonce-based snippet. |
| HSTS IncludeSubDomains with subdomains on different CDN |
PREREQUISITES_MISSING — emit HSTS without IncludeSubDomains snippet. |
| Origin not reachable on HTTPS |
PREREQUISITES_MISSING — emit HTTPS enablement snippet. |
| Managed policy ID malformed |
PREREQUISITES_MISSING — emit correct managed policy ID. |
Process — response headers policy design (apply in order)
Step 0: Expert knowledge — non-obvious CloudFront header behaviors
→ All 12 non-obvious behaviors (immutable+ETag, Server/Via, CSP baseline, XFO redundancy, HSTS preload, preflight cache, credentials, override, managed auto-update, cached errors, behavior attach, Permissions-Policy) — references/advanced-patterns.md.
Step 1: Security headers design
| Header |
Recommended value |
Why |
Content-Security-Policy |
default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self' |
Mitigates XSS, clickjacking, data injection |
Strict-Transport-Security |
max-age=63072000; includeSubDomains; preload (production); max-age=300 (testing) |
Forces HTTPS, prevents SSL stripping |
X-Frame-Options |
DENY (or SAMEORIGIN if iframes needed) |
Clickjacking defense (legacy browsers) |
X-Content-Type-Options |
nosniff |
Prevents MIME-type sniffing |
Referrer-Policy |
strict-origin-when-cross-origin |
Limits referrer leakage to cross-origin |
Permissions-Policy |
camera=(), microphone=(), geolocation=(), payment=() |
Disables browser feature APIs |
Step 2: CORS configuration design
| Decision |
Default |
Why |
AllowOrigin |
specific origins (NOT * for credentialed) |
* + credentials = browser reject |
AllowMethods |
["GET", "HEAD", "OPTIONS"] (read-only); add POST, PUT, DELETE for write APIs |
Least-privilege |
AllowHeaders |
["Authorization", "Content-Type"] |
Headers the browser is allowed to send |
ExposeHeaders |
[] (add X-Total-Count etc. for pagination) |
Headers the browser JS can read |
AllowCredentials |
false (set true only for cookie-bearing requests) |
Credentials + * origin is invalid |
MaxAgeSec |
86400 (1 day) |
Browser preflight cache duration |
Origin reflection pattern (echo back the requesting Origin header)
is NOT supported by response headers policies — use Lambda@Edge or
CloudFront Functions for origin reflection.
Step 3: Custom headers design
| Use case |
Header |
Value |
| Force browser caching |
Cache-Control |
public, max-age=3600 |
| Disable browser caching |
Cache-Control |
no-store |
| Sensitivity label |
X-Content-Classification |
Restricted |
| Service version |
X-Service-Version |
1.2.3 |
Custom headers OVERRIDE origin-emitted headers with the same name.
Step 4: Removal headers design
| Header |
Why remove |
Server |
Fingerprint (CANNOT be removed in CloudFront — silently ignored) |
X-Powered-By |
Framework fingerprint (PHP, Express, etc.) |
X-AspNet-Version |
.NET framework fingerprint |
X-AspNetMvc-Version |
.NET MVC fingerprint |
Via |
Proxy fingerprint (CANNOT be removed in CloudFront) |
Step 5: Managed policy selection
| Managed policy |
When to use |
SecurityHeadersPolicy (0857826db9cffff310d5ad62955c9c26) |
Security headers only (HSTS, X-Frame-Options DENY, X-Content-Type-Options nosniff, Referrer-Policy strict-origin-when-cross-origin) |
SimpleCORS (608323ce734e4449839d234493be9c7c) |
Simple CORS (no preflight); allows all origins |
CORS-with-preflight-and-SecurityHeadersPolicy (5cc3b908-e619-4b99-88e5-2ca770afe08f) |
Combined CORS + preflight + security headers |
CORSAndHTTPSecurityHeadersPolicy (e0bbb029-0798-45b7-9b86-9e6a1c2670e4) |
Combined CORS + security headers (no preflight) |
Always emit a custom policy if the operator's requirements differ from
any managed policy — managed policies cannot be modified.
Step 6: Attach policy to distribution
The policy attaches to a cache behavior. Use
get-distribution-config --id <id> to retrieve the current config,
modify the target behavior's ResponseHeadersPolicyId, and call
update-distribution with the retrieved ETag.
ETAG=$(aws cloudfront get-distribution-config --id <id> \
--query 'ETag' --output text)
aws cloudfront update-distribution --id <id> \
--if-match "$ETAG" \
--distribution-config file://updated-config.json
Step 7: Emit template (READY_TO_DEPLOY) or gap (PREREQUISITES_MISSING)
If all pre-flight requirements pass, emit the complete response headers
policy template + the distribution update plan:
AWS::CloudFront::ResponseHeadersPolicy (custom policy).
- OR the managed policy ID reference (for managed policy path).
- The
AWS::CloudFront::Distribution update (set
ResponseHeadersPolicyId on the target cache behavior).
AWS::CloudFront::CachePolicy (if a new cache policy is also needed).
If any requirement is missing, emit PREREQUISITES_MISSING with the
specific gap and the exact CLI / IaC snippet to close it.
Patterns — IaC templates
Full CloudFormation and Terraform templates for both custom and managed
policy paths live in references/response-headers-policy-templates.md.
→ The two non-negotiable config blocks (SecurityHeadersConfig + credentialed CorsConfig) — references/response-headers-policy-templates.md.
Diagnostic flows
→ All four flows (headers not appearing, CSP breakage, CORS preflight failure, HSTS breaking subdomains) — references/error-handling.md.
Output format (per operation)
→ Full per-operation label contract — references/worked-examples.md (the STRICT output contract below remains authoritative).
FORBIDDEN output patterns — NEVER
NEVER emit VERDICT: READY_TO_DEPLOY while any CHECKLIST item is
[ ] (unchecked). A single unchecked item forces
PREREQUISITES_MISSING.
NEVER emit a CORS config with Access-Control-Allow-Origin: *
combined with AllowCredentials: true. Browsers reject this
combination silently — CloudFront serves the headers, the browser
console shows the CORS error, and no CloudFront metric fires.
NEVER emit security headers with Override: false. Without
Override: true, origin-emitted headers (often absent or weak) win
over the policy. The CloudFront API accepts Override: false
silently. Every security header in the policy MUST be Override: true.
NEVER emit HSTS: max-age=63072000; includeSubDomains; preload on a
non-production distribution. HSTS is irreversible for the max-age
duration — once a browser sees it, all subdomains are HTTPS-only for
2 years. Use max-age=300 for testing; reserve the 2-year duration
for verified production sites.
NEVER emit a RemoveHeaders list that includes Server or Via.
CloudFront injects these at the edge and silently ignores removal
attempts. List only origin-emitted fingerprint headers
(X-Powered-By, X-AspNet-Version).
NEVER emit X-Frame-Options: ALLOW-FROM. ALLOW-FROM is deprecated
and ignored by modern browsers. Use DENY or SAMEORIGIN, and use
CSP frame-ancestors for fine-grained control.
NEVER auto-execute update-distribution without the current ETag
from get-distribution-config. Without --if-match <etag>, the
update fails with PreconditionFailed and provides no warning
during planning.
Worked example — READY_TO_DEPLOY (distribution with HSTS + X-Frame-Options + CSP)
DISTRIBUTION_ID: E27TVSIEXAMPLE1A
VERDICT: READY_TO_DEPLOY
CHECKLIST:
[x] Target distribution: E27TVSIEXAMPLE1A exists in Deployed state (verified via get-distribution-config)
[x] Target behavior: DefaultCacheBehavior (PathPattern: * — catch-all)
[x] Response headers policy:
- Security headers:
Content-Security-Policy: "default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'"
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()
- CORS: not configured (same-origin app — no cross-origin requirements)
- Custom headers: X-Content-Classification=Restricted, X-Service-Version=1.2.3
- Removal headers: X-Powered-By, X-AspNet-Version (CloudFront Server/Via intentionally not listed — cannot be removed)
[x] Policy origin: custom (managed SecurityHeadersPolicy does not include CSP frame-ancestors 'none' + Permissions-Policy simultaneously)
[x] Override: true on every security header (CSP, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy)
[x] Attach plan: get-distribution-config E27TVSIEXAMPLE1A → capture ETag → update-distribution with --if-match
GAP: None
IAC_TEMPLATE:
# CloudFormation — AWS::CloudFront::ResponseHeadersPolicy (custom) +
# AWS::CloudFront::Distribution update attaching policy ID to DefaultCacheBehavior
SecurityHeadersConfig:
ContentSecurityPolicy: { Content: "default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'", Override: true }
StrictTransportSecurity: { AccessControlMaxAgeSec: 63072000, IncludeSubdomains: true, Preload: true, Override: true }
FrameOptions: { FrameOption: DENY, Override: true }
ContentTypeOptions: { Override: true }
ReferrerPolicy: { ReferrerPolicy: "strict-origin-when-cross-origin", Override: true }
PermissionsPolicy: { Content: "camera=(), microphone=(), geolocation=(), payment=()", Override: true }
CustomHeadersConfig:
Items:
- { Header: { Value: Restricted }, Name: X-Content-Classification, Override: true }
- { Header: { Value: 1.2.3 }, Name: X-Service-Version, Override: true }
RemoveHeadersConfig:
Items: [X-Powered-By, X-AspNet-Version]
# Full CloudFormation / Terraform template in references/response-headers-policy-templates.md
MANUAL_GAPS: (none)
NOTES:
- Distribution update requires ETag match — call get-distribution-config E27TVSIEXAMPLE1A first.
- CloudFront invalidation recommended after attach: aws cloudfront create-invalidation --distribution-id E27TVSIEXAMPLE1A --paths "/*"
- Test CSP in Report-Only mode first if site has unknown inline scripts.
- HSTS max-age=63072000 with includeSubDomains is irreversible for 2 years — confirm all subdomains serve HTTPS before deploy.
Worked example — PREREQUISITES_MISSING (wildcard CORS + credentials)
→ Full example block — references/worked-examples.md.
Decision tree — managed policy vs custom policy
Start: response headers requirement
├─ CORS required?
│ ├─ Yes → Preflight (OPTIONS) needed?
│ │ ├─ Yes → CORS-with-preflight-and-SecurityHeadersPolicy (managed ID 5cc3b908-e619-4b99-88e5-2ca770afe08f)
│ │ │ if security headers also needed; else custom (no managed
│ │ │ preflight-only policy)
│ │ └─ No → CORSAndHTTPSecurityHeadersPolicy (managed ID e0bbb029-0798-45b7-9b86-9e6a1c2670e4)
│ │ OR SimpleCORS (managed ID 608323ce734e4449839d234493be9c7c) if no security headers
│ └─ No → Security headers only?
│ ├─ Default OWASP baseline sufficient?
│ │ ├─ Yes → SecurityHeadersPolicy (managed ID 0857826db9cffff310d5ad62955c9c26)
│ │ └─ No → Custom (CSP / Permissions-Policy / HSTS tweak required)
│ └─ Custom or removal headers needed?
│ └─ Yes → Custom policy (managed policies cannot be modified)
└─ Wildcard origin "*" with credentials true? → ALWAYS PREREQUISITES_MISSING
STRICT output contract
The rules below are hard constraints. Violating any one produces a
response headers policy that fails silently (no headers in browser,
CSP breaks site, CORS rejected) or a gap report that leaves the
operator stuck. Self-check EVERY emitted block against these rules.
Required output structure
Every response MUST be a single block using these literal labels, in
this order. Do NOT substitute markdown headings or camelCase variants.
OPERATION: <create | update | attach | audit>
VERDICT: READY_TO_DEPLOY | PREREQUISITES_MISSING
TARGET: <policy-name>
REQUIREMENTS:
- [PASS] <requirement description>
- [FAIL] <requirement description> — <gap>
IAC_TEMPLATE: <inline CloudFormation / Terraform, or "(held in draft)">
MANUAL_GAPS:
- GAP: <gap description>
REMEDIATION: <exact CLI or IaC snippet to close the gap>
REASON: <why this cannot be automated>
NOTES: <managed policy version, attach-vs-embed, distribution deploy state>
FORBIDDEN output patterns
NEVER emit VERDICT: READY_TO_DEPLOY when any requirement is
[FAIL]. A single [FAIL] MUST produce
VERDICT: PREREQUISITES_MISSING.
NEVER emit a [FAIL] requirement without a corresponding
MANUAL_GAPS entry. Every [FAIL] line MUST have a matching
GAP/REMEDIATION/REASON block.
NEVER emit a CORS config with Access-Control-Allow-Origin: *
AND Access-ControlAllowCredentials: true. Browsers reject this
combination — CloudFront will serve it but the browser console
shows a CORS error. Use specific origins or disable credentials.
NEVER emit a response headers policy with Override: false on
security headers. Without Override: true, origin-emitted headers
(often weak or absent) win over the policy values. Every security
header MUST have Override: true.
NEVER emit an HSTS config with max-age=63072000 on a
non-production distribution. HSTS is irreversible for the
max-age duration. Use max-age=300 for testing; reserve the
2-year duration for verified production sites.
NEVER emit a RemoveHeaders list including Server or Via.
CloudFront injects these at the edge and silently ignores removal
attempts. List only origin-emitted fingerprint headers.
NEVER emit IAC_TEMPLATE: (held in draft) without listing which
specific [FAIL] items blocked it.
Self-check before emit:
Expert heuristic — top 5 non-obvious failure modes
→ All five failure modes (Override:false, CSP vs inline handlers, HSTS includeSubDomains, uncached preflight, cached-error bypass) — references/advanced-patterns.md.
Anti-Patterns — NEVER do these things
NEVER emit a CORS policy with Access-Control-Allow-Origin: *
AND Access-Control-Allow-Credentials: true. Browsers reject this
combination. Use specific origins or disable credentials.
NEVER emit security headers with Override: false. Without
override, origin values (often absent or weak) win over the policy.
Every security header MUST have Override: true.
NEVER emit X-Frame-Options: ALLOW-FROM. ALLOW-FROM is
deprecated and ignored by modern browsers. Use DENY or
SAMEORIGIN, and use CSP frame-ancestors for fine-grained control.
NEVER emit an HSTS max-age=63072000 on a non-production site.
HSTS is irreversible for the duration. Use max-age=300 for testing.
NEVER emit a RemoveHeaders list including Server or Via.
CloudFront injects these at the edge and silently ignores removal.
NEVER emit a CSP without testing in Report-Only mode first. CSP
default-src 'none' will block all resources on a site with inline
scripts, external CDNs, or images from other domains. Test with
Content-Security-Policy-Report-Only first.
NEVER emit a managed policy reference assuming it covers CORS
preflight. SecurityHeadersPolicy and SimpleCORS do NOT handle
preflight. Use CORS-with-preflight-and-SecurityHeadersPolicy if
preflight is needed.
NEVER auto-execute update-distribution without the ETag match.
UpdateDistribution requires the current ETag from
get-distribution-config. Without it, the update fails with
PreconditionFailed. Always snapshot via get first.
NEVER emit a response headers policy attached to a distribution in
InProgress state. The update fails with InvalidIfMatchVersion.
Wait for Deployed state before attaching.
NEVER emit a custom header that overrides Cache-Control without
verifying the cache policy. If the cache policy honors
Cache-Control from the origin, and the response headers policy
overrides it, the cache behavior changes silently.
NEVER emit Referrer-Policy: no-referrer for a public marketing
site. no-referrer breaks analytics (Google Analytics uses the
referrer for source attribution). Use strict-origin-when-cross-origin.
NEVER assume the response headers policy applies to cached errors.
Cached 4xx/5xx responses bypass the policy. Configure custom error
responses for security headers on error pages.
Pre-flight safety checks (run before any remediation CLI)
→ Full checklist (confirmation gate, Deployed-state verify, snapshots, ETag capture, CSP inventory, HSTS subdomain check) — references/diagnostic-commands.md.
Recent AWS features (2024-2026)
→ All six updates (managed policy updates, CORS-with-preflight, OAC, Permissions-Policy GA, CloudFormation, KeyValueStore) — references/advanced-patterns.md.
References (load on demand)
references/worked-examples.md — secondary worked example (PREREQUISITES_MISSING wildcard CORS) + per-operation output format spec
references/error-handling.md — diagnostic flows: headers not appearing, CSP breakage, CORS preflight failure, HSTS breaking subdomains
references/diagnostic-commands.md — live-account pre-flight commands; pre-remediation safety checks
references/advanced-patterns.md — Step 0 non-obvious behaviors, expert-heuristic failure modes, mindset realities, recent AWS features (2024-2026)
references/response-headers-policy-templates.md — full IaC templates (pre-existing) + non-negotiable config blocks
references/security-headers-and-managed-policies.md — header semantics + managed policy matrix (pre-existing)
Domain
AWS CloudOps / CloudFront Networking — Response Headers Policy,
Security Headers, CORS Configuration, Managed Policy Selection,
Distribution Hardening.
AWS documentation
1---2name: cloudfront-response-headers-deployer3description: 'Provisions CloudFront response headers policies with secure defaults: security headers (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy), CORS configuration (access-control-allow-origin, methods, headers, credentials, expose-headers, max-age, preflight), custom headers (Cache-Control, X-Custom), removal headers (Server, X-Powered-By), managed policies (CORS-with-preflight-and-SecurityHeadersPolicy, SimpleCORS, CORSAndHTTPSecurityHeadersPolicy, SecurityHeadersPolicy), and the latest CloudFront response headers policy managed updates. Emits a deployment plan with a verdict (READY_TO_DEPLOY with full CloudFormation / Terraform template | PREREQUISITES_MISSING with specific gap and remediation). Use when provisioning security headers on a CloudFront distribution, configuring CORS for cross-origin access, attaching managed SecurityHeadersPolicy, removing server fingerprint headers, or hardening a CDN''s HTTP response posture.'4license: Apache-2.05compatibility: Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). No AWS CLI required for offline plan classification. Live-account operations use aws cloudfront create-response-headers-policy, get-response-headers-policy, update-response-headers-policy, delete-response-headers-policy, list-response-headers-policies, create-response-headers-policy-config, get-distribution-config, update-distribution, create-distribution, list-conflicting-aliases, and aws cloudfront...6metadata:7 source: https://skillmd.com/skills/jhkchan/cloudfront-response-headers-deployer8 domain: aws-cloudops9 complexity: medium10 requires_llm: 'true'11 phase: '1'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: Networking15 task_type: deploy16 skill_class: capability17 lifecycle_status: active18 verdict_shape: READY_TO_DEPLOY | PREREQUISITES_MISSING19 when_to_use: Provisioning a CloudFront response headers policy for security headers (CSP, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy); configuring CORS for cross-origin access (simple CORS, preflight, credentials); attaching a managed policy (SecurityHeadersPolicy, CORSAndHTTPSecurityHeadersPolicy, SimpleCORS, CORS-with-preflight-and-SecurityHeadersPolicy); removing server fingerprint headers (Server, X-Powered-By); setting custom headers (Cache-Control, X-Custom); or hardening a distribution's HTTP response posture before production.20 activation_triggers: create CloudFront response headers policy, CloudFront security headers, CloudFront CSP, CloudFront HSTS, CloudFront X-Frame-Options, CloudFront CORS, CloudFront access-control-allow-origin, CloudFront preflight, CloudFront managed SecurityHeadersPolicy, CloudFront SimpleCORS, CloudFront remove Server header, CloudFront remove X-Powered-By, CloudFront Cache-Control header, CloudFront Permissions-Policy, CloudFront Referrer-Policy, attach response headers policy to distribution21 invocation_schema: 'Input shape (one of): (a) a deployment spec describing header requirements (security headers + values, CORS origin/methods/headers, custom headers, removal headers, managed vs custom policy); (b) a partial spec for interactive refinement ("security headers on my distribution"); (c) an existing distribution ID for policy review against the secure-defaults checklist. Output shape: { POLICY_SPEC, VERDICT, ARCHITECTURE, CHECKLIST[], FINDINGS[], DEPLOY_COMMANDS } where VERDICT ∈ { READY_TO_DEPLOY, PREREQUISITES_MISSING }.'22 version: 0.1.023 author: Jacky Chan — AWS Community Builder24 keywords: CloudFront, response headers policy, security headers, Content-Security-Policy, CSP, Strict-Transport-Security, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, CORS, access-control-allow-origin, preflight, managed policy, SecurityHeadersPolicy, SimpleCORS, Cache-Control, custom headers, removal headers, Server header, X-Powered-By25 tags: cloudfront, networking, deploy, security-headers, cors, response-headers-policy, cdn, hardening26---2728# CloudFront Response Headers Deployer2930## What this skill does3132Provisions CloudFront response headers policies with secure defaults —33security headers (CSP, HSTS, X-Frame-Options, X-Content-Type-Options,34Referrer-Policy, Permissions-Policy), CORS configuration (origins,35methods, headers, credentials, preflight), custom headers (Cache-Control,36X-Custom), and removal headers (Server, X-Powered-By). Picks between37managed policies (`SecurityHeadersPolicy`, `CORSAndHTTPSecurityHeadersPolicy`,38`SimpleCORS`, `CORS-with-preflight-and-SecurityHeadersPolicy`) and custom39policies based on the operator's requirements. Runs deterministic40requirement checks before emitting the template — if all checks pass, the41verdict is `READY_TO_DEPLOY` with the populated CloudFormation / Terraform42template and the distribution update plan. If a requirement is missing43(no distribution to attach, conflicting managed policy reference, custom44origin not reachable), the verdict is `PREREQUISITES_MISSING` with the45specific gap and the exact CLI / IaC snippet that closes it.4647## Quick navigation4849| Section | What it covers | When to read it |50|---|---|---|51| **§ Quick reference** | Verdict thresholds + requirement checklist + capability matrix | Before any build |52| **§ Mindset** | Why response headers policies, the attach-vs-embed distinction, managed vs custom | Understanding the design model |53| **§ Pre-flight** | Requirement gate — distribution exists, origin reachable, cache policy compatibility | Before emitting any template |54| **§ Process** | Per-header design: security, CORS, custom, removal, managed | When designing each layer |55| **§ STRICT output contract** | Required labels + FORBIDDEN patterns + self-check | Before emitting any block |56| **§ Expert heuristic** | The 5 non-obvious failure modes that miss naive header setups | Defense-in-depth |57| **§ Anti-Patterns** | NEVER list — common mistakes that silently break headers | Review before emitting |5859## Quick reference — verdict thresholds6061| Verdict | Trigger condition | Action |62|---|---|---|63| `READY_TO_DEPLOY` | All requirements satisfied (distribution exists or will be created alongside, origin reachable, no conflicting policy reference, managed policy ARN valid if used, CORS origin list consistent with cert SAN). Template generated. | Emit complete response headers policy template + distribution update plan |64| `PREREQUISITES_MISSING` | One or more requirements missing (distribution does not exist; managed policy does not exist in this account/region; CORS origin uses `*` with `AllowCredentials: true`; CSP conflicts with inline scripts; origin not reachable). | Emit the specific gap and the exact CLI / IaC snippet to close it. Hold the partial template as a draft. |6566**Requirement checklist (all must be satisfied for READY_TO_DEPLOY):**67681. **Target distribution** — exists (for attach-to-existing) or will be69 created alongside the policy (for greenfield). Verify via70 `aws cloudfront get-distribution-config --id <id>`.712. **Cache behavior target** — `DefaultCacheBehavior` or a specific72 `CacheBehavior` (matched by `PathPattern`). The policy attaches at73 the behavior level, not the distribution level.743. **Origin reachable** — for CORS with credentials, the origin must be75 HTTPS (not HTTP). CloudFront rejects `Access-Control-Allow-Origin: *`76 combined with `Access-Control-Allow-Credentials: true`.774. **Managed policy ARN** (if used) — `SecurityHeadersPolicy`,78 `CORSAndHTTPSecurityHeadersPolicy`, `SimpleCORS`, or79 `CORS-with-preflight-and-SecurityHeadersPolicy` exist as AWS-managed80 policies with fixed IDs (`0857826db9cffff310d5ad62955c9c26` etc.).815. **CORS origin list** — specific origins or `*`. If `*`, the policy82 MUST NOT set `Access-ControlAllowCredentials: true` (browser rejects).836. **CSP compatibility** — if CSP includes `script-src 'self'`, no84 inline `<script>` tags are allowed on the origin. If the site uses85 inline scripts, CSP must include `'unsafe-inline'` or nonces.867. **HSTS includesubdomains** — must match the actual domain scope. If87 subdomains are served by a different CDN, `IncludeSubDomains` will88 pin them to HTTPS irreversibly for the HSTS duration.898. **Removal header list** — `Server`, `X-Powered-By`, and any custom90 fingerprint headers. CloudFront adds its own `Server: CloudFront`91 and `Via` headers — these cannot be removed.929. **Distribution state** — must be `Deployed` to attach a policy. A93 distribution in `InProgress` state rejects updates.9410. **Cache policy compatibility** — response headers policies are95 orthogonal to cache policies (one controls what CloudFront sends to96 viewers; the other controls what CloudFront caches from origins).97 No conflict possible, but the operator should know both are set.9899**Capability matrix (which AWS service handles each layer):**100101| Layer | Service | Common pitfalls |102|---|---|---|103| Security headers | CloudFront response headers policy | CSP too strict breaks site; HSTS too long is irreversible |104| CORS | CloudFront response headers policy | `*` + credentials = browser reject; preflight missing |105| Custom headers | CloudFront response headers policy | Cannot override `Server`, `Via` (CloudFront-injected) |106| Removal headers | CloudFront response headers policy | Removal list MUST match exact header names (case-sensitive) |107| Managed policies | AWS-managed, fixed IDs | Cannot modify; fork to custom if extension needed |108| Attachment | Distribution cache behavior | Policy attaches at behavior level; distribution update required |109110## Mindset111112**One-line takeaway:** a response headers policy is the only CloudFront113configuration surface that lets you add, modify, or remove HTTP response114headers without writing Lambda@Edge or CloudFront Functions. It is a115managed feature (no compute, no cost beyond the policy object storage).116Driven by three realities:117118→ The three realities (Lambda@Edge replacement, wildcard+credentials silent rejection, fixed managed IDs) — `references/advanced-patterns.md`.119120## Pre-flight: requirement gate121122Run before emitting any template. Missing requirements produce123PREREQUISITES_MISSING with the exact gap.124125**Live-account pre-flight (skip if offline plan audit):**126→ Full 6-check CLI listing (distribution Deployed state, policy inventory + snapshot, origin HTTPS, cache-policy conflict, managed ID) — `references/diagnostic-commands.md`.127128**Malformed input:** if the input scenario is missing required fields129(distribution ID or "create new", target behavior, header requirements),130emit `VERDICT: PREREQUISITES_MISSING` with `GAP: Scenario missing131required field <field>. Provide <field> to proceed.`132133| Requirement | Effect on automation |134|---|---|135| Distribution does not exist | PREREQUISITES_MISSING — emit `create-distribution` snippet or operator confirms "create alongside". |136| Distribution state is `InProgress` | PREREQUISITES_MISSING — wait for deployment; emit wait-and-retry note. |137| Policy name already exists | AUTOMATED (the template updates in place; emit CONFIRM gate). |138| CORS `*` with credentials | PREREQUISITES_MISSING — emit specific-origin-list or disable-credentials snippet. |139| CSP conflicts with known site scripts | PREREQUISITES_MISSING — emit CSP with `'unsafe-inline'` or nonce-based snippet. |140| HSTS IncludeSubDomains with subdomains on different CDN | PREREQUISITES_MISSING — emit HSTS without IncludeSubDomains snippet. |141| Origin not reachable on HTTPS | PREREQUISITES_MISSING — emit HTTPS enablement snippet. |142| Managed policy ID malformed | PREREQUISITES_MISSING — emit correct managed policy ID. |143144## Process — response headers policy design (apply in order)145146### Step 0: Expert knowledge — non-obvious CloudFront header behaviors147→ All 12 non-obvious behaviors (immutable+ETag, Server/Via, CSP baseline, XFO redundancy, HSTS preload, preflight cache, credentials, override, managed auto-update, cached errors, behavior attach, Permissions-Policy) — `references/advanced-patterns.md`.148149### Step 1: Security headers design150151| Header | Recommended value | Why |152|---|---|---|153| `Content-Security-Policy` | `default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'` | Mitigates XSS, clickjacking, data injection |154| `Strict-Transport-Security` | `max-age=63072000; includeSubDomains; preload` (production); `max-age=300` (testing) | Forces HTTPS, prevents SSL stripping |155| `X-Frame-Options` | `DENY` (or `SAMEORIGIN` if iframes needed) | Clickjacking defense (legacy browsers) |156| `X-Content-Type-Options` | `nosniff` | Prevents MIME-type sniffing |157| `Referrer-Policy` | `strict-origin-when-cross-origin` | Limits referrer leakage to cross-origin |158| `Permissions-Policy` | `camera=(), microphone=(), geolocation=(), payment=()` | Disables browser feature APIs |159160### Step 2: CORS configuration design161162| Decision | Default | Why |163|---|---|---|164| `AllowOrigin` | specific origins (NOT `*` for credentialed) | `*` + credentials = browser reject |165| `AllowMethods` | `["GET", "HEAD", "OPTIONS"]` (read-only); add `POST, PUT, DELETE` for write APIs | Least-privilege |166| `AllowHeaders` | `["Authorization", "Content-Type"]` | Headers the browser is allowed to send |167| `ExposeHeaders` | `[]` (add `X-Total-Count` etc. for pagination) | Headers the browser JS can read |168| `AllowCredentials` | `false` (set `true` only for cookie-bearing requests) | Credentials + `*` origin is invalid |169| `MaxAgeSec` | `86400` (1 day) | Browser preflight cache duration |170171**Origin reflection pattern** (echo back the requesting Origin header)172is NOT supported by response headers policies — use Lambda@Edge or173CloudFront Functions for origin reflection.174175### Step 3: Custom headers design176177| Use case | Header | Value |178|---|---|---|179| Force browser caching | `Cache-Control` | `public, max-age=3600` |180| Disable browser caching | `Cache-Control` | `no-store` |181| Sensitivity label | `X-Content-Classification` | `Restricted` |182| Service version | `X-Service-Version` | `1.2.3` |183184Custom headers OVERRIDE origin-emitted headers with the same name.185186### Step 4: Removal headers design187188| Header | Why remove |189|---|---|190| `Server` | Fingerprint (CANNOT be removed in CloudFront — silently ignored) |191| `X-Powered-By` | Framework fingerprint (PHP, Express, etc.) |192| `X-AspNet-Version` | .NET framework fingerprint |193| `X-AspNetMvc-Version` | .NET MVC fingerprint |194| `Via` | Proxy fingerprint (CANNOT be removed in CloudFront) |195196### Step 5: Managed policy selection197198| Managed policy | When to use |199|---|---|200| `SecurityHeadersPolicy` (`0857826db9cffff310d5ad62955c9c26`) | Security headers only (HSTS, X-Frame-Options DENY, X-Content-Type-Options nosniff, Referrer-Policy strict-origin-when-cross-origin) |201| `SimpleCORS` (`608323ce734e4449839d234493be9c7c`) | Simple CORS (no preflight); allows all origins |202| `CORS-with-preflight-and-SecurityHeadersPolicy` (`5cc3b908-e619-4b99-88e5-2ca770afe08f`) | Combined CORS + preflight + security headers |203| `CORSAndHTTPSecurityHeadersPolicy` (`e0bbb029-0798-45b7-9b86-9e6a1c2670e4`) | Combined CORS + security headers (no preflight) |204205Always emit a custom policy if the operator's requirements differ from206any managed policy — managed policies cannot be modified.207208### Step 6: Attach policy to distribution209210The policy attaches to a cache behavior. Use211`get-distribution-config --id <id>` to retrieve the current config,212modify the target behavior's `ResponseHeadersPolicyId`, and call213`update-distribution` with the retrieved `ETag`.214215```bash216ETAG=$(aws cloudfront get-distribution-config --id <id> \217 --query 'ETag' --output text)218aws cloudfront update-distribution --id <id> \219 --if-match "$ETAG" \220 --distribution-config file://updated-config.json221```222223### Step 7: Emit template (READY_TO_DEPLOY) or gap (PREREQUISITES_MISSING)224225If all pre-flight requirements pass, emit the complete response headers226policy template + the distribution update plan:227- `AWS::CloudFront::ResponseHeadersPolicy` (custom policy).228- OR the managed policy ID reference (for managed policy path).229- The `AWS::CloudFront::Distribution` update (set230 `ResponseHeadersPolicyId` on the target cache behavior).231- `AWS::CloudFront::CachePolicy` (if a new cache policy is also needed).232233If any requirement is missing, emit `PREREQUISITES_MISSING` with the234specific gap and the exact CLI / IaC snippet to close it.235236## Patterns — IaC templates237238Full CloudFormation and Terraform templates for both custom and managed239policy paths live in `references/response-headers-policy-templates.md`.240241→ The two non-negotiable config blocks (SecurityHeadersConfig + credentialed CorsConfig) — `references/response-headers-policy-templates.md`.242243## Diagnostic flows244245→ All four flows (headers not appearing, CSP breakage, CORS preflight failure, HSTS breaking subdomains) — `references/error-handling.md`.246247## Output format (per operation)248249→ Full per-operation label contract — `references/worked-examples.md` (the STRICT output contract below remains authoritative).250251### FORBIDDEN output patterns — NEVER2522531. NEVER emit `VERDICT: READY_TO_DEPLOY` while any CHECKLIST item is254 `[ ]` (unchecked). A single unchecked item forces255 `PREREQUISITES_MISSING`.2562572. NEVER emit a CORS config with `Access-Control-Allow-Origin: *`258 combined with `AllowCredentials: true`. Browsers reject this259 combination silently — CloudFront serves the headers, the browser260 console shows the CORS error, and no CloudFront metric fires.2612623. NEVER emit security headers with `Override: false`. Without263 `Override: true`, origin-emitted headers (often absent or weak) win264 over the policy. The CloudFront API accepts `Override: false`265 silently. Every security header in the policy MUST be `Override: true`.2662674. NEVER emit `HSTS: max-age=63072000; includeSubDomains; preload` on a268 non-production distribution. HSTS is irreversible for the `max-age`269 duration — once a browser sees it, all subdomains are HTTPS-only for270 2 years. Use `max-age=300` for testing; reserve the 2-year duration271 for verified production sites.2722735. NEVER emit a `RemoveHeaders` list that includes `Server` or `Via`.274 CloudFront injects these at the edge and silently ignores removal275 attempts. List only origin-emitted fingerprint headers276 (`X-Powered-By`, `X-AspNet-Version`).2772786. NEVER emit `X-Frame-Options: ALLOW-FROM`. `ALLOW-FROM` is deprecated279 and ignored by modern browsers. Use `DENY` or `SAMEORIGIN`, and use280 CSP `frame-ancestors` for fine-grained control.2812827. NEVER auto-execute `update-distribution` without the current ETag283 from `get-distribution-config`. Without `--if-match <etag>`, the284 update fails with `PreconditionFailed` and provides no warning285 during planning.286287### Worked example — READY_TO_DEPLOY (distribution with HSTS + X-Frame-Options + CSP)288289```text290DISTRIBUTION_ID: E27TVSIEXAMPLE1A291VERDICT: READY_TO_DEPLOY292CHECKLIST:293 [x] Target distribution: E27TVSIEXAMPLE1A exists in Deployed state (verified via get-distribution-config)294 [x] Target behavior: DefaultCacheBehavior (PathPattern: * — catch-all)295 [x] Response headers policy:296 - Security headers:297 Content-Security-Policy: "default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'"298 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload299 X-Frame-Options: DENY300 X-Content-Type-Options: nosniff301 Referrer-Policy: strict-origin-when-cross-origin302 Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()303 - CORS: not configured (same-origin app — no cross-origin requirements)304 - Custom headers: X-Content-Classification=Restricted, X-Service-Version=1.2.3305 - Removal headers: X-Powered-By, X-AspNet-Version (CloudFront Server/Via intentionally not listed — cannot be removed)306 [x] Policy origin: custom (managed SecurityHeadersPolicy does not include CSP frame-ancestors 'none' + Permissions-Policy simultaneously)307 [x] Override: true on every security header (CSP, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy)308 [x] Attach plan: get-distribution-config E27TVSIEXAMPLE1A → capture ETag → update-distribution with --if-match309GAP: None310IAC_TEMPLATE:311 # CloudFormation — AWS::CloudFront::ResponseHeadersPolicy (custom) +312 # AWS::CloudFront::Distribution update attaching policy ID to DefaultCacheBehavior313 SecurityHeadersConfig:314 ContentSecurityPolicy: { Content: "default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'", Override: true }315 StrictTransportSecurity: { AccessControlMaxAgeSec: 63072000, IncludeSubdomains: true, Preload: true, Override: true }316 FrameOptions: { FrameOption: DENY, Override: true }317 ContentTypeOptions: { Override: true }318 ReferrerPolicy: { ReferrerPolicy: "strict-origin-when-cross-origin", Override: true }319 PermissionsPolicy: { Content: "camera=(), microphone=(), geolocation=(), payment=()", Override: true }320 CustomHeadersConfig:321 Items:322 - { Header: { Value: Restricted }, Name: X-Content-Classification, Override: true }323 - { Header: { Value: 1.2.3 }, Name: X-Service-Version, Override: true }324 RemoveHeadersConfig:325 Items: [X-Powered-By, X-AspNet-Version]326 # Full CloudFormation / Terraform template in references/response-headers-policy-templates.md327MANUAL_GAPS: (none)328NOTES:329 - Distribution update requires ETag match — call get-distribution-config E27TVSIEXAMPLE1A first.330 - CloudFront invalidation recommended after attach: aws cloudfront create-invalidation --distribution-id E27TVSIEXAMPLE1A --paths "/*"331 - Test CSP in Report-Only mode first if site has unknown inline scripts.332 - HSTS max-age=63072000 with includeSubDomains is irreversible for 2 years — confirm all subdomains serve HTTPS before deploy.333```334335### Worked example — PREREQUISITES_MISSING (wildcard CORS + credentials)336→ Full example block — `references/worked-examples.md`.337338### Decision tree — managed policy vs custom policy339340```341Start: response headers requirement342├─ CORS required?343│ ├─ Yes → Preflight (OPTIONS) needed?344│ │ ├─ Yes → CORS-with-preflight-and-SecurityHeadersPolicy (managed ID 5cc3b908-e619-4b99-88e5-2ca770afe08f)345│ │ │ if security headers also needed; else custom (no managed346│ │ │ preflight-only policy)347│ │ └─ No → CORSAndHTTPSecurityHeadersPolicy (managed ID e0bbb029-0798-45b7-9b86-9e6a1c2670e4)348│ │ OR SimpleCORS (managed ID 608323ce734e4449839d234493be9c7c) if no security headers349│ └─ No → Security headers only?350│ ├─ Default OWASP baseline sufficient?351│ │ ├─ Yes → SecurityHeadersPolicy (managed ID 0857826db9cffff310d5ad62955c9c26)352│ │ └─ No → Custom (CSP / Permissions-Policy / HSTS tweak required)353│ └─ Custom or removal headers needed?354│ └─ Yes → Custom policy (managed policies cannot be modified)355└─ Wildcard origin "*" with credentials true? → ALWAYS PREREQUISITES_MISSING356```357358## STRICT output contract359360The rules below are hard constraints. Violating any one produces a361response headers policy that fails silently (no headers in browser,362CSP breaks site, CORS rejected) or a gap report that leaves the363operator stuck. Self-check EVERY emitted block against these rules.364365### Required output structure366367Every response MUST be a single block using these literal labels, in368this order. Do NOT substitute markdown headings or camelCase variants.369370```text371OPERATION: <create | update | attach | audit>372VERDICT: READY_TO_DEPLOY | PREREQUISITES_MISSING373TARGET: <policy-name>374REQUIREMENTS:375 - [PASS] <requirement description>376 - [FAIL] <requirement description> — <gap>377IAC_TEMPLATE: <inline CloudFormation / Terraform, or "(held in draft)">378MANUAL_GAPS:379 - GAP: <gap description>380 REMEDIATION: <exact CLI or IaC snippet to close the gap>381 REASON: <why this cannot be automated>382NOTES: <managed policy version, attach-vs-embed, distribution deploy state>383```384385### FORBIDDEN output patterns3863871. **NEVER emit `VERDICT: READY_TO_DEPLOY` when any requirement is388 `[FAIL]`.** A single `[FAIL]` MUST produce389 `VERDICT: PREREQUISITES_MISSING`.3903912. **NEVER emit a `[FAIL]` requirement without a corresponding392 `MANUAL_GAPS` entry.** Every `[FAIL]` line MUST have a matching393 GAP/REMEDIATION/REASON block.3943953. **NEVER emit a CORS config with `Access-Control-Allow-Origin: *`396 AND `Access-ControlAllowCredentials: true`.** Browsers reject this397 combination — CloudFront will serve it but the browser console398 shows a CORS error. Use specific origins or disable credentials.3994004. **NEVER emit a response headers policy with `Override: false` on401 security headers.** Without `Override: true`, origin-emitted headers402 (often weak or absent) win over the policy values. Every security403 header MUST have `Override: true`.4044055. **NEVER emit an HSTS config with `max-age=63072000` on a406 non-production distribution.** HSTS is irreversible for the407 `max-age` duration. Use `max-age=300` for testing; reserve the408 2-year duration for verified production sites.4094106. **NEVER emit a `RemoveHeaders` list including `Server` or `Via`.**411 CloudFront injects these at the edge and silently ignores removal412 attempts. List only origin-emitted fingerprint headers.4134147. **NEVER emit `IAC_TEMPLATE: (held in draft)` without listing which415 specific `[FAIL]` items blocked it.**416417**Self-check before emit:**418- [ ] Any `[FAIL]` in REQUIREMENTS → VERDICT is PREREQUISITES_MISSING?419- [ ] Every `[FAIL]` has a matching GAP/REMEDIATION/REASON block?420- [ ] CORS: `*` origin NOT combined with credentials?421- [ ] Security headers all have `Override: true`?422- [ ] HSTS `max-age` appropriate for environment (300 test, 63072000 prod)?423- [ ] `RemoveHeaders` excludes `Server` and `Via`?424425## Expert heuristic — top 5 non-obvious failure modes426→ All five failure modes (Override:false, CSP vs inline handlers, HSTS includeSubDomains, uncached preflight, cached-error bypass) — `references/advanced-patterns.md`.427428## Anti-Patterns — NEVER do these things429430- **NEVER emit a CORS policy with `Access-Control-Allow-Origin: *`431 AND `Access-Control-Allow-Credentials: true`.** Browsers reject this432 combination. Use specific origins or disable credentials.433434- **NEVER emit security headers with `Override: false`.** Without435 override, origin values (often absent or weak) win over the policy.436 Every security header MUST have `Override: true`.437438- **NEVER emit `X-Frame-Options: ALLOW-FROM`.** `ALLOW-FROM` is439 deprecated and ignored by modern browsers. Use `DENY` or440 `SAMEORIGIN`, and use CSP `frame-ancestors` for fine-grained control.441442- **NEVER emit an HSTS `max-age=63072000` on a non-production site.**443 HSTS is irreversible for the duration. Use `max-age=300` for testing.444445- **NEVER emit a `RemoveHeaders` list including `Server` or `Via`.**446 CloudFront injects these at the edge and silently ignores removal.447448- **NEVER emit a CSP without testing in Report-Only mode first.** CSP449 `default-src 'none'` will block all resources on a site with inline450 scripts, external CDNs, or images from other domains. Test with451 `Content-Security-Policy-Report-Only` first.452453- **NEVER emit a managed policy reference assuming it covers CORS454 preflight.** `SecurityHeadersPolicy` and `SimpleCORS` do NOT handle455 preflight. Use `CORS-with-preflight-and-SecurityHeadersPolicy` if456 preflight is needed.457458- **NEVER auto-execute `update-distribution` without the ETag match.**459 `UpdateDistribution` requires the current ETag from460 `get-distribution-config`. Without it, the update fails with461 `PreconditionFailed`. Always snapshot via `get` first.462463- **NEVER emit a response headers policy attached to a distribution in464 `InProgress` state.** The update fails with `InvalidIfMatchVersion`.465 Wait for `Deployed` state before attaching.466467- **NEVER emit a custom header that overrides `Cache-Control` without468 verifying the cache policy.** If the cache policy honors469 `Cache-Control` from the origin, and the response headers policy470 overrides it, the cache behavior changes silently.471472- **NEVER emit `Referrer-Policy: no-referrer` for a public marketing473 site.** `no-referrer` breaks analytics (Google Analytics uses the474 referrer for source attribution). Use `strict-origin-when-cross-origin`.475476- **NEVER assume the response headers policy applies to cached errors.**477 Cached 4xx/5xx responses bypass the policy. Configure custom error478 responses for security headers on error pages.479480## Pre-flight safety checks (run before any remediation CLI)481482→ Full checklist (confirmation gate, Deployed-state verify, snapshots, ETag capture, CSP inventory, HSTS subdomain check) — `references/diagnostic-commands.md`.483484## Recent AWS features (2024-2026)485486→ All six updates (managed policy updates, CORS-with-preflight, OAC, Permissions-Policy GA, CloudFormation, KeyValueStore) — `references/advanced-patterns.md`.487488## References (load on demand)489490- [`references/worked-examples.md`](references/worked-examples.md) — secondary worked example (PREREQUISITES_MISSING wildcard CORS) + per-operation output format spec491- [`references/error-handling.md`](references/error-handling.md) — diagnostic flows: headers not appearing, CSP breakage, CORS preflight failure, HSTS breaking subdomains492- [`references/diagnostic-commands.md`](references/diagnostic-commands.md) — live-account pre-flight commands; pre-remediation safety checks493- [`references/advanced-patterns.md`](references/advanced-patterns.md) — Step 0 non-obvious behaviors, expert-heuristic failure modes, mindset realities, recent AWS features (2024-2026)494- [`references/response-headers-policy-templates.md`](references/response-headers-policy-templates.md) — full IaC templates (pre-existing) + non-negotiable config blocks495- [`references/security-headers-and-managed-policies.md`](references/security-headers-and-managed-policies.md) — header semantics + managed policy matrix (pre-existing)496497## Domain498499AWS CloudOps / CloudFront Networking — Response Headers Policy,500Security Headers, CORS Configuration, Managed Policy Selection,501Distribution Hardening.502503## AWS documentation504505- **CloudFront response headers policy** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/creating-response-headers-policies.html506- **Managed response headers policies** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/managed-response-headers-policies.html507- **Security headers reference** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/understanding-response-headers-policies.html#understanding-response-headers-policies-security508- **CORS reference** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/understanding-response-headers-policies.html#understanding-response-headers-policies-cors509- **Custom headers reference** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-response-headers-policies.html510- **CloudFront response headers API** — https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_ResponseHeadersPolicy.html511- **AWS CLI cloudfront response-headers-policy** — https://docs.aws.amazon.com/cli/latest/reference/cloudfront/create-response-headers-policy.html512- **OWASP Secure Headers Project** — https://owasp.org/www-project-secure-headers/513- **MDN Content-Security-Policy** — https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP