Learn/Website

Security headers: what to set and how

The response headers that switch on browser protections, safe values to start with, where to add them, and what to leave out.

Want this checked on your own domain?

Join the waitlist

Updated

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: SAMEORIGIN lets only your own pages frame the site. DENY blocks 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:

  1. Send the policy as report-only. Content-Security-Policy-Report-Only uses the same syntax but only reports violations. Reports need an endpoint, declared with Reporting-Endpoints and named by report-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.
  2. Review the reports while the site is used normally, and adjust the policy or the pages until only unwanted loads are reported.
  3. 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:

HeaderSetting
Server from nginxserver_tokens off; (the header stays as just nginx)
Server from ApacheServerTokens Prod in the main server configuration; it can’t be set per virtual host
X-Powered-By from PHPexpose_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 CloudflareThe 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:

BranchSecurity support until
8.2December 31, 2026
8.3December 31, 2027
8.4December 31, 2028
8.5December 31, 2029
  1. 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.
  2. 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.
  3. 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 PHPSESSID by default): session.cookie_secure = 1 and session.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

HeaderEffectStandard
X-Content-Type-Options: nosniffUse the declared type; block scripts and styles with the wrong typeFetch §3.6
X-Frame-OptionsDENY blocks all framing; SAMEORIGIN allows only your own originHTML §7.7
Content-Security-PolicyRestrict where resources load from; frame-ancestors restricts framingCSP Level 3
Content-Security-Policy-Report-OnlyReport, don’t enforceCSP Level 3
Referrer-PolicyHow much of the page address is sent onward; default strict-origin-when-cross-originReferrer Policy §3
Strict-Transport-SecurityAlways use HTTPS for this site; see HSTSRFC 6797

Details that trip people up:

  • frame-ancestors doesn’t fall back to default-src, and is ignored in a <meta> policy (CSP Level 3 §6.4.2). X-Frame-Options in a <meta> tag has no effect.
  • X-Frame-Options: ALLOW-FROM is obsolete; browsers ignore the whole header when they see it. Use frame-ancestors.
  • Sending X-Frame-Options more than once with conflicting values blocks framing entirely (HTML §7.7).
  • report-uri is the older reporting directive; MDN advises sending it alongside report-to until all browsers support report-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.

FindingCondition
Missing “nosniff”X-Content-Type-Options isn’t exactly nosniff (ignoring case and surrounding spaces)
Other sites can frame this siteNo frame-ancestors in Content-Security-Policy (or one that allows *), and X-Frame-Options isn’t DENY or SAMEORIGIN
No Content Security PolicyNo 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 versionsServer, X-Powered-By, X-AspNet-Version, or X-AspNetMvc-Version contains a version number such as 2.4
No longer gets security updatesA disclosed PHP version whose security support has ended, per php.net
Cookies without SecureA 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

Want this checked on your own domain?

Join the waitlist
Domain Readiness

Free checks for email, website, DNS, and registration, with plain-English fixes.

Domain Readiness™ (domainreadiness.com) is a service of Riviera Learning, LLC.