Content-Security-Policy Generator
Turn CSP Level 3 directives on or off, set their source lists, and copy a Content-Security-Policy header, a report-only header, or an HTML meta tag.
Input
Result
How to use CSP Generator
- Choose the directivesStart from a strict or balanced policy, then turn directives on and edit their source lists, such as 'self', https://cdn.example.com, or 'none'.
- Review the headerCheck the HTTP header, the HTML meta tag, and the Nginx or Apache snippet. Warnings flag unsafe script sources and directives that meta tags cannot carry.
- Copy or downloadCopy the header, the policy value, the report-only header, or the HTML, Nginx, or Apache form.
Limits and how it works
- You can include at most 40 directives, and the serialized policy can be at most 8,192 characters.
- This tool does not fetch your site, crawl scripts, or invent nonces or hashes for you.
- A generated policy is not a guarantee that a page is free of cross-site scripting. CSP is defense in depth, as the W3C specification states.
- Nginx and Apache snippets are templates. You still have to place them in the right server context and reload the server.
How this Content-Security-Policy header is built
Directives and source lists follow Content Security Policy Level 3 (W3C Working Draft, 27 October 2026): https://www.w3.org/TR/CSP3/. Keyword sources such as 'self', 'none', and 'unsafe-inline' must be written in single quotes. Host and scheme sources such as https://example.com and https: are unquoted. If 'none' is used, it must be the only source in that directive. Duplicate directive names are rejected.
Installability and deployment notes on MDN (https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy) explain fetch, document, navigation, and reporting directives, plus fallbacks such as default-src. This tool warns when default-src or script-src includes 'unsafe-inline', 'unsafe-eval', http:, or *. The HTML meta tag omits frame-ancestors, sandbox, report-uri, and report-to, which are not honored in meta http-equiv. report-uri is deprecated in favor of report-to.
This is not Security Headers Checker or HTTP Headers Checker, which inspect headers on a live URL or a pasted policy. It is also not Meta Tag Generator, which builds title, description, and social meta tags. This page only authors a CSP policy in your browser. It does not fetch or scan a website.
Frequently asked questions
Is this the same as Security Headers Checker?
No. Security Headers Checker grades the headers on a public URL, and it can also validate a pasted CSP. This page builds a Content-Security-Policy value from directives you choose. It never fetches a site.
Why is frame-ancestors missing from the HTML meta tag?
The HTML processing rules for meta http-equiv, cited in CSP Level 3, do not honor frame-ancestors, sandbox, or report-uri in a meta element. report-to is also omitted here because it depends on HTTP reporting headers. Put those directives in the Content-Security-Policy response header.
Should I start with the strict or balanced policy?
The strict policy is a tighter starting point: scripts and styles are limited to 'self', and plugins are blocked with object-src 'none'. The balanced policy adds 'unsafe-inline' so older pages that rely on inline script or style are less likely to break, but it weakens XSS protection. Prefer nonces or hashes instead of 'unsafe-inline' when you can.
Related tools
All toolsSecurity Headers Checker
Grade HSTS, CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy and Permissions-Policy.
HTTP Headers Checker
See the status code and response headers a public URL returns.
Meta Tag Generator
Build title, description, Open Graph and Twitter card tags.
.htaccess Redirect Generator
Generate Apache Redirect or RewriteRule lines for 301, 302, 307 and 308 redirects.