Security headers: what to set and how
Want this checked on your own domain?
Join the waitlistUpdated
Message for whoever manages your website
Hi, could you add these security headers to every page of our website: “X-Content-Type-Options: nosniff”, “X-Frame-Options: SAMEORIGIN”, and “Referrer-Policy: strict-origin-when-cross-origin”? Please also mark our cookies “Secure” (and “HttpOnly” for login sessions), stop the server from showing software version numbers in its headers, and confirm our software still receives security updates. If we have logins, forms, or payments, could we also plan a Content Security Policy, starting in report-only mode? Thank you.
Want this checked on your own domain? Join the waitlist.
Check yours
Run the full report (join the waitlist for access) on your domain. Its website section checks the headers on your secure homepage, along with HSTS, which has its own guide.
Fix it
Start with this set. Each value is explained in the sections below.
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Where to add a header
Add headers in one place that every response passes through. If you set the same header in two places (say, the application and the CDN), visitors can receive it twice with different values.
nginx. In the server block. always adds the header to error responses too. A location that has its own add_header lines doesn’t inherit the server’s, so repeat them there (from nginx 1.29.3, add_header_inherit merge; changes this).
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
Apache (with mod_headers). In the virtual host or .htaccess. always adds the header to error and redirect responses too.
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
IIS. In web.config, under system.webServer → httpProtocol → customHeaders, add one <add name="…" value="…" /> per header.
Cloudflare. On the Rules Overview page, select Create rule → Response Header Transform Rule, then “Set static” for each header. Cloudflare also offers a Managed Transform (Rules Settings → Managed Transforms) called “Add security headers”. It adds nosniff, X-Frame-Options: SAMEORIGIN, and Referrer-Policy: same-origin, but also two retired headers (see what to leave out).
Netlify. A _headers file in the publish directory, or [[headers]] in netlify.toml. These don’t apply to responses from functions or server-side rendering; those must set their own headers.
/*
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Vercel. A headers entry in vercel.json with "source": "/(.*)" and one key/value pair per header.
Missing “nosniff” header
Without X-Content-Type-Options: nosniff, browsers may examine a file’s contents and decide for themselves what type it is (“MIME sniffing”). A file uploaded to your site as plain text that contains HTML could then be treated as a web page on your domain, scripts included. With nosniff, browsers use the declared Content-Type as-is, and refuse scripts and stylesheets served with the wrong type (Fetch Standard §3.6).
Add:
X-Content-Type-Options: nosniff
Before you do, make sure your server sends correct types: JavaScript as a JavaScript type such as text/javascript, and CSS as text/css. Files served with the wrong type will stop loading.
Check: run the report again; this finding is gone.
Other sites can frame this site
Any site can load yours inside a frame. That allows “clickjacking”: a page that shows your site, often invisibly, and tricks visitors into clicking things on it. Two headers prevent it:
X-Frame-Options: SAMEORIGINlets only your own pages frame the site.DENYblocks all framing. Supported by all current browsers.Content-Security-Policy: frame-ancestors 'self'does the same within a Content Security Policy, and can also list specific sites allowed to frame you.'none'blocks all framing. The quotes are part of the value and must be straight quotes.
If you send both, browsers use an enforced frame-ancestors and ignore X-Frame-Options (HTML Standard §7.7). Neither works when set in a <meta> tag; they must be response headers.
If another site legitimately embeds your pages (for example, a booking widget on a partner’s site), list that site in frame-ancestors instead of using SAMEORIGIN:
Content-Security-Policy: frame-ancestors 'self' https://partner.example.net
Check: run the report again; this finding is gone.
No Content Security Policy
A Content Security Policy (CSP) tells browsers where scripts, styles, images, and other resources may load from. If an attacker manages to inject a script into one of your pages (cross-site scripting), a good policy can stop it from running. It’s most worth the effort on sites with logins, forms, or payments.
A wrong policy breaks things: anything it doesn’t allow, including your own analytics, chat widget, or payment form, stops working. Don’t copy another site’s policy; it describes their scripts, not yours. Build yours in report-only mode first:
- Send the policy as report-only.
Content-Security-Policy-Report-Onlyuses the same syntax but only reports violations. Reports need an endpoint, declared withReporting-Endpointsand named byreport-to:Reporting-Endpoints: csp-endpoint="https://example.com/csp-reports" Content-Security-Policy-Report-Only: script-src 'nonce-{RANDOM}'; object-src 'none'; base-uri 'none'; report-to csp-endpoint
This is the nonce-based “strict CSP” MDN recommends.{RANDOM}stands for a value your server generates fresh and unpredictably for every response and also puts in each<script nonce="…">tag. That needs pages generated per request; for static pages, use hashes of each script instead ('sha256-…'). If a trusted script loads further scripts, as some third-party widgets do, add'strict-dynamic'; MDN’s CSP guide explains it. - Review the reports while the site is used normally, and adjust the policy or the pages until only unwanted loads are reported.
- Enforce it by renaming the header to
Content-Security-Policy. You can keep a report-only header alongside to test the next change; browsers honor both.
If the report says a report-only policy was found, you’re at step 2: the policy observes but doesn’t block anything yet.
A policy that contains only frame-ancestors protects against framing but doesn’t restrict scripts. Script protection comes from script-src (or default-src).
Check: the report no longer lists this finding once an enforced Content-Security-Policy header is sent.
No Referrer-Policy header
This is informational. When a visitor follows a link from your site, the browser can tell the destination which page they came from, in the Referer header (spelled that way in HTTP). Without a Referrer-Policy header, browsers apply their default, strict-origin-when-cross-origin: the full address to your own site, only the origin (such as https://example.com/) to other HTTPS sites, and nothing to plain HTTP sites (Referrer Policy §3). Setting it explicitly also covers older browsers, whose default was no-referrer-when-downgrade:
Referrer-Policy: strict-origin-when-cross-origin
Use no-referrer instead if page addresses on your site can contain private information.
The server reveals software versions
Headers such as Server: nginx/1.18.0 or X-Powered-By: PHP/8.1.2 announce exactly which software and version runs your site. That makes known vulnerabilities in that version easier to find. Hiding the number doesn’t fix anything by itself: MDN notes that keeping software updated is the more robust protection, and Apache’s documentation says removing the header “does nothing at all to make your server more secure”. Still, there’s no reason to advertise it: RFC 9110 §10.2.4 says servers SHOULD NOT send “needlessly fine-grained detail”.
Where to turn it off:
| Header | Setting |
|---|---|
Server from nginx | server_tokens off; (the header stays as just nginx) |
Server from Apache | ServerTokens Prod in the main server configuration; it can’t be set per virtual host |
X-Powered-By from PHP | expose_php = Off in php.ini (it can only be set there) |
X-AspNet-Version (classic ASP.NET) | <httpRuntime enableVersionHeader="false" /> in the <system.web> section of web.config |
X-Powered-By behind Cloudflare | The Managed Transform that removes X-Powered-By headers |
Apache’s own documentation recommends against settings below Minimal because they make interoperability problems harder to debug. That trade-off is yours; our report flags any header that includes a version number.
Check: run the report again; this finding is gone.
Software that no longer gets security updates
Your server’s headers report a version of PHP whose security support has ended. New vulnerabilities in it won’t be fixed. Updating is the fix; hiding the version number is not.
PHP supports each release branch for about four years: two years of active support, then two of security fixes only. Branches with security support as of October 2026:
| Branch | Security support until |
|---|---|
| 8.2 | December 31, 2026 |
| 8.3 | December 31, 2027 |
| 8.4 | December 31, 2028 |
| 8.5 | December 31, 2029 |
- Ask your host or developer to move the site to a supported branch. Choosing a newer one than 8.2 avoids repeating this in a few months.
- Test first, ideally on a copy of the site. Each PHP release has a migration guide listing changes that can break old code, plugins, or themes.
- Once the site runs on the new version, also turn off the version header (see above).
Check: the report shows the new version, or no version at all.
Cookies set without the Secure flag
Your homepage sets a login or session cookie without the Secure attribute. Browsers may then send it over plain http:// connections, where it can be read or changed in transit. With Secure, a cookie is only sent over HTTPS. Add HttpOnly to cookies that hold a login session, so page scripts can’t read them.
We list only cookies that look like they matter: ones named for a session, a login or a token (such as PHPSESSID, session or csrftoken), and ones marked HttpOnly, which only cookies meant for the server are. A preference, a country code or an analytics ID has no security role. We also leave out cookies that browsers never send over http:// anyway, because HTTPS is enforced for every address they go to for as long as they last: by the HSTS preload list, or by the page’s own HSTS header, with includeSubDomains when the cookie is shared with subdomains.
Set-Cookie: session=…; Path=/; Secure; HttpOnly
Where the setting lives depends on what sets the cookie:
- PHP sessions (cookie
PHPSESSIDby default):session.cookie_secure = 1andsession.cookie_httponly = 1. Both are off by default. - Your application or framework: look for a secure-cookie option in its cookie or session settings.
- A plugin or third-party service: check its settings, or ask its developer.
Check: run the report again; no cookie names are listed.
Technical reference
What each header does
| Header | Effect | Standard |
|---|---|---|
X-Content-Type-Options: nosniff | Use the declared type; block scripts and styles with the wrong type | Fetch §3.6 |
X-Frame-Options | DENY blocks all framing; SAMEORIGIN allows only your own origin | HTML §7.7 |
Content-Security-Policy | Restrict where resources load from; frame-ancestors restricts framing | CSP Level 3 |
Content-Security-Policy-Report-Only | Report, don’t enforce | CSP Level 3 |
Referrer-Policy | How much of the page address is sent onward; default strict-origin-when-cross-origin | Referrer Policy §3 |
Strict-Transport-Security | Always use HTTPS for this site; see HSTS | RFC 6797 |
Details that trip people up:
frame-ancestorsdoesn’t fall back todefault-src, and is ignored in a<meta>policy (CSP Level 3 §6.4.2).X-Frame-Optionsin a<meta>tag has no effect.X-Frame-Options: ALLOW-FROMis obsolete; browsers ignore the whole header when they see it. Useframe-ancestors.- Sending
X-Frame-Optionsmore than once with conflicting values blocks framing entirely (HTML §7.7). report-uriis the older reporting directive; MDN advises sending it alongsidereport-tountil all browsers supportreport-to.
Optional: Permissions-Policy
Permissions-Policy turns off browser features, such as the camera, microphone, or location, for your page and anything it embeds. For example, Permissions-Policy: camera=(), microphone=(), geolocation=() disables all three. Chrome and other Chromium-based browsers support the header; Firefox and Safari don’t. MDN marks it experimental. Our report doesn’t check it.
What to leave out
X-XSS-Protection: a retired browser feature. MDN warns it can create cross-site scripting vulnerabilities in otherwise safe sites and recommends a Content Security Policy instead.Expect-CT: deprecated since Chrome 107, which enforces Certificate Transparency by default.
What the report checks
We read the response headers of your secure homepage, the final https:// page after redirects, when it answers with status 200. We skip this check when the homepage redirects to another domain or a bot-protection page answers instead.
| Finding | Condition |
|---|---|
| Missing “nosniff” | X-Content-Type-Options isn’t exactly nosniff (ignoring case and surrounding spaces) |
| Other sites can frame this site | No frame-ancestors in Content-Security-Policy (or one that allows *), and X-Frame-Options isn’t DENY or SAMEORIGIN |
| No Content Security Policy | No Content-Security-Policy header with script-src or default-src, the directives that limit scripts. We say so when the policy sets neither, or when only a report-only policy is sent. A policy in a <meta> tag isn’t counted |
| No Referrer-Policy (informational) | No Referrer-Policy header |
| Reveals software versions | Server, X-Powered-By, X-AspNet-Version, or X-AspNetMvc-Version contains a version number such as 2.4 |
| No longer gets security updates | A disclosed PHP version whose security support has ended, per php.net |
| Cookies without Secure | A Set-Cookie header on the homepage without the Secure attribute, for a cookie named for a session, login or token, or marked HttpOnly. Not counted: a cookie being deleted; one browsers would reject; and one whose every address HTTPS is enforced on for its whole life, by the preload list or by the page’s own HSTS (includeSubDomains when the cookie has a Domain; a cookie with no expiry needs at least 180 days) |
Beyond whether it limits scripts at all, we don’t evaluate how strict a Content Security Policy is. We don’t check other pages or see cookies set by scripts in the browser.
Sources
- WHATWG Fetch Standard, §3.6 X-Content-Type-Options
- WHATWG HTML Standard, §7.7 The X-Frame-Options header
- W3C Content Security Policy Level 3 (Editor’s Draft), §6.4.2 frame-ancestors
- W3C Referrer Policy (Editor’s Draft), §3 Referrer policies
- RFC 6797, HTTP Strict Transport Security (HSTS)
- RFC 9110, HTTP Semantics, §10.2.4 Server
- MDN, X-Content-Type-Options
- MDN, X-Frame-Options
- MDN, Content Security Policy (CSP) guide
- MDN, Content-Security-Policy-Report-Only
- MDN, Referrer-Policy
- MDN, Permissions-Policy
- MDN, Set-Cookie
- MDN, Server
- MDN, X-XSS-Protection
- MDN, Expect-CT
- MDN browser compatibility data, Permissions-Policy header
- nginx, ngx_http_headers_module (add_header)
- nginx, ngx_http_core_module (server_tokens)
- Apache HTTP Server, mod_headers
- Apache HTTP Server, ServerTokens
- PHP manual, core php.ini directives (expose_php)
- PHP manual, session configuration (session.cookie_secure)
- PHP, Supported versions
- PHP, Unsupported branches
- Microsoft Learn, HttpRuntimeSection.EnableVersionHeader
- Microsoft Learn (archived blog), Remove unwanted HTTP response headers
- Cloudflare, Create a response header transform rule
- Cloudflare, Available Managed Transforms
- Netlify, Custom headers
- Vercel, vercel.json headers
Want this checked on your own domain?
Join the waitlist