Security Headers Checklist: Harden a Real App
On this page
Learning Objective
Combine every control this course covered into one coherent header set for a realistic application, in a defensible order, with a rollout plan that does not break production and a verification step for each decision.
Concept Explanation
This is a synthesis lesson rather than new material. The goal is a repeatable sequence of questions to run against any application, drawing one decision from each earlier lesson, because that sequence is the transferable skill this course has been building toward rather than the memory of any individual header.
Start with the origin inventory, from the first phase. What origins does this application actually consist of, which of them are same-site but different-origin, and which subdomains exist that the team does not control? That inventory determines every later decision: whether cookies can be host-only, whether a site-level control such as SameSite is sufficient, and whether a same-site attacker is in the threat model. Then transport, from the fourth lesson of the final phase: HSTS staged from a short max-age upward, includeSubDomains only after auditing every subdomain, and preload only when that audit is complete.
Next, cookies, from the fourth phase. Every session and CSRF cookie gets the __Host- prefix, Secure, HttpOnly where script does not need it, Path=/, and an explicit SameSite value rather than the default. Then CSRF, from the same phase: a signed double-submit token bound to the session, plus an Origin or Sec-Fetch-Site check, on the grounds that SameSite alone leaves a same-site attacker, SameSite=None cookies, and any state-changing GET endpoint uncovered. Then framing: frame-ancestors stated explicitly, defaulting to none, with X-Frame-Options alongside only for legacy clients.
Then CORS, from the second phase, but only if the application genuinely has a cross-origin front end. An exact-match allowlist, credentials enabled per route rather than globally, Vary: Origin whenever the value is computed, and a regression test asserting a fabricated origin is rejected. Then CSP, from the third phase, deployed as a ratchet: report-only first, a nonce with strict-dynamic rather than a host allowlist, object-src and base-uri always stated, connect-src limited to real destinations, and Trusted Types once the sink inventory is known.
Finally, isolation and third parties, from this phase. CORP: same-origin as the default on every API endpoint. COOP and COEP together, in report-only first, only if the application actually needs SharedArrayBuffer or high-resolution timers, since the deployment cost is real and the benefit is specific. SRI on every static third-party script with a pinned version. A strict Permissions-Policy. Referrer-Policy at strict-origin-when-cross-origin site-wide and no-referrer on pages whose URLs carry tokens. And throughout, the habit that makes all of it durable: deploy in report-only, watch the reports, and promote only when they are quiet.
| Decision point | Question to ask | This course's lesson |
|---|---|---|
| Origin inventory | Which origins exist, and which subdomains do we not control? | Lessons 1 and 3 |
| Transport | Is HSTS staged, and is every subdomain HTTPS-ready before preload? | Lesson 24 |
| Cookies | Is every session cookie __Host-, Secure, HttpOnly, with explicit SameSite? | Lessons 18 and 19 |
| CSRF | Is there a signed token plus an Origin or Sec-Fetch-Site check? | Lesson 20 |
| Framing | Is frame-ancestors stated explicitly on every page? | Lesson 21 |
| CORS | Exact allowlist, credentials per route, Vary: Origin, and a negative test? | Lessons 9 to 11 |
| CSP | Nonce plus strict-dynamic, object-src and base-uri set, connect-src narrow? | Lessons 13, 14, and 16 |
| DOM sinks | Is Trusted Types enforced, or at least measured in report-only? | Lesson 17 |
| Isolation | CORP on APIs, and COOP plus COEP only if a powerful API needs them? | Lessons 22 and 23 |
| Third parties | SRI on static vendor scripts, connect-src limiting exfiltration? | Lesson 25 |
Worked Example: The Complete Header Set for a Banking Dashboard
The configuration below is what the whole course produces for one realistic application: a customer dashboard at app.bank.example, an API at api.bank.example, one embedded payment iframe from a vendor, and no requirement for SharedArrayBuffer. Each block traces back to a specific lesson.
# ---------- app.bank.example : the HTML document ----------
# Transport (L24): a year, subdomains audited, preload submitted
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
# Content policy (L13, L14, L16, L17): nonce-based, no host allowlist
Content-Security-Policy:
default-src 'self';
script-src 'nonce-{PER_RESPONSE}' 'strict-dynamic' https: 'unsafe-inline';
style-src 'self' 'nonce-{PER_RESPONSE}';
img-src 'self' data: https://cdn.bank.example;
connect-src 'self' https://api.bank.example;
frame-src https://payments.vendor.example;
object-src 'none';
base-uri 'none';
form-action 'self';
frame-ancestors 'none';
require-trusted-types-for 'script';
trusted-types app-html default;
upgrade-insecure-requests;
report-to csp
Reporting-Endpoints: csp="https://app.bank.example/reports/csp"
# Framing (L21): frame-ancestors is authoritative; XFO for legacy only
X-Frame-Options: DENY
# Isolation and sniffing (L4, L22, L23)
X-Content-Type-Options: nosniff
Cross-Origin-Opener-Policy: same-origin-allow-popups
Cross-Origin-Resource-Policy: same-origin
# Leakage and capabilities (L24)
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=(), usb=(), payment=(self)
# Cookies (L18, L19)
Set-Cookie: __Host-session=...; Secure; HttpOnly; Path=/; SameSite=Lax
Set-Cookie: __Host-csrf=...; Secure; Path=/; SameSite=Strict
# ---------- api.bank.example : the JSON API ----------
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
Cross-Origin-Resource-Policy: same-origin # L23: closes load oracles
Content-Security-Policy: default-src 'none'; frame-ancestors 'none'
Cache-Control: no-store
# CORS (L9, L10, L11): exact allowlist, credentials, Vary
Access-Control-Allow-Origin: https://app.bank.example
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Headers: Content-Type, X-CSRF-Token
Access-Control-Expose-Headers: X-Request-Id
Access-Control-Max-Age: 7200
Vary: Origin
# ---------- Verification checklist ----------
# curl -H 'Origin: https://evil.example' ... -> no ACAO in the response
# self.crossOriginIsolated -> false, and that is fine here
# CSP report stream quiet for 7 days before promoting the next tightening
# Every third-party <script> carries integrity= and a pinned version
# A state change on GET anywhere -> treat as a defectReal-World Examples
- Mozilla operates the Observatory scanner, which grades a site against essentially this checklist, awarding points for CSP, HSTS, X-Content-Type-Options, X-Frame-Options or frame-ancestors, Referrer-Policy, SRI, and cookie attributes, and deducting for unsafe-inline and permissive CORS; running a site through it is the fastest way to convert this lesson's checklist into a concrete list of findings.
- Google publishes the CSP Evaluator at csp-evaluator.withgoogle.com, which analyzes a policy for the specific weaknesses this course covered, missing object-src and base-uri, host allowlists containing known JSONP endpoints, and the presence of unsafe-inline or unsafe-eval, and it is built on the same research that found the overwhelming majority of deployed policies bypassable.
Review Questions & Answers
Because they face different threats. The document is a rendering context that executes script, embeds resources, and can be framed, so it needs the full CSP, frame-ancestors, Referrer-Policy, and Permissions-Policy. The API returns data and renders nothing, so it gets default-src none, CORP: same-origin to close load-success oracles, no-store caching, and a precise CORS policy. Applying the document's policy to the API would be noise, and applying the API's to the document would break it.
Because the application does not need SharedArrayBuffer or high-resolution timers, so cross-origin isolation buys it nothing, while COEP: require-corp would require every third-party subresource to add a CORP header. The allow-popups variant still severs the relationship with whatever opened the page, which is the part that matters for a banking dashboard, while preserving the ability to run a payment or identity popup. Deploying full isolation without a capability that needs it is cost with no benefit.
The session cookie is Lax so that a user arriving from an email link or a search result is still logged in, which Strict would break. The CSRF cookie is Strict because nothing legitimate ever needs it on a cross-site request, so the stricter value costs nothing. Together they give usable session continuity while ensuring that the token required for any state change is withheld on exactly the cross-site requests an attacker would use, which is the pattern from the SameSite and CSRF lessons combined.
The curl probe with a fabricated Origin header, run as an automated test. CORS configuration is the control most likely to be loosened later by someone debugging a cross-origin problem, the loosening produces no visible symptom, and the consequence is that any site a logged-in user visits can read their authenticated data. A single assertion that a fabricated origin receives no Access-Control-Allow-Origin header catches unconditional reflection, null acceptance, and suffix matching all at once, which is why its absence explains nearly every CORS disclosure on record.