
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.
| Header | Protects against | Risk to roll out |
|---|---|---|
Strict-Transport-Security | Downgrade to HTTP, cookie theft on insecure networks | Medium: hard to undo once set for a long time |
Content-Security-Policy | Cross-site scripting and data injection | High: can break pages if too strict |
X-Content-Type-Options | MIME-type sniffing | Low |
frame-ancestors / X-Frame-Options | Clickjacking | Low, unless you are embedded on purpose |
Referrer-Policy | Leaking page addresses to other sites | Low |
Permissions-Policy | Unwanted use of browser features | Low |
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-ageis 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.includeSubDomainsapplies the rule to every subdomain, so only add it when all of them support HTTPS.preloadis a request to be included in browsers' built-in lists. It has strict requirements (including a max-age of at least one year andincludeSubDomains) 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-Onlyand areport-to/report-uriendpoint (or just watch the browser console). It logs what would have been blocked without blocking anything. - Avoid
'unsafe-inline'and'unsafe-eval'inscript-src; they remove most of the benefit. Use nonces or hashes for inline scripts you cannot move to files. - Wildcards (
*),data:and broadhttps:sources inscript-srcalso 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,HttpOnlyandSameSiteare 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.0orX-Powered-Byreveal software versions. They are not a vulnerability, but there is little reason to publish them.
A safe rollout order
- Confirm the whole site works on HTTPS and redirects HTTP to HTTPS.
- Add
X-Content-Type-Options,Referrer-Policy, clickjacking protection andPermissions-Policy. - Add HSTS with a short max-age, then increase it.
- Add CSP in report-only mode, fix violations, then enforce.
- 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.