Security Headers Cheat Sheet: CSP, HSTS, Frame and Cross-Origin Policies
Checked against HTTP security headers W3C CSP Level 3 Working Draft of 27 Oct 2026; MDN header pages and OWASP HTTP Headers Cheat Sheet on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers who ship web apps and want the response headers that actually change browser behaviour, with values you can paste. It follows the CSP Level 3 Working Draft dated 27 October 2026, the MDN header reference and the OWASP HTTP Headers Cheat Sheet as read on 28 November 2026. Header values are taken from those pages; only the live checks against github.com and httpbin.org were run here.
When to use what
Start with the cheap, safe ones: X-Content-Type-Options: nosniff, a Referrer-Policy of strict-origin-when-cross-origin, and HSTS with a short max-age that you raise once nothing breaks. None of those need changes to your front-end code.
CSP is where the real XSS protection lives and also where most of the pain is. Allowlists of hosts age badly, because every new analytics or CDN domain means a header change, and a single permissive host can undo the policy. A nonce-based policy with 'strict-dynamic' is easier to keep correct: your server stamps a fresh nonce on the scripts it trusts and those scripts may load others. Ship it as Content-Security-Policy-Report-Only first, read the reports for a week, then switch the header name. The CSP builder drafts a policy and the CSP validator flags weak sources such as 'unsafe-inline' without a nonce.
For framing, use frame-ancestors in CSP and keep X-Frame-Options only as a fallback for old browsers. Add COOP and COEP only when you need cross-origin isolation, for example for SharedArrayBuffer; on an ordinary site, COEP require-corp mostly breaks third-party images. Preloading HSTS is a one-way door, so read the preload section before adding the token. When you are done, paste your headers into the security headers analyzer, and see the security headers guide for server config snippets.
default-src is the fallback for fetch directives only. frame-ancestors, form-action and base-uri are not covered by it, so set them yourself. Script source keywords are on https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/script-src.
Content-Security-Policy: default-src 'self'Allow resources only from the page's own origin for every fetch directive you don't set explicitly
script-src 'nonce-R4nd0m' 'strict-dynamic'Run only scripts carrying this response's nonce, plus anything those scripts load themselves
Generate a new nonce for every response. With 'strict-dynamic', host allowlists and 'self' are ignored by supporting browsers.
script-src 'nonce-R4nd0m' 'strict-dynamic' https: 'unsafe-inline'Backward-compatible form: new browsers ignore https: and 'unsafe-inline', old ones fall back to them
script-src 'sha256-<base64 hash>'Allow one exact inline script by its hash; whitespace and case inside the script change the hash
object-src 'none'; base-uri 'self'Block plugins and stop injected <base> tags from rewriting your relative script URLs
frame-ancestors 'none'Refuse to be embedded in any frame, the CSP replacement for X-Frame-Options DENY
upgrade-insecure-requestsTreat the page's http:// subresource URLs as https:// before fetching them
report-to csp-endpoint; report-uri /csp-reportsSend violation reports; browsers that know report-to ignore the deprecated report-uri
Define the endpoint name with the Reporting-Endpoints header.
A report-only policy needs a reporting directive, otherwise it does nothing at all. It cannot be set with a <meta> tag.
Content-Security-Policy-Report-Only: default-src 'self'; report-to cspLog what the policy would block without blocking anything
Send both CSP and CSP-Report-OnlyEnforce the current policy while you trial a stricter one alongside it
sandbox in a report-only policyHas no effect: the sandbox directive is ignored in report-only mode
Preload requirements are on https://hstspreload.org/, which itself says preloading is not recommended by default because removal is slow.
Strict-Transport-Security: max-age=300; includeSubDomainsFirst step of a ramp-up: five minutes, so a mistake expires quickly
Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadMinimum value hstspreload.org accepts: one year, all subdomains, preload token
Strict-Transport-Security: max-age=63072000; includeSubDomains; preloadOWASP's suggested value (two years) once you are sure every subdomain serves HTTPS
Strict-Transport-Security: max-age=0Tell browsers to forget HSTS; only works when sent over HTTPS
curl -sI https://github.com | grep -i strictCheck what a live site sends; github.com returned max-age=31536000; includeSubdomains; preload on 28 Nov 2026
MDN pages: X-Content-Type-Options, X-Frame-Options and Referrer-Policy under https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/.
X-Content-Type-Options: nosniffBlock scripts and stylesheets whose Content-Type is wrong instead of guessing their type
X-Frame-Options: DENYLegacy framing block; ignored inside a <meta> tag and superseded by frame-ancestors
X-Frame-Options: SAMEORIGINAllow framing only when every ancestor frame is on the same origin
Referrer-Policy: strict-origin-when-cross-originSend the full URL same-origin, only the origin cross-origin, and nothing on HTTPS to HTTP
Referrer-Policy: no-referrer, strict-origin-when-cross-originFallback list: the browser applies the last value it understands
Remove Server and X-Powered-ByStop advertising your server software and framework version, as OWASP recommends
Also https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Permissions-Policy and the COOP and CORP pages. Cross-origin isolation needs COOP same-origin and COEP require-corp or credentialless together.
Permissions-Policy: geolocation=(), camera=(), microphone=()Turn off these browser features for the page and every iframe it embeds
Permissions-Policy: geolocation=(self "https://maps.example.com")Allow a feature for your origin and one named origin; origins go in double quotes
Cross-Origin-Opener-Policy: same-originPut the page in its own browsing context group so cross-origin popups lose window.opener
Cross-Origin-Embedder-Policy: require-corpOnly load cross-origin no-cors resources that opt in with CORP or CORS
Cross-Origin-Embedder-Policy: credentiallessLoad cross-origin no-cors resources without cookies instead of requiring CORP
Cross-Origin-Resource-Policy: same-siteStop other sites from embedding this resource through no-cors requests
X-XSS-Protection: 0Turn the old XSS auditor off; MDN warns it can create XSS holes and points you to CSP
Expect-CTDeprecated; OWASP says not to send it
Public-Key-PinsRemoved from Chromium in 2018; a bad pin could lock users out of your site
Feature-PolicyOld name of Permissions-Policy, with a different syntax; migrate the directives
X-Frame-Options: ALLOW-FROM https://a.exampleObsolete; modern browsers ignore the whole header, use frame-ancestors instead
Worked example: Roll out a nonce-based CSP without breaking production
Step one: send the policy in report-only mode, with a new nonce generated per response and placed on every <script> tag you render.
Reporting-Endpoints: csp="https://example.com/csp-reports"
Content-Security-Policy-Report-Only: script-src 'nonce-8IBTHwOdqNKAWeKl7plt8g==' 'strict-dynamic'; object-src 'none'; base-uri 'self'; report-to csp
Step two: check what you actually serve.
curl -sI https://example.com | grep -i content-security
For a week, read the reports. Each one names the blocked resource and the directive that would have blocked it. Inline onclick handlers and javascript: links show up here because nonces don't cover them; move them into script files instead of adding 'unsafe-inline'. Scripts injected by a nonced loader (a tag manager, for example) are fine because 'strict-dynamic' passes trust on to them. When the reports go quiet, rename the header to Content-Security-Policy. If you see the same nonce in two responses, your HTML is being cached with it, and the policy protects nothing: make those pages uncacheable or move to hashes.
Common mistakes
Reusing one hard-coded nonce for every response
Generate a fresh random nonce per response; a fixed nonce is just a password printed in your HTML that an attacker can copy.
Adding
'unsafe-inline'to make a CSP warning go awayPair it with a nonce or hash, which makes modern browsers ignore it, or move the inline code into a file.
Expecting
default-src 'none'to stop framingframe-ancestorsis not a fetch directive and has no fallback; setframe-ancestors 'self'or'none'explicitly.Putting X-Frame-Options or a report-only CSP in a meta tag
Both are ignored there; send them as real HTTP response headers from the server or CDN.
Submitting to the HSTS preload list before checking every subdomain
Ramp
max-ageup from 300 seconds, confirm internal hosts serve HTTPS, and only then addpreload.Sending HSTS on the plain HTTP response
Browsers ignore it there; redirect HTTP to HTTPS with a 301 and send the header on the HTTPS response.
Related cheat sheets
Sources
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy
- https://www.w3.org/TR/CSP3/
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security
- https://hstspreload.org/
- https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cross-Origin-Opener-Policy
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.