OneFirewall Alliance

CSP Header Generator

Build a Content Security Policy header interactively — configure directives, get server config snippets

Pick the sources you allow for scripts, styles, images, frames and other resource types, and the generator assembles a valid Content-Security-Policy header. It also outputs configuration snippets you can paste into common web servers. More free security tools.

Presets
Strict (No Inline)
Moderate (Common CDNs)
Single Page App
API Only
Clear All
Configure Directives
Generated CSP
Configure directives above…
Nginx
Apache
HTML Meta
How It Works & Why It Matters

A Content-Security-Policy header is only as good as its weakest directive — a single script-src 'unsafe-inline' or a wildcard host can undo the protection the rest of the policy provides against XSS and data injection. Building one by hand means tracking which directive governs which resource type (script-src, style-src, img-src, frame-src, connect-src and more) and getting the source-list syntax exactly right.

This generator lets you pick allowed sources per resource type and assembles a syntactically valid header, along with ready-to-paste configuration snippets for common web servers. Start as restrictive as your application allows — default-src 'self' plus explicit exceptions — rather than adding broad allowances and trying to narrow them later.

Need help implementing and monitoring CSP for your web applications?

If you like this tool, Speak with OneFirewall

What the CSP Header Generator does

A Content Security Policy (CSP) tells the browser which sources of scripts, styles, images and frames your page may load. A well-tuned policy is one of the strongest defences against cross-site scripting (XSS) and data injection.

Writing CSP by hand is error-prone. The generator builds a valid header from your choices and outputs snippets for Nginx, Apache or an HTML meta tag.

How to use it

  1. Choose your sources. For each directive, such as script-src, style-src, img-src and frame-src, pick the sources your site actually uses.
  2. Review the policy. Check the assembled Content-Security-Policy header. Avoid 'unsafe-inline' and 'unsafe-eval' where you can.
  3. Deploy it. Copy the Nginx, Apache or HTML meta snippet into your configuration. Consider testing first with Content-Security-Policy-Report-Only.

Frequently asked questions

What is the safest way to roll out a CSP?

Start with the Content-Security-Policy-Report-Only header so violations are reported but nothing is blocked, fix what breaks, then switch to the enforcing header.

Why avoid 'unsafe-inline'?

It allows any inline script to run, which removes most of CSP's protection against XSS. Nonces or hashes let specific inline scripts run safely.

Can I set CSP in a meta tag?

Yes, for most directives. Some, such as frame-ancestors and report-uri, only work when sent as an HTTP header.

More free tools: OneFirewall Free Tools · Terms explained: Glossary