Developer tool

CSP Header Generator

Generate a Content-Security-Policy header from practical resource controls.

Runs in your browser
CSP Header Generatorworks locally
Result

Test in Content-Security-Policy-Report-Only first. Frameworks, analytics, payments, embeds, workers, and inline scripts may require narrower additional sources or nonces.

How to use this csp header generator

  1. Choose a policy preset, add the origins your site loads resources from, and review every directive before using the header.
  2. Review the generated options. Check syntax, escaping, and edge cases against the source before using the result in a live project.
  3. Check the output against the source, then copy or download the finished result.

About this csp header generator

The CSP Header Generator lets you generate a Content-Security-Policy header from practical resource controls. The controls cover only the inputs needed for the result.

You can also use it to change the controls to produce a different result.

Example

Start with a self-only policy, then add the exact CDN or font origins the page needs rather than allowing every source.

Common uses

  • generate a Content-Security-Policy header from practical resource controls
  • change the controls to produce a different result
  • copy a useful result into the project it belongs to