About CSP Generator and Checker
A Content-Security-Policy tells browsers where a page may load scripts, styles, images and frames from, which limits the damage of an injected script. Writing one by hand is error-prone: one stray keyword can switch the protection off.
Build a policy by ticking what your site needs and copy it as a header, a meta tag, or an nginx or Apache line. Or paste a policy you already send and get each problem ranked by severity: unsafe-inline without a nonce, wildcard sources, missing object-src or base-uri, misspelled directives and more.
How it works
- The builder writes one directive per kind of resource you allow, in a conventional order, and adds object-src, base-uri, form-action and frame-ancestors as you choose.
- The checker splits a policy into directives and their sources, the way a browser does: names are not case-sensitive, a repeated directive counts only the first time, and keywords need single quotes.
- Script sources are judged as a browser would apply them: with a nonce or hash, unsafe-inline is ignored, and with strict-dynamic, host lists are ignored too. Directives fall back to default-src where browsers do.
- Findings are ranked high, medium, low or note. The checks are based on how CSP is specified and on well-known bypasses, not on a live scan of your site.
Questions
Should I use a nonce or a list of hosts?
A nonce with 'strict-dynamic' is the stronger choice: allow-lists of hosts are often bypassed through scripts those hosts serve. It needs your server to generate a new nonce for every response, so a static site may have to use 'self' and hosts instead.
Header or meta tag?
Use the header where you can. A meta tag cannot set frame-ancestors, report-uri or sandbox, and only applies from the point it appears in the page. The tool leaves those directives out of the meta version for you.
Will a policy with no findings keep my site safe?
It means none of the known problems was found in the policy text. It cannot tell whether your pages work under it, so roll it out as Content-Security-Policy-Report-Only first and watch the reports.
Does the checker fetch my site?
No. It reads only the policy you paste, entirely in your browser. Copy the header from your browser’s developer tools or from your server configuration.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.