HTTP Security Headers: CSP, HSTS and a Safe Rollout
Short answer: HTTP security headers are instructions your server sends with every response telling the browser how strict to be: use HTTPS only, do not guess file types, do not let other sites frame you, and load scripts only from places you name. The headers that protect the most are also the ones most likely to break a working site, so roll them out in steps. Build them in the Security Headers Generator and test what you already send with the HTTP Header Analyzer.
None of these headers replaces secure code. They limit the damage when something else goes wrong.
The headers, what they help with, and what they can break
| Header | Helps with | Can break |
|---|---|---|
| Strict-Transport-Security (HSTS) | Stops downgrade to HTTP and removes the first insecure request on later visits | Every covered host must keep valid HTTPS for the whole max-age. preload is very hard to reverse |
| Content-Security-Policy (CSP) | Limits where scripts, styles, frames and more may load from, which reduces the effect of an injected script | Inline scripts and anything not listed: analytics, widgets, fonts |
| X-Content-Type-Options | Stops the browser guessing that a file is a script or style | Wrongly typed scripts and styles stop loading |
X-Frame-Options / frame-ancestors |
Prevents other sites framing your pages (clickjacking) | Legitimate embedding, including by partners |
| Referrer-Policy | Limits how much of the page URL is sent to other sites | Analytics or partners that rely on the full referrer |
| Permissions-Policy | Turns powerful features (camera, microphone, location) off for your page and its frames | Embedded widgets that need a disabled feature |
| Cross-Origin-Opener-Policy (COOP) | Separates your window from cross-origin windows | Cross-origin pop-ups, which can break sign-in and payment flows |
| Cross-Origin-Embedder-Policy (COEP) | Needed with COOP for cross-origin isolation | Third-party resources that send no CORP or CORS headers |
| Cross-Origin-Resource-Policy (CORP) | Stops other sites loading your responses as subresources | Your own CDN or sister sites, if set too tightly |
A rollout that does not take your site down
- Start gentle. Add the low-risk headers first:
X-Content-Type-Options: nosniff, a sensibleReferrer-Policy, andframe-ancestors(orX-Frame-Options) if your pages should not be embedded. - CSP in Report-Only mode.
Content-Security-Policy-Report-Onlyshows what would be blocked without blocking it. Build the policy for your page, not from a copied example, and fix the violations. Only then switch to enforcing. - HSTS in small steps. Begin with a short
max-age, confirm every host in scope serves valid HTTPS (you can inspect a certificate to check it), and raise it later. AddincludeSubDomainsonly if every subdomain is HTTPS, and think hard beforepreload, because removal takes a long time. - Review the odd ones. COOP, COEP and CORP matter mainly for sensitive sites and for pages that need cross-origin isolation. Do not enable them by default.
- Re-test after every change. Sign-in, payment, embeds, analytics, fonts.
Pitfalls the generator warns about
'unsafe-inline'in a CSP, or a wildcard script source, which weaken the policy a lot;- an HSTS
preloadthat cannot qualify (it requiresincludeSubDomainsand a long enoughmax-age); X-Frame-Optionsandframe-ancestorsthat disagree.frame-ancestorsis the modern form, and you can send both for older browsers.
The generator ships presets for a typical site, a strict static site and a gentle first rollout, and explains each header as you edit.
Output for your server
The generator copies the result as raw headers, nginx, Apache, Express middleware, or a _headers file for Cloudflare Pages or Netlify. For a static site on Cloudflare Pages the _headers file is the simplest route: one file in the site root, uploaded with the rest of the site. Remember that a path-specific rule in that file can add to or replace the general one, so check the result for the pages that matter.
Check what you actually send
Headers can be added, removed or duplicated by a CDN or proxy, so test the real response. Copy the headers from your browser's Network tab or from curl -i (see how to copy a request as cURL from the Network tab), paste them into the HTTP Header Analyzer, and read the notes. It checks for:
- missing HSTS, Content-Security-Policy, X-Content-Type-Options, X-Frame-Options, Referrer-Policy and Permissions-Policy;
- cookies set without
Secure,HttpOnlyorSameSite(explained in HTTP headers and cookie flags); Access-Control-Allow-Origin: *combined with credentials, which browsers reject;- repeated header names.
X-Frame-Options is not reported as missing when the CSP has frame-ancestors, and a Content-Security-Policy-Report-Only header does not count as an enforced policy. Those notes are general suggestions, not a security audit: an internal API with no cookies may reasonably skip some of them.
How to check HTTP security headers with the two tools
- Paste your current response headers into the HTTP Header Analyzer to see the gaps.
- Open the Security Headers Generator, pick a preset and adjust the values for your site.
- Read the warnings and the compatibility notes for each header.
- Copy the result in your server's format and deploy it.
- Check the live response again with the analyzer.
Limits to know
- Headers reduce risk. They do not fix vulnerable code.
- A good CSP has to match your page. Copying a policy from another site usually breaks something.
- Both tools run in your browser and send nothing anywhere. The analyzer reads only what you paste, and it does not fetch your site.
- Browser support differs for newer headers. Check current compatibility before you rely on one.
Frequently asked questions
What are HTTP security headers? Response headers that tell the browser how strictly to treat your site, for example HTTPS only, no framing and restricted script sources.
What is the safest way to add a CSP? Start in Report-Only mode, fix what it reports, then enforce.
Is X-Frame-Options still needed?
frame-ancestors in CSP is the modern way. Sending both covers older browsers.
Should I use HSTS preload? Only when every subdomain is HTTPS and you are sure. Removal is slow.
Where do I put headers on Cloudflare Pages?
In a _headers file at the site root. The generator can output that format.
Related tools and guides
- Meta tags, Open Graph and Twitter cards
- DNS records explained
- HTTP Header Analyzer
- HTTP Status Codes for the status line (see 401 vs 403, 301 vs 302)
- cURL Command Generator to fetch headers with
curl -i - X.509 Certificate Inspector: HTTPS and HSTS rely on valid certificates (see How to decode a PEM certificate)
- DNS Analyzer
- Meta Tag Generator
- WCAG colour contrast guide for the accessibility side of the same site checklist