Security

Security Headers Generator

Build a set of HTTP security headers, see what each one does and what it can break, and copy the result for nginx, Apache, Express or Cloudflare Pages. Warnings point out risky combinations before they reach production.

Guide: HTTP Security Headers: CSP, HSTS and a Safe Rollout

Features left unticked above are switched off for every origin. Also switch off completely:

Hash an inline script or style

If your page has an inline <script> or <style> you cannot move to a file, paste its exact text (what sits between the tags, including whitespace) to compute a SHA-256 source and add it to the policy. The text is hashed in your browser.

Ready.

Checks on this combination

    Raw headers

    nginx

    Apache

    Node.js (Express middleware)

    Cloudflare Pages / Netlify (_headers file)

    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 _headers file 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 and frame-ancestors disagreeing.
    • 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.

    HeaderWhat it helps withUse it whenCompatibility impact
    Strict-Transport-SecurityStops downgrade to HTTP and removes the first insecure request on later visitsThe whole site, and any subdomains you add includeSubDomains for, works over valid HTTPSEvery covered host must keep valid HTTPS for the whole max-age. preload is very hard to reverse.
    Content-Security-PolicyLimits where scripts, styles, frames and more may load from, which reduces the effect of an injected scriptAlmost always worth having, but built for your page, not copiedBlocks inline scripts and anything not listed, including analytics, widgets and fonts
    X-Content-Type-OptionsStops the browser guessing that a file is a script or styleSafe default, once your files are served with correct Content-Type valuesWrongly typed scripts and styles stop loading
    X-Frame-Options / frame-ancestorsPrevents 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-PolicyLimits how much of the page URL is sent to other sitesURLs carry tokens, IDs or private pathsAnalytics or partners that rely on the full referrer see less
    Permissions-PolicyTurns powerful features such as camera, microphone and location off for your page and its framesYou know which features the site and its embeds actually useEmbedded widgets that need a disabled feature stop working
    Cross-Origin-Opener-PolicySeparates your window from cross-origin windows, which helps against some cross-window leaksSites handling sensitive data, or those that need cross-origin isolationCuts window.opener for cross-origin pop-ups, which can break sign-in and payment flows
    Cross-Origin-Embedder-PolicyRequired, together with COOP, for cross-origin isolation (needed by some high-resolution timers and shared memory features)You need cross-origin isolation, not by defaultBlocks third-party resources that do not send CORP or CORS headers
    Cross-Origin-Resource-PolicyStops other sites loading your responses as subresourcesPrivate or authenticated files that should never be hotlinkedAlso 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-src may be stricter than you expect.
    • Nonces must be unique per response, so they need server-side code. A static file or a _headers rule can use hashes, not nonces.
    • A policy in a <meta> tag cannot use frame-ancestors, report-uri or 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

    1. 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.
    2. Start HSTS small. Begin with a short max-age such as 300 seconds, raise it to a day, a week, then a year as nothing breaks. Add includeSubDomains only when every subdomain is HTTPS, and preload last.
    3. Check Content-Type. Before nosniff, confirm scripts, styles and JSON are served with the right type. The MIME Type Lookup lists the standard values.
    4. Run CSP as Report-Only and fix violations, then enforce.
    5. 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 a location block defines any add_header, it does not inherit the ones from the enclosing server block, so repeat them.
    • Apache: needs mod_headers enabled. Header always set also 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 _headers file 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-CT and Public-Key-Pins: deprecated or removed; Certificate Transparency is now handled by browsers and certificate authorities.
    • Feature-Policy: renamed to Permissions-Policy.
    • X-Frame-Options: ALLOW-FROM: not supported by current browsers; use CSP frame-ancestors for an allow-list.
    • X-Content-Security-Policy and X-WebKit-CSP: legacy names for CSP.

    Common mistakes

    • Writing self instead of 'self'. Without quotes it is read as a host name; the checks above flag this.
    • Putting *, data: or 'unsafe-inline' in script-src and assuming the policy still protects you.
    • Sending X-Frame-Options: DENY and a frame-ancestors that allows framing, or the reverse. Browsers disagree on which wins unless both say the same thing.
    • Turning on preload or a long HSTS max-age before 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.

    Share this tool

    Your data is not included in this link.