CSP Generator

Build a Content-Security-Policy header from directive pickers — protect your site from XSS and injection.

100% FreeNo sign-upPrivate — runs in your browser

Test in Report-Only mode first — a strict policy can break inline scripts, styles and third-party embeds.

Copied to clipboard

How to use this tool

1
Pick a preset or go custom

Strict blocks objects and framing; basic allows images from https: and data:.

2
Edit the directives

Sources are space-separated; use 'self', 'none', data:, https: or a host as needed.

3
Consider Report-Only first

Tick Report-Only to test the policy without breaking the site.

4
Copy the header

Add it to your server config or meta tag and watch the console for violations.

Formula & worked example

Each directive is name followed by space-separated sources, joined with '; '. Report-Only mode changes the header name to Content-Security-Policy-Report-Only; upgrade-insecure-requests and report-uri are appended when set.

default-src 'self', script-src 'self', img-src 'self' data: gives header Content-Security-Policy: default-src 'self'; script-src 'self'; img-src 'self' data:.

Limitations — read this before you rely on it

This generates the header value only — it does not set it on your server, and it does not scan your site for blocked resources. 'unsafe-inline' and 'unsafe-eval' are never added by presets; add them by hand only if you understand the risk, and prefer nonces or hashes for inline scripts.

Frequently asked questions

Content Security Policy: an HTTP header that tells the browser which sources may load scripts, styles, images and other resources, limiting XSS and injection damage.

Report-Only logs violations without blocking, so you can find what a policy would break before enforcing it.

A policy without 'unsafe-inline' (or a matching nonce/hash) blocks inline scripts and event handlers. Move scripts to files or add nonces.

No. It generates the header text; you add it in your server, CDN or hosting config.

For a simple site, often yes. Third-party analytics, fonts, embeds and payment scripts each need their hosts added explicitly.