Skip to main content
KalkuNet

CSP Header Generator — Build a Valid Content-Security-Policy

Build strict Content-Security-Policy rules controlling scripts, styles & frames.

Runs in your browserWeb · Security & Privacy
Start from:
Hash for an inline script
Read an existing CSP

✓ Valid syntax and no common gaps detected.

When to use the Content-Security-Policy (CSP) Header Generator

  • Validated like a browser does

    Every source is checked against the CSP Level 3 grammar: quoted keywords, nonces, SHA-256/384/512 hash lengths, schemes and hosts. Misspelled directives get a suggested fix.

  • Common gaps flagged

    'unsafe-inline' without a nonce, overly broad script sources such as https: or *, a forgotten object-src or base-uri and a missing frame-ancestors are explained one by one.

  • Ready for any server

    One policy comes out as an HTTP header, an Nginx, Apache or Caddy line, a _headers file for Cloudflare Pages/Netlify, or a meta tag, with a Report-Only trial mode.

  • Nonces and hashes made here

    Nonces come from the browser's cryptographic random generator, and inline-script hashes are computed with Web Crypto straight from the text you paste.

Frequently asked questions

How do I roll out CSP without breaking the site?

Start in Report-Only mode, collect violations from the console or report-to for a few days, refine the policy, then switch to the normal Content-Security-Policy header.

Why does the strict example contain 'unsafe-inline'?

It is a fallback for old browsers that do not know nonces. Modern browsers ignore it because a nonce and 'strict-dynamic' are present, so security is not reduced.

Is a CSP in a meta tag just as strong?

Almost, but frame-ancestors, sandbox and reporting do not apply through meta, and it only takes effect once parsed. An HTTP header is still the best choice.

How does CSP stop XSS attacks?

Browsers only run scripts from the sources listed in script-src. A script an attacker injects into the page has no valid nonce or hash, so it is blocked and logged as a violation.

Learn more