Guide

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

  1. Start gentle. Add the low-risk headers first: X-Content-Type-Options: nosniff, a sensible Referrer-Policy, and frame-ancestors (or X-Frame-Options) if your pages should not be embedded.
  2. CSP in Report-Only mode. Content-Security-Policy-Report-Only shows 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.
  3. 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. Add includeSubDomains only if every subdomain is HTTPS, and think hard before preload, because removal takes a long time.
  4. 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.
  5. 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 preload that cannot qualify (it requires includeSubDomains and a long enough max-age);
  • X-Frame-Options and frame-ancestors that disagree. frame-ancestors is 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, HttpOnly or SameSite (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

  1. Paste your current response headers into the HTTP Header Analyzer to see the gaps.
  2. Open the Security Headers Generator, pick a preset and adjust the values for your site.
  3. Read the warnings and the compatibility notes for each header.
  4. Copy the result in your server's format and deploy it.
  5. 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

Sources and further reading