CSP Generator — Policy Drafts, Nonces and Limited Checks

Draft Content Security Policy headers, generate sample nonces and script hashes, and inspect limited policy notes. Test every policy on your real website.

🔒 Local processing
⚡ Free to use
🌐 Runs in your browser
📦 See output options
⚡

CSP Generator — Policy Drafts, Nonces and Limited Checks

Tool workspace

Ready

Loading tool...

  1. Choose a starting preset and edit the sources needed by your site.
  2. Add one source per custom entry and review the limited checks.
  3. Select the required output format; prefer HTTP headers for full directive support.
  4. Test on your own site before enforcement and generate fresh nonces per response.

Draft a policy for your site

This editor assembles CSP directives from selected tokens and custom sources. Presets are starting examples, not policies validated against your application. Allow only the resources your site requires, then test page functionality and browser reports before enforcing a policy. The tool does not fetch or scan your site.

Checks are not an assurance of security

The notes inspect selected patterns, including broad script schemes, unsafe evaluation, source fallback and missing restrictions. Their count is not a security percentage. A policy with no listed notes can still be unsuitable or vulnerable. The URL checker compares a limited set of explicit origins, paths and schemes. It reports unknown for cases needing the target origin or script context, including self, nonces and hashes. It does not reproduce the browser CSP algorithm.

Output formats and input limits

Outputs include raw and report-only headers, HTML meta, Nginx, Apache, an Express header middleware snippet, a Cloudflare response-header snippet and a Next.js header-array example. Merge configuration snippets into your existing application; they are not complete deployment files. Express output includes the same global flags and reporting endpoint as the raw policy.

Custom entries accept one token, up to8,000characters, and reject whitespace, separators and configuration-sensitive characters. This protects the output boundary; it is not full CSP grammar validation. The reporting endpoint must be an HTTP(S) URL or relative path without credentials. Invalid entries clear the export until corrected.

Delivery and nonce limitations

Meta output omits frame-ancestors, report-uri and sandbox. Report-only does not enforce blocking. Consult the W3C CSP specification for delivery and directive behavior. A generated nonce is a sample: the server must create a fresh unpredictable nonce for each response and put the same value in the policy and intended script attributes. Do not paste one fixed nonce into a production policy.

The hash helper computes SHA-256 over the exact input text encoded as UTF-8. Whitespace changes the hash. Browser checks, redirects, resource types and server integration can affect the actual result. Processing is local, but loading the site still involves network requests.

Hash the exact inline script

The SHA-256 helper hashes the exact UTF-8 text, including whitespace, with a 200000-character limit. Empty text has a valid hash. Changing the input clears the previous result; recalculate before adding it to the policy. Browser cryptographic API failures are shown without retaining an old hash.

Frequently asked questions

Does the note count measure site security?

No. These are limited checks, not a security score or browser test.

Can I reuse the generated nonce permanently?

No. Generate a fresh unpredictable nonce for each response.

Does the URL checker prove a resource will load?

No. It is a limited source comparison and reports unknown when context is missing.