The best security headers every website needs are Strict-Transport-Security, Content-Security-Policy, X-Frame-Options (or CSP frame-ancestors), X-Content-Type-Options, Referrer-Policy and Permissions-Policy. Together they force HTTPS, block cross-site scripting and clickjacking, stop MIME sniffing, and limit what browsers share. Add the cross-origin isolation headers and Clear-Site-Data for advanced protection, and test the result with a free security headers checker.
Key takeaways
- Six core headers — HSTS, CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Permissions-Policy — cover most browser-side attacks.
- Content-Security-Policy is the most powerful header and the only one that needs real design; roll it out in report-only mode first.
- X-XSS-Protection is deprecated: OWASP recommends sending X-XSS-Protection: 0 or omitting it and relying on CSP instead.
Security headers are a few lines of server configuration that tell browsers to refuse framing, stop guessing content types, insist on HTTPS, and limit where scripts can load from. They cost nothing, slow nothing down, and block whole classes of attack that no amount of application code can fix on its own.
What are security headers, and why do they matter?
Security headers are HTTP response headers your server sends with every page, telling the browser how to handle that page. They are the browser's instructions for what to trust, what to block, and what never to do.
They matter because many attacks happen in the browser, not on your server. Cross-site scripting, clickjacking, MIME sniffing and protocol downgrade all exploit a browser that was never told to be careful. A header closes that gap in one line, before any JavaScript runs.
The OWASP Secure Headers Project lists more than fifteen headers, but only a handful are essential for every site. The OWASP response headers page gives each header's purpose and recommended value, and this list follows it. You can check your own site in seconds with our free security headers checker.
How did we choose the best security headers?
We ranked headers by OWASP's own guidance, by the severity of the attack each one blocks, and by how widely scanners and auditors check for them. A header that blocks a critical attack class on every site outranks one that only matters for advanced use cases.
The first six are the core set: they belong on virtually every public website, and most security header scanners grade them. The next six are situational or advanced — valuable, but only when your site needs what they protect. Headers OWASP lists as deprecated, such as Expect-CT and Public-Key-Pins, are left out entirely.
Best security headers compared
The six core headers deliver most of the protection. The advanced six add isolation and privacy hardening for sites that need them, such as apps using SharedArrayBuffer or handling sensitive sessions.
| Header | Best for | Recommended value | Priority |
|---|---|---|---|
| Strict-Transport-Security | Forcing HTTPS | max-age=63072000; includeSubDomains | Core |
| Content-Security-Policy | Blocking XSS | default-src 'self'; script-src 'self' | Core |
| X-Frame-Options | Blocking clickjacking | DENY | Core |
| X-Content-Type-Options | Stopping MIME sniffing | nosniff | Core |
| Referrer-Policy | Limiting referrer leaks | strict-origin-when-cross-origin | Core |
| Permissions-Policy | Disabling browser features | camera=(), microphone=(), geolocation=() | Core |
| Cross-Origin-Opener-Policy | Process isolation | same-origin | Advanced |
| Cross-Origin-Embedder-Policy | Cross-origin isolation | require-corp | Advanced |
| Cross-Origin-Resource-Policy | Blocking cross-origin reads | same-origin | Advanced |
| Clear-Site-Data | Logout cleanup | "cache", "cookies", "storage" | Advanced |
| Cache-Control | Stopping sensitive caching | no-store | Advanced |
| X-Permitted-Cross-Domain-Policies | Blocking Flash-era cross-domain access | none | Advanced |
Values are OWASP's recommended starting points. A Content-Security-Policy must be built for your own site; the value in the table is a minimal example, not a policy to copy blindly.
The 12 best security headers
Each header below states what it does, the attack it blocks, the recommended value, and the mistake that most often breaks it. Start with the first six, verify with a checker, then add the advanced set.
1. Strict-Transport-Security (HSTS) — best for forcing HTTPS
HSTS tells the browser to interact with your site only over HTTPS, for a set time, even if a user types http:// or clicks an old http link. It protects against protocol downgrade attacks and cookie hijacking on insecure connections, and it is specified in RFC 6797.
The OWASP recommended value is Strict-Transport-Security: max-age=63072000; includeSubDomains; preload, though preload should only be added deliberately: it submits your domain to browser-hardcoded preload lists, which is hard to undo. Note that the header is ignored by the browser when your site has only been accessed over HTTP.
Pros: one line, huge protection; no application changes. Cons: a mistake can lock users out of HTTP subdomains; preload is effectively permanent. Who should use it: every HTTPS site.
2. Content-Security-Policy (CSP) — best for blocking cross-site scripting
CSP lists where scripts, styles, images, frames and connections may load from; anything else is blocked. It is the most powerful header on this list and the primary defence against cross-site scripting, which OWASP ranks as a top injection risk.
There is no universal value — a policy must be built for your site. A minimal starting example is Content-Security-Policy: default-src 'self'; script-src 'self'. Roll it out in report-only mode first, using Content-Security-Policy-Report-Only, so you can see what would break without breaking it.
Pros: blocks XSS and injected third-party code; report-only mode makes rollout safe. Cons: needs real design; allowing 'unsafe-inline' largely defeats it. Who should use it: every site, starting in report-only mode.
3. X-Frame-Options — best for blocking clickjacking
X-Frame-Options controls whether your pages can be embedded in a frame on another site. Set to DENY, it stops clickjacking attacks in which an attacker frames your page invisibly and tricks users into clicking something they cannot see.
The recommended value is X-Frame-Options: DENY, or SAMEORIGIN if framing by your own domain is required. The modern replacement is CSP's frame-ancestors directive, which does the same job with more flexibility — use it if your CSP is already in place, and keep X-Frame-Options for older browsers.
Pros: one word stops clickjacking; trivial to set. Cons: superseded by frame-ancestors; no reporting. Who should use it: every site that does not need to be framed.
4. X-Content-Type-Options — best for stopping MIME sniffing
This header stops browsers from guessing a file's type. Without it, a browser may treat an uploaded file as a script or stylesheet even when the server says otherwise — the classic MIME-sniffing attack that turns a file upload into code execution.
The value is simply X-Content-Type-Options: nosniff. There is no reason not to send it: it has no downside, breaks nothing when your content types are correct, and every major scanner checks for it.
Pros: free, zero risk, universally recommended. Cons: none of note. Who should use it: every site, especially any site with file uploads.
5. Referrer-Policy — best for limiting referrer leaks
Referrer-Policy controls how much referrer information the browser sends when a user follows a link from your site. Without it, full URLs — including paths that may contain tokens or private identifiers — can leak to the destination site.
The recommended value is Referrer-Policy: strict-origin-when-cross-origin, which sends the full URL for same-origin requests but only the origin for cross-origin ones. It is a privacy control as much as a security one, and it costs nothing to set.
Pros: stops URL and token leakage; no breakage risk. Cons: analytics tools that rely on full referrers see less data. Who should use it: every site, especially sites with private or tokenized URLs.
6. Permissions-Policy — best for disabling unwanted browser features
Permissions-Policy, the successor to the deprecated Feature-Policy, lets you disable browser features your site does not use, such as the camera, microphone and geolocation. If a script injection ever succeeds, it cannot turn on a feature you have already switched off.
A good starting value is Permissions-Policy: camera=(), microphone=(), geolocation=(), which disables all three everywhere. Add features your site genuinely needs, such as payment or fullscreen, only where they are required.
Pros: reduces attack surface; easy to audit. Cons: a too-strict policy can break a feature you forgot you used. Who should use it: every site; start strict and loosen only on evidence.
7. Cross-Origin-Opener-Policy (COOP) — best for process isolation
COOP isolates your page's browsing context from cross-origin pages, so a malicious page that opens yours cannot reach into it. It is part of the cross-origin isolation set, and it is rated high severity by header scanners because its absence enables cross-origin leakage.
The recommended value is Cross-Origin-Opener-Policy: same-origin. It matters most for sites that handle sensitive data in the same tab as other sites, such as banking and webmail. Most simple sites can add it without noticing any change.
Pros: strong isolation; simple value. Cons: can break cross-origin popups and OAuth flows that rely on window access. Who should use it: sites handling sensitive sessions.
8. Cross-Origin-Embedder-Policy (COEP) — best for cross-origin isolation
COEP requires that resources loaded by your page either come from the same origin or explicitly allow being loaded cross-origin. Together with COOP, it enables full cross-origin isolation, which is required for powerful features such as SharedArrayBuffer.
The recommended value is Cross-Origin-Embedder-Policy: require-corp. Do not set it casually: third-party scripts, fonts and images that do not send the right headers will stop loading, so audit your dependencies first.
Pros: enables advanced features safely; deep isolation. Cons: breaks third-party resources that are not configured for it. Who should use it: apps that need SharedArrayBuffer or strong process isolation.
9. Cross-Origin-Resource-Policy (CORP) — best for blocking cross-origin reads
CORP tells the browser which other origins are allowed to read a resource. It stops other sites from loading your resources in ways that leak data, such as using an image or script request to probe whether a user is logged in.
The recommended value is Cross-Origin-Resource-Policy: same-origin for resources that only your own site should load, or same-site where your subdomains need access. It is a medium-severity header, but it is cheap insurance for sensitive endpoints.
Pros: blocks cross-origin data leaks; pairs with COEP. Cons: needs care with CDNs and shared assets. Who should use it: sites with sensitive resources or APIs.
10. Clear-Site-Data — best for logout cleanup
Clear-Site-Data tells the browser to delete data associated with your site: cache, cookies, storage and execution contexts. It belongs on logout endpoints, not site-wide, so that signing out actually signs the user out everywhere that matters.
The value is Clear-Site-Data: "cache", "cookies", "storage", sent in the response to a logout request. On shared or public computers this is the difference between a logout that works and one that leaves a session behind.
Pros: makes logout real; protects shared devices. Cons: only useful on logout responses; sending it site-wide would log users out constantly. Who should use it: any site with user accounts.
11. Cache-Control — best for stopping sensitive data being cached
Cache-Control is not only a performance header: with the right value it stops browsers and proxies from storing sensitive responses. A cached bank statement or medical result on a shared computer is a data breach waiting for the next user.
For sensitive pages, send Cache-Control: no-store. For public assets, keep normal caching — the header's job here is to be precise about what must never be stored, not to disable caching everywhere.
Pros: prevents data lingering on shared devices; simple. Cons: a blanket no-store hurts performance if applied to static assets. Who should use it: any site serving sensitive or authenticated content.
12. X-Permitted-Cross-Domain-Policies — best for blocking legacy cross-domain access
This header controls cross-domain policy files for Flash and PDF clients — a legacy mechanism, but one that still matters for sites serving PDFs and other embeddable content. The recommended value is X-Permitted-Cross-Domain-Policies: none.
It is the lowest-priority header on this list, and most scanners list it as recommended rather than critical. Send it anyway: it is one line, it has no downside, and it closes a door that modern browsers still respect.
Pros: one line, no downside. Cons: marginal benefit on modern stacks. Who should use it: any site that wants a complete header set.
How do I add security headers to my website?
Add them in your server or framework configuration, not in application code. For Nginx, add the headers in the server block; for Apache, use .htaccess or the virtual host; for Node.js, the Helmet library (version 8.3.0 on npm in October 2026) sets 13 headers with one line, including a sensible default CSP and removal of X-Powered-By.
Deploy to staging first, test with a checker, and watch for breakage: a strict CSP can block a script your site needs, and COOP can break an OAuth popup. The HTTP security headers checklist gives copy-ready Nginx and Helmet configuration for the core set.
Then test in production. Run our security headers checker and the MDN HTTP Observatory, which grades headers and related settings — when it ran for developer.mozilla.org in October 2026 it reported grade A+, score 110, with 12 of 12 tests passed. Keep the checker in your deployment pipeline so a new framework version cannot silently drop a header.
What mistakes should I avoid with security headers?
The most common mistake is copying a CSP from another site. A policy built for someone else's dependencies will either block your scripts or allow far more than you need. Build yours from your own report-only violations, and keep 'unsafe-inline' out of script-src if you can.
The second mistake is setting HSTS preload without understanding it. Preload puts your domain on a browser-hardcoded list, and removing it is slow and unreliable. Only add preload after you are certain every subdomain works over HTTPS.
The third mistake is forgetting headers exist after setting them. Framework upgrades, CDN changes and new deployments can all drop headers silently. A checker in your pipeline catches that before your users do.
For the wider website hardening picture, read our guide to DMARC for email authentication.
Check your TLS setup with our SSL checker as well, since headers only help when the underlying HTTPS is sound.
The bottom line
Start with the six core headers: HSTS, CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Permissions-Policy. They are free, fast to add, and they close the most common browser-side attack classes in a single deployment.
Add the advanced set where your site needs it, roll CSP out in report-only mode, and retest after every deployment. You can verify your site right now with the free security headers checker.
Frequently asked questions
What are the best security headers for a website?
The six essential headers are Strict-Transport-Security, Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Permissions-Policy. They are the OWASP core set and the headers graded by most security header scanners.
What is the most important security header?
Content-Security-Policy is the most important, because it is the primary defence against cross-site scripting. Strict-Transport-Security is the next most important, because it stops downgrade attacks that strip HTTPS away.
Do security headers slow down a website?
No. Headers are a few lines of text sent with each response and add no measurable load time. A strict Content-Security-Policy can block a resource your site needs, so test before enforcing it.
Should I still use X-XSS-Protection?
No. OWASP recommends sending X-XSS-Protection: 0 or not setting it at all. The old browser XSS filter it controlled is gone from modern browsers and could itself be abused, so rely on a strong Content-Security-Policy instead.
How do I test my security headers?
Use a free security headers checker or the MDN HTTP Observatory, which grades your headers and related settings. Fix the headers it flags, retest, and check again after every deployment, because a new framework version can change what your site sends.
What is the difference between X-Frame-Options and CSP frame-ancestors?
Both stop clickjacking by controlling which sites can frame your pages. X-Frame-Options is the older header, while CSP frame-ancestors is the modern replacement. Use frame-ancestors if your CSP is in place, and keep X-Frame-Options for older browsers.
Can security headers replace a web application firewall?
No. Headers tell the browser how to behave, while a web application firewall inspects traffic before it reaches your server. They solve different problems and work best together.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against the OWASP Secure Headers Project's response headers list and its recommended configuration values.
How we write and fact-check →