Security · resource loading
Content security policy.
Assemble a readable CSP, inspect source expressions, and test a report-only draft before enforcement. Your policy text stays in this browser.
Generate a header
Generated header
The validator will flag unknown directives, malformed sources, and risky allowances.
Validate an existing policy
Paste only a policy you are authorized to inspect.Your validation result will appear here.
What this checks
- Known CSP directives, duplicates, required values, and no-value directives
- Keywords, HTTPS origins, scheme sources, nonces, hashes, and wildcard hosts
- Warnings for unsafe-inline, unsafe-eval, broad HTTP/data sources, and missing fallbacks
- Enforce vs report-only header naming
Nonce and hash guidance: a nonce must be unpredictable and freshly generated for each response; a hash must match the exact inline content. This page only recognises their shape and never fabricates a security token or proves deployment safety.
MDN CSP header reference · MDN CSP deployment guide · W3C CSP Level 3
Worked example: build a report-only header, then validate a risky one
Choose report only and set default-src 'self' and img-src 'self' data:. The generator joins the directives with semicolons and picks the matching header name.
| Step | Input | Output |
|---|---|---|
| Generate (report only) | default-src 'self'; img-src 'self' data: | Content-Security-Policy-Report-Only: default-src 'self'; img-src 'self' data: |
| Validate | default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.example.com; img-src * | Valid, with one warning: script-src includes 'unsafe-inline'; prefer nonces or hashes for inline code |
Report-only mode logs violations without blocking, which is how you test a policy before you enforce it.
Next steps: Permissions-Policy generator, security headers analyzer, Cache-Control analyzer, or HTML validator.
Frequently asked questions
What is the difference between Content-Security-Policy and Report-Only?
The enforcing header blocks violations. The Report-Only policy records violations without enforcing that policy. An enforcing policy or other browser controls can still block content.
Why is unsafe-inline flagged?
Without an effective nonce or hash policy, it permits inline scripts and weakens protection against injected scripts. Nonces or hashes allow specific inline scripts instead.
Can I paste a policy from my live site?
Yes, as long as you are allowed to inspect it. The validator reads the text only and does not fetch your site.
Is a clean result a security audit?
No. It checks the header syntax and some risky patterns, not your application.