Skip to content

Menu

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

Try it: CSP BuilderFrom the docs, not run by us
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.

Try it: CSP BuilderFrom the docs, not run by us
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

Try it: csp-validatorFrom the docs, not run by us
script-src 'sha256-<base64 hash>'

Allow one exact inline script by its hash; whitespace and case inside the script change the hash

From the docs, not run by us
object-src 'none'; base-uri 'self'

Block plugins and stop injected <base> tags from rewriting your relative script URLs

From the docs, not run by us
frame-ancestors 'none'

Refuse to be embedded in any frame, the CSP replacement for X-Frame-Options DENY

From the docs, not run by us
upgrade-insecure-requests

Treat the page's http:// subresource URLs as https:// before fetching them

From the docs, not run by us
report-to csp-endpoint; report-uri /csp-reports

Send violation reports; browsers that know report-to ignore the deprecated report-uri

Define the endpoint name with the Reporting-Endpoints header.

From the docs, not run by us

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 csp

Log what the policy would block without blocking anything

Try it: CSP BuilderFrom the docs, not run by us
Send both CSP and CSP-Report-Only

Enforce the current policy while you trial a stricter one alongside it

From the docs, not run by us
sandbox in a report-only policy

Has no effect: the sandbox directive is ignored in report-only mode

From the docs, not run by us

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; includeSubDomains

First step of a ramp-up: five minutes, so a mistake expires quickly

Try it: http-header-generatorFrom the docs, not run by us
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Minimum value hstspreload.org accepts: one year, all subdomains, preload token

From the docs, not run by us
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

OWASP's suggested value (two years) once you are sure every subdomain serves HTTPS

From the docs, not run by us
Strict-Transport-Security: max-age=0

Tell browsers to forget HSTS; only works when sent over HTTPS

From the docs, not run by us
curl -sI https://github.com | grep -i strict

Check 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: nosniff

Block scripts and stylesheets whose Content-Type is wrong instead of guessing their type

Try it: Security Headers AnalyzerFrom the docs, not run by us
X-Frame-Options: DENY

Legacy framing block; ignored inside a <meta> tag and superseded by frame-ancestors

From the docs, not run by us
X-Frame-Options: SAMEORIGIN

Allow framing only when every ancestor frame is on the same origin

From the docs, not run by us
Referrer-Policy: strict-origin-when-cross-origin

Send the full URL same-origin, only the origin cross-origin, and nothing on HTTPS to HTTP

Try it: HTTP Header ParserFrom the docs, not run by us
Referrer-Policy: no-referrer, strict-origin-when-cross-origin

Fallback list: the browser applies the last value it understands

From the docs, not run by us
Remove Server and X-Powered-By

Stop advertising your server software and framework version, as OWASP recommends

From the docs, not run by us

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

From the docs, not run by us
Permissions-Policy: geolocation=(self "https://maps.example.com")

Allow a feature for your origin and one named origin; origins go in double quotes

From the docs, not run by us
Cross-Origin-Opener-Policy: same-origin

Put the page in its own browsing context group so cross-origin popups lose window.opener

From the docs, not run by us
Cross-Origin-Embedder-Policy: require-corp

Only load cross-origin no-cors resources that opt in with CORP or CORS

From the docs, not run by us
Cross-Origin-Embedder-Policy: credentialless

Load cross-origin no-cors resources without cookies instead of requiring CORP

From the docs, not run by us
Cross-Origin-Resource-Policy: same-site

Stop other sites from embedding this resource through no-cors requests

From the docs, not run by us
X-XSS-Protection: 0

Turn the old XSS auditor off; MDN warns it can create XSS holes and points you to CSP

From the docs, not run by us
Expect-CT

Deprecated; OWASP says not to send it

From the docs, not run by us
Public-Key-Pins

Removed from Chromium in 2018; a bad pin could lock users out of your site

From the docs, not run by us
Feature-Policy

Old name of Permissions-Policy, with a different syntax; migrate the directives

From the docs, not run by us
X-Frame-Options: ALLOW-FROM https://a.example

Obsolete; modern browsers ignore the whole header, use frame-ancestors instead

From the docs, not run by us

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 away

    Pair 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 framing

    frame-ancestors is not a fetch directive and has no fallback; set frame-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-age up from 300 seconds, confirm internal hosts serve HTTPS, and only then add preload.

  • 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.