Content Security Policy (CSP) Generator / Builder
Build a Content Security Policy header interactively, directive by directive.
About CSP Builder
Builds a Content Security Policy header interactively — selecting which sources are allowed to load scripts, styles, images, fonts, and other resource types for a page, and assembling the correct directive syntax. CSP is one of the most effective defenses against XSS, but also one of the easiest headers to get wrong by hand, since a single missing directive or an overly permissive wildcard can either break legitimate page functionality or quietly defeat the protection. Testing a new policy in Content-Security-Policy-Report-Only mode before enforcing it catches what would have broken without breaking it in production first.
Adding 'unsafe-inline' or 'unsafe-eval' to get a broken page working again defeats most of what CSP protects against — if a policy needs either to function, the page's own inline scripts or styles are the actual thing to fix.
Quick presets
Related Tools
A practical starting policy
For a site that loads everything from its own domain, this is a strict and workable baseline:
default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'
Add third-party sources (analytics, CDNs, fonts) only to the directive that needs them.
The directives that matter most
| Directive | Why |
|---|---|
default-src | Fallback for every fetch directive you don't set. |
script-src | The main defense against XSS. Avoid 'unsafe-inline'; use nonces or hashes for inline scripts you need. |
object-src 'none' | Blocks legacy plugin content. |
base-uri | Stops an injected <base> tag from redirecting relative URLs. |
frame-ancestors | Controls who may frame the page (clickjacking). The modern replacement for X-Frame-Options. |
form-action | Limits where forms may submit. |
Roll it out without breaking the site
- Send the policy as
Content-Security-Policy-Report-Only. Browsers report violations but block nothing. - Open every important page and check the browser console for violations.
- Add the missing sources, or move inline code into files. For inline scripts that must stay, use a per-response
'nonce-…'value. - Rename the header to
Content-Security-Policyto enforce it.
Header or meta tag
A <meta http-equiv="Content-Security-Policy"> tag works for most directives, but frame-ancestors, report-uri and sandbox are ignored there. Prefer the HTTP header. Check what a site actually sends with the security headers checker.