1. Home
  2. Guides
  3. Security headers explained
Security guide

HTTP security headers explained

Security headers are short instructions your server sends with every page that tell browsers to switch on built-in protections. They are cheap to add and are one of the first things a security review looks at.

Key points

  • Headers are defence in depth. They reduce the damage of mistakes elsewhere; they do not make an application secure on their own.
  • Start with the low-risk ones (X-Content-Type-Options, Referrer-Policy, framing protection) and roll out HSTS and CSP carefully.
  • Test CSP in report-only mode first. A strict policy that is enforced too early can break your own site.

What security headers are

When a browser loads a page, the server's response includes headers: key-value lines that describe the content. Some headers tell the browser how to behave: only use HTTPS for this site, do not guess file types, do not let other sites embed this page. Browsers enforce these rules for you, so they are among the cheapest security improvements available.

The WebsiteHealthLabs audit checks the headers below on the final URL of your page and scores them with the weights listed on the methodology page. It is a header check, not a penetration test of your application.

HeaderProtects againstRisk to roll out
Strict-Transport-SecurityDowngrade to HTTP, cookie theft on insecure networksMedium: hard to undo once set for a long time
Content-Security-PolicyCross-site scripting and data injectionHigh: can break pages if too strict
X-Content-Type-OptionsMIME-type sniffingLow
frame-ancestors / X-Frame-OptionsClickjackingLow, unless you are embedded on purpose
Referrer-PolicyLeaking page addresses to other sitesLow
Permissions-PolicyUnwanted use of browser featuresLow

Strict-Transport-Security (HSTS)

After a browser sees this header over HTTPS, it refuses to talk to your domain over plain HTTP for the stated period, even if someone types http:// or follows an old link. It closes the window in which an attacker on the network could intercept the first insecure request.

Strict-Transport-Security: max-age=31536000; includeSubDomains
  • max-age is in seconds. 31536000 is one year. Start small (a few minutes or a day), confirm nothing breaks, then raise it. Our audit treats six months (15552000) or more as a pass.
  • includeSubDomains applies the rule to every subdomain, so only add it when all of them support HTTPS.
  • preload is a request to be included in browsers' built-in lists. It has strict requirements (including a max-age of at least one year and includeSubDomains) and is hard to reverse, so treat it as a deliberate, later step.
  • Send it only over HTTPS. Browsers ignore it on HTTP responses.

Content-Security-Policy (CSP)

A CSP lists where scripts, styles, images, frames and other resources may come from. If an attacker manages to inject a script tag into your page, a good policy stops the browser from running it. It is the strongest header here and the one most likely to need care.

Content-Security-Policy: default-src 'self'; img-src 'self' data:; script-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'
  • Begin with Content-Security-Policy-Report-Only and a report-to/report-uri endpoint (or just watch the browser console). It logs what would have been blocked without blocking anything.
  • Avoid 'unsafe-inline' and 'unsafe-eval' in script-src; they remove most of the benefit. Use nonces or hashes for inline scripts you cannot move to files.
  • Wildcards (*), data: and broad https: sources in script-src also weaken the policy. WebsiteHealthLabs marks such a policy as partially effective.
  • Add third parties one at a time, only the ones you actually use.

X-Content-Type-Options

Browsers sometimes guess a file's type from its content instead of trusting the declared Content-Type. That can turn an uploaded text file into running script. The only valid value, nosniff, switches the guessing off.

X-Content-Type-Options: nosniff

Make sure your server sends correct content types first, especially for scripts and stylesheets, since browsers will then enforce them.

Clickjacking protection

In a clickjacking attack another site loads yours in a transparent frame and tricks visitors into clicking buttons they cannot see. The modern fix is the CSP frame-ancestors directive; the older X-Frame-Options header is still widely supported and our audit accepts either.

Content-Security-Policy: frame-ancestors 'self'
X-Frame-Options: SAMEORIGIN

Use 'none' / DENY if nobody should embed you, and list specific origins if partners do. ALLOW-FROM is obsolete; use frame-ancestors for that.

Referrer-Policy

When a visitor clicks a link, the browser can send the previous page's address in the Referer request header. Page addresses can contain search terms, tokens or internal paths. Modern browsers default to a sensible setting, but an explicit policy makes it consistent.

Referrer-Policy: strict-origin-when-cross-origin

This sends the full address to your own pages and only the origin to other sites, and nothing when moving from HTTPS to HTTP. no-referrer is stricter. unsafe-url is the one to avoid.

Permissions-Policy

Lets you turn off browser features your site never uses (camera, microphone, geolocation, payment, USB and more), including for embedded third-party frames.

Permissions-Policy: camera=(), microphone=(), geolocation=()

An empty list () disables the feature for everyone. Use (self) to allow only your own pages.

Other headers and checks

  • Cookie flags: Secure, HttpOnly and SameSite are set per cookie, not as headers. Our audit checks cookies set on the page response.
  • Cross-origin isolation headers (Cross-Origin-Opener-Policy, Cross-Origin-Resource-Policy, Cross-Origin-Embedder-Policy) are useful for specific advanced cases and are not scored by our audit.
  • Version disclosure: headers like Server: nginx/1.24.0 or X-Powered-By reveal software versions. They are not a vulnerability, but there is little reason to publish them.

A safe rollout order

  1. Confirm the whole site works on HTTPS and redirects HTTP to HTTPS.
  2. Add X-Content-Type-Options, Referrer-Policy, clickjacking protection and Permissions-Policy.
  3. Add HSTS with a short max-age, then increase it.
  4. Add CSP in report-only mode, fix violations, then enforce.
  5. Re-run the audit and check that nothing on the site broke.

See also: HTTP headers explained, Website down: what to check.

FAQ

Do security headers improve SEO?

Not directly. HTTPS is a lightweight ranking signal, and HSTS keeps visitors on it, but the other headers are about safety rather than ranking.

Where do I set these headers?

At your web server (Nginx, Apache), CDN or hosting control panel, or in your application framework. Set them once at the edge where possible so every response gets them.

Can a CSP break my site?

Yes, if it blocks resources your pages rely on. That is why you start in report-only mode, review what would be blocked and only then enforce the policy.

Is a full score here a guarantee that my site is secure?

No. Headers are one layer. Patching software, validating input, strong authentication and backups matter at least as much.

WebsiteHealthLabs Editorial
Guides explain audit results in plain English. Facts are checked against public documentation from Google, W3C and the browser vendors, and we update them when guidance changes.

↑ ↓ to moveEnter to openEsc to closeAll results