What this tool does
HTTP security headers are instructions your server sends with every response that tell the browser how strictly to treat your site: only use HTTPS, do not guess file types, do not let other sites frame you, and only load scripts from places you name. This generator lets you pick the headers, edit the values, and copy them in the format your server needs. It also checks the combination and explains what each header can break, because the headers that give the most protection are also the ones most likely to stop a working site.
- Nine headers: Content-Security-Policy (enforcing or Report-Only), Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy, Cross-Origin-Opener-Policy, Cross-Origin-Embedder-Policy and Cross-Origin-Resource-Policy.
- Five output formats: raw headers, nginx, Apache, Express middleware, and a
_headersfile for Cloudflare Pages or Netlify. - Warnings and notes for risky values such as
'unsafe-inline', a wildcard script source, a preload that cannot qualify, or X-Frame-Options andframe-ancestorsdisagreeing. - Presets for a typical site, a strict static site, and a gentle first rollout.
Which header does what
None of these replaces secure code. They limit the damage when something else goes wrong, and each one has a context where it is the wrong choice.
| Header | What it helps with | Use it when | Compatibility impact |
|---|---|---|---|
Strict-Transport-Security | Stops downgrade to HTTP and removes the first insecure request on later visits | The whole site, and any subdomains you add includeSubDomains for, works over valid HTTPS | Every covered host must keep valid HTTPS for the whole max-age. preload is very hard to reverse. |
Content-Security-Policy | Limits where scripts, styles, frames and more may load from, which reduces the effect of an injected script | Almost always worth having, but built for your page, not copied | Blocks inline scripts and anything not listed, including analytics, widgets and fonts |
X-Content-Type-Options | Stops the browser guessing that a file is a script or style | Safe default, once your files are served with correct Content-Type values | Wrongly typed scripts and styles stop loading |
X-Frame-Options / frame-ancestors | Prevents your pages being framed by other sites (clickjacking) | Pages that should not be embedded. frame-ancestors is the modern form; send both if you care about older browsers. | Blocks legitimate embedding, including by partners |
Referrer-Policy | Limits how much of the page URL is sent to other sites | URLs carry tokens, IDs or private paths | Analytics or partners that rely on the full referrer see less |
Permissions-Policy | Turns powerful features such as camera, microphone and location off for your page and its frames | You know which features the site and its embeds actually use | Embedded widgets that need a disabled feature stop working |
Cross-Origin-Opener-Policy | Separates your window from cross-origin windows, which helps against some cross-window leaks | Sites handling sensitive data, or those that need cross-origin isolation | Cuts window.opener for cross-origin pop-ups, which can break sign-in and payment flows |
Cross-Origin-Embedder-Policy | Required, together with COOP, for cross-origin isolation (needed by some high-resolution timers and shared memory features) | You need cross-origin isolation, not by default | Blocks third-party resources that do not send CORP or CORS headers |
Cross-Origin-Resource-Policy | Stops other sites loading your responses as subresources | Private or authenticated files that should never be hotlinked | Also blocks your own CDN domain or sister sites if set to same-origin |
Context decides almost everything here. An internal tool behind a login, a public marketing site, an API and an app that embeds third-party payment pages need different values. Treat the output as a starting point to test, not as a verdict on what your site needs.
Why Content-Security-Policy needs care
A CSP is the only header here that can stop your own pages from working. The browser enforces it literally: if the policy does not name a source, anything from that source is blocked. Common surprises:
- Inline scripts and styles stop running unless you allow them with a hash or nonce, or with
'unsafe-inline', which removes most of the protection. - Third-party scripts (analytics, chat, ads, maps) load more scripts and frames of their own, so one allowed host is often not enough.
- Fonts, images and API calls each have their own directive; falling back to
default-srcmay be stricter than you expect. - Nonces must be unique per response, so they need server-side code. A static file or a
_headersrule can use hashes, not nonces. - A policy in a
<meta>tag cannot useframe-ancestors,report-urior sandbox, and applies only after the tag is parsed. The HTTP header is more complete.
A safe way to introduce one is the same on every stack: send it as Content-Security-Policy-Report-Only first (tick Report-Only above), browse the whole site with DevTools open and fix every violation it logs, then switch the same value to the enforcing header. Applying a very restrictive policy straight to production is the usual way CSP causes an outage. If you only need to allow a few inline snippets, the hash helper above computes the 'sha256-...' source for you; the Hash Generator and Base64 tool show how the same value is built from a SHA-256 digest.
Rolling headers out safely
- Get HTTPS right first. HSTS is only honoured over HTTPS, so the site needs a valid certificate (the X.509 Certificate Inspector shows expiry and names) and HTTP should redirect to HTTPS with a permanent status such as 301 or 308; the HTTP Status Codes reference explains the difference.
- Start HSTS small. Begin with a short
max-agesuch as 300 seconds, raise it to a day, a week, then a year as nothing breaks. AddincludeSubDomainsonly when every subdomain is HTTPS, andpreloadlast. - Check Content-Type. Before
nosniff, confirm scripts, styles and JSON are served with the right type. The MIME Type Lookup lists the standard values. - Run CSP as Report-Only and fix violations, then enforce.
- Verify what the server really sends. Reverse proxies, CDNs and frameworks can add, replace or drop headers. Fetch your page with the cURL Command Generator (
curl -I), paste the response headers into the HTTP Header Analyzer, and compare them with what you intended.
Where to put the headers
- nginx: use
add_header ... always;so error responses carry them too. Watch the inheritance rule: if alocationblock defines anyadd_header, it does not inherit the ones from the enclosingserverblock, so repeat them. - Apache: needs
mod_headersenabled.Header always setalso covers error responses. - Express: the middleware above must be registered before your routes. Libraries such as Helmet set a similar default set; either approach works, so use one and avoid sending the same header twice.
- Cloudflare Pages and Netlify: a
_headersfile in the published folder. On Cloudflare Pages these rules apply to static assets; responses generated by Functions need their headers set in code.
Headers you probably should not copy from old guides
This tool does not generate these on purpose:
X-XSS-Protection: the old browser filter it controlled has been removed from current browsers, and in some older ones it could introduce problems. A good CSP is the replacement.Expect-CTandPublic-Key-Pins: deprecated or removed; Certificate Transparency is now handled by browsers and certificate authorities.Feature-Policy: renamed toPermissions-Policy.X-Frame-Options: ALLOW-FROM: not supported by current browsers; use CSPframe-ancestorsfor an allow-list.X-Content-Security-PolicyandX-WebKit-CSP: legacy names for CSP.
Common mistakes
- Writing
selfinstead of'self'. Without quotes it is read as a host name; the checks above flag this. - Putting
*,data:or'unsafe-inline'inscript-srcand assuming the policy still protects you. - Sending
X-Frame-Options: DENYand aframe-ancestorsthat allows framing, or the reverse. Browsers disagree on which wins unless both say the same thing. - Turning on
preloador a long HSTSmax-agebefore testing every subdomain. - Testing only the home page. Violations often appear on pages with embeds, forms or admin screens.
Privacy and local processing
This tool runs entirely in your browser. The values you enter, including any inline code you hash, are processed on your device and are not sent to a server. Sharing the page link does not share your configuration.