Skip to content
Free tool · Security

CSP Header Generator

Build a Content-Security-Policy directive by directive, start from a tested preset or paste an existing policy, and get it ready to deploy for Apache, Nginx, Next.js or as a meta tag — with warnings about unsafe-inline, wildcards and missing protections.

Runs in your browser — nothing is uploadedNo sign-up · no tracking of your input

Start from

Presets
Paste an existing CSP

Directives

  • Reporting

Generated policy

Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests
10 directives · 226 characters

Checks · 0 issues

No obvious weaknesses found. Test the policy in Report-Only mode before enforcing it.

How to use the CSP Header Generator

  1. 1

    Choose a starting point

    Pick a preset (strict nonce-based, static site, SPA with API), add Google Fonts, or paste the policy you already have to load it into the editor.

  2. 2

    Adjust the directives

    Enable directives such as script-src or connect-src, tick keywords like 'self' or 'none' and add the hosts your site really loads from.

  3. 3

    Copy and roll out

    Choose the output format, fix the warnings and deploy the policy in Report-Only mode first. Enforce it once no unexpected violations are reported.

FAQ

CSP Header Generator: frequently asked questions

What is a Content-Security-Policy?

A Content-Security-Policy (CSP) is an HTTP response header that tells the browser which sources of scripts, styles, images and other resources a page may use. A strict CSP is one of the most effective defences against cross-site scripting (XSS).

Why is 'unsafe-inline' dangerous in script-src?

'unsafe-inline' allows every inline script and event handler, which is exactly what most XSS attacks inject. Use a random nonce per response or a hash of each inline script instead; with a nonce or hash present, modern browsers ignore 'unsafe-inline'.

Should I use the header or a meta tag?

Prefer the HTTP header. A meta tag cannot use frame-ancestors, report-uri, report-to or sandbox, cannot be Report-Only and only applies to content after the tag. Use the meta tag only when you cannot change server headers, for example on static hosting.

How do I test a CSP without breaking my site?

Send the policy as Content-Security-Policy-Report-Only first. Browsers report violations in the console and to your report-uri or report-to endpoint but block nothing. Fix the violations, then switch to the enforcing header.

What is a minimal secure CSP?

A good baseline is default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'. For the best XSS protection add script-src with a nonce and 'strict-dynamic'.