No. 105Security6 min read1,553 words
Security headers checklist: safe values to start with
A free security headers checklist: CSP, HSTS and preload, frame-ancestors, nosniff, Referrer-Policy, Permissions-Policy, COOP/COEP/CORP and cookie flags.
- Written by
- Lazy Devs
- Published
- Updated
- Sources
- Cited inline

Key takeaways · 05
The short version
- 01Every site should send HSTS, X-Content-Type-Options: nosniff, a frame-ancestors rule, a Referrer-Policy and a Permissions-Policy. They are cheap, low-risk and stop whole classes of attacks.
- 02Content Security Policy gives the most protection and breaks the most things. Roll it out in Report-Only mode first, use nonces or hashes instead of 'unsafe-inline', and only then enforce it.
- 03HSTS preloading is hard to undo. hstspreload.org requires a max-age of at least 31536000 seconds, includeSubDomains and preload, and it applies to every subdomain, including internal ones.
- 04Check where your headers are actually set. Some hosts serve static assets outside your application, so headers set in framework config never reach them.
- 05Cookies need their own flags: Secure, HttpOnly for sessions, SameSite, and the __Host- prefix for session cookies.
On this page · 13
Security headers are the cheapest security work on a website: a few lines of configuration that tell the browser to refuse whole classes of attacks, from protocol downgrades to clickjacking to injected scripts. They are also easy to get subtly wrong, by setting them where they never reach half your responses, or by enabling a policy that breaks the page in production.
This checklist covers each header we set on client projects: what it does, a safe value to start with, and the gotchas. The starting values are our defaults, not universal answers, and every one should be tested on staging first. Each claim links to MDN, hstspreload.org or the framework's own documentation.
Download the security headers checklist (Markdown)
First: find where headers are set
Before choosing values, find out where headers come from on your stack. They can be set in framework config, middleware, a CDN or edge rule, the web server, or a static-asset rule, and different response types often take different paths.
We learned this on our own site. It runs on Cloudflare Workers, where static files are served directly by Workers Static Assets and bypass the Next.js handler, so headers set in next.config.ts never reach them. We send HSTS from next.config.ts for pages and repeat it in public/_headers so every response carries it.
When you test, check five responses, not one: an HTML page, an API response, a static asset, a redirect and a 404.
Strict-Transport-Security (HSTS)
What it does: tells the browser to only ever connect to your host over HTTPS, for the number of seconds in max-age (MDN).
Start with: Strict-Transport-Security: max-age=63072000
Gotchas:
- Send it over HTTPS only. MDN notes that browsers ignore the header when it is sent over HTTP, so an attacker in the middle cannot alter it.
- Add
includeSubDomainsonly when every subdomain serves HTTPS. - Preloading is a commitment. To be accepted on the preload list, hstspreload.org requires a valid certificate, a redirect from HTTP to HTTPS on the same host, HTTPS on all subdomains (including
wwwif it has a DNS record), and an HSTS header on the base domain with amax-ageof at least 31536000 seconds (one year),includeSubDomainsandpreload. If you serve a redirect from your HTTPS site, that redirect must carry the header too. The site also warns that preloading applies to all subdomains, "including internal subdomains that are not publicly accessible".
Content-Security-Policy (CSP)
What it does: restricts where scripts, styles, frames and other resources may load from, and blocks inline scripts unless you allow them. It is the main browser-side defence against cross-site scripting. MDN is clear that it is defence in depth, "not an alternative to sanitizing input" (MDN CSP guide).
Start with (in Report-Only mode):
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-{RANDOM}' 'strict-dynamic'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; report-to csp
Reporting-Endpoints: csp="https://example.com/csp-reports"Gotchas:
- Roll out in Report-Only first.
Content-Security-Policy-Report-Onlyreports violations without blocking anything. Run it until the reports are clean, then switch to the enforcing header. - Avoid
'unsafe-inline'. MDN warns that it "defeats much of the purpose of having a CSP". Use nonces or hashes instead. 'strict-dynamic'helps with third-party scripts that load further scripts, which otherwise fail a nonce or hash policy.- Reporting: the recommended method is the
report-todirective with endpoints declared inReporting-Endpoints.report-uriis deprecated, but MDN advises declaring both untilreport-tois supported everywhere. - Next.js and nonces: the Next.js CSP guide says nonces require dynamic rendering, which disables static optimisation and incremental static regeneration and means pages "cannot be cached by CDNs without additional configuration". For mostly static sites it documents two alternatives: a CSP without nonces in
next.config, or experimental Subresource Integrity, which adds build-time hashes so pages stay static. - Every allowed domain needs an owner. Analytics and marketing tags tend to pull in long lists of domains. Each one you allow is a place scripts can come from.
frame-ancestors and X-Frame-Options
What they do: control who may embed your page in a frame, which prevents clickjacking.
Start with: frame-ancestors 'none' inside your CSP (or 'self' if you frame your own pages), plus X-Frame-Options: DENY (or SAMEORIGIN) for older browsers.
Gotchas:
- MDN notes that
frame-ancestors 'none'"is similar to X-Frame-Options: deny", and that the directive is not supported in a<meta>element, so send it as a header. X-Frame-Options: ALLOW-FROMis obsolete: "Modern browsers that encounter response headers with this directive will ignore the header completely."
X-Content-Type-Options
What it does: turns off MIME-type sniffing.
Start with: X-Content-Type-Options: nosniff
Gotcha: for scripts and stylesheets, the browser blocks the response if its MIME type doesn't match what it expects. Make sure every response sends a correct Content-Type, or files that used to work will stop loading.
Referrer-Policy
What it does: controls how much of the current URL is sent in the Referer header when people follow links or the page loads resources.
Start with: Referrer-Policy: strict-origin-when-cross-origin, or a stricter value such as same-origin if you don't need cross-origin referrers.
Gotcha: MDN notes that strict-origin-when-cross-origin is already the default when no policy is specified. Setting it explicitly still documents intent and protects you from a page or tag setting something looser, such as unsafe-url, which leaks full URLs including query strings.
Permissions-Policy
What it does: turns browser features such as the camera, microphone and geolocation on or off for your page and anything it embeds.
Start with: disable what you don't use, for example Permissions-Policy: camera=(), microphone=(), geolocation=().
Gotcha: an empty list () disables the feature "for all browsing contexts (this includes all <iframe>s), regardless of their origin" (MDN). If an embedded map or video call needs a feature, allow that origin explicitly.
COOP, COEP and CORP (only when you need them)
These three headers control how your page shares a browsing context and resources with other origins. Most marketing sites don't need all three; apps that need cross-origin isolation (for example for SharedArrayBuffer) do.
- Cross-Origin-Opener-Policy:
same-originisolates your page from cross-origin windows. If you rely on popups, such as OAuth sign-in windows,same-origin-allow-popupsis the usual compromise. - Cross-Origin-Embedder-Policy:
require-corponly allows cross-origin resources that explicitly permit embedding;credentiallessloads them without cookies instead. Audit every embedded resource first, or images and embeds will fail. - Cross-Origin-Resource-Policy: set
same-originorsame-siteon resources that other sites should not embed.
Cookie flags
Cookies are configured on the Set-Cookie header, and the flags matter as much as any header (MDN):
Secureon every cookie, so it is only sent over HTTPS.HttpOnlyon session and authentication cookies: it "forbids JavaScript from accessing the cookie", which limits the damage of cross-site scripting.SameSite=Lax(orStrict) to limit cross-site sending.SameSite=NonerequiresSecure, and should only be used when a cookie genuinely has to travel cross-site.__Host-prefix for session cookies. Such cookies must be set withSecure, must not have aDomainattribute and must havePath=/, which keeps them on the exact host that set them.
If your cookies are non-essential (analytics or advertising), they also need consent: see our GDPR cookie consent guide.
The checklist
- Headers verified on a page, an API response, a static asset, a redirect and a 404
- HTTPS only, with HTTP redirecting to HTTPS on the same host
-
Strict-Transport-Security: max-age=63072000, sent over HTTPS -
includeSubDomainsand preload only when every subdomain is HTTPS for good - CSP running in Report-Only, reports reviewed, then enforced
- No
'unsafe-inline'for scripts; nonces or hashes with'strict-dynamic' -
object-src 'none',base-uri 'self',frame-ancestors 'none' -
X-Frame-Options: DENYfor older browsers; noALLOW-FROM -
X-Content-Type-Options: nosniffand correctContent-Typeon every response -
Referrer-Policy: strict-origin-when-cross-originor stricter -
Permissions-Policydisabling unused features - COOP, COEP and CORP set where cross-origin isolation is needed
- Cookies:
Secure,HttpOnlyfor sessions,SameSite,__Host-for session cookies - Headers re-checked after every hosting, CDN or framework change
Where this fits
Headers are one layer. Input validation, authentication, authorisation and dependency hygiene matter more, and our web application security checklist covers them; file handling has its own risks, covered in handling file uploads safely. Headers also belong on your website launch checklist, and for regulated products they are part of the evidence in HIPAA-conscious software, fintech web apps and SOC 2 readiness.
Sources
- MDN HTTP headers reference and MDN Content Security Policy guide
- hstspreload.org submission requirements
- OWASP Secure Headers Project
- Next.js guide: Content Security Policy
This checklist is part of our compliance and risk guides. If you want headers, CSP and the rest of your security baseline set up properly, it is part of our cloud and DevOps and maintenance and support work. Tell us about your stack.
FAQ · 05 questions
Frequently asked questions
Which security headers should every website have?
At minimum: Strict-Transport-Security, X-Content-Type-Options: nosniff, a frame-ancestors directive (with X-Frame-Options for older browsers), Referrer-Policy and Permissions-Policy. Add a Content-Security-Policy, starting in Report-Only mode.
Is X-Frame-Options still needed if I use frame-ancestors?
MDN recommends the CSP frame-ancestors directive for more comprehensive control and notes that 'none' is similar to X-Frame-Options: DENY, which is also supported in older browsers. Sending both is a common belt-and-braces setup. Never use ALLOW-FROM: it is obsolete and browsers ignore the whole header.
Should I submit my domain to the HSTS preload list?
Only when every subdomain, including internal ones, serves HTTPS and you are sure that will stay true. Preloading requires includeSubDomains and a long max-age, and removal is slow because it depends on browser releases.
How do I add a Content Security Policy in Next.js?
The Next.js documentation shows a nonce-based CSP generated in Proxy (proxy.ts) before the page renders, but nonces require dynamic rendering, which disables static optimisation and CDN caching for those pages. For mostly static sites, a CSP without nonces in next.config, or the experimental Subresource Integrity option, keeps pages static.
What does X-Content-Type-Options: nosniff do?
It stops the browser guessing content types. For scripts and stylesheets, the browser blocks the response if its MIME type doesn't match what was expected, so every response needs a correct Content-Type header.