Code · Made a little simpler

Content Security Policy Builder

Build and validate a Content Security Policy header from source allowlists. Start with a same-origin policy, review notices and export the header locally.

Free to useNo account neededProcessed on your device
Your workspaceProcessed on your device

Separate sources with spaces. Use 'self', 'none', HTTPS hosts or directive-specific sources such as a script hash. Blank fields are omitted.

Inputs and output stay on this device.

Add this tool to your website

Paste this code into your page to add the tool and a visible ToolMellow credit link.

HTML embed code
Preview embed

Content Security Policy Builder: how to use it

  1. Review the same-origin starter and select Enforce or Report only. Enter source lists for the resources your page actually uses.
  2. Select Build CSP header. Correct invalid sources and review notices for broad host patterns or omitted restrictions.
  3. Copy or download the HTTP response header. Test it on a staging page and review expected resources and browser violations.

Limits and notes

Creates one header up to 4,096 ASCII characters. Supports common resource, base, frame and form directives, HTTPS hosts, WSS connections, selected data and blob sources, SHA-256/384/512 sources for scripts and styles and optional HTTPS upgrades. Report-only output has no configured reporting endpoint. The builder does not load any listed source.

How your privacy works →

Content Security Policy Builder: common questions

What happens if a directive is blank?

The directive is omitted. Fetch directives can fall back to other directives such as default-src. frame-ancestors, form-action and base-uri have separate behavior.

What does report-only mode do?

Compatible browsers record CSP violations without blocking the load. The generated header does not send reports to an endpoint.

How do I allow a separate image host?

Add the host to img-src, with 'self' if the page also loads same-origin images. Test representative pages with the generated header.

Guides