Free CSP Header Generator

Create Content Security Policy headers for your website. Free, fast, and works entirely in your browser with no sign-up required.

Updated

Share:
Home/Security Tools/CSP Generator

CSP Generator

Build Content Security Policy headers interactively with presets, directive builder, nonce support, and strictness scoring.

CSP Builder

Strictness Score
70/100
Nonce:Not generated

Directives

default-src
L1

Fallback for other fetch directives

'self'
script-src
L1

Valid sources for JavaScript

'self'
style-src
L1

Valid sources for stylesheets

'self'
'unsafe-inline'
img-src
L1

Valid sources for images

'self'
data:
font-src
L1

Valid sources for fonts

'self'
connect-src
L1

Valid targets for fetch, XHR, WebSocket

'self'
object-src
L1

Valid sources for plugins (Flash, etc.)

'none'
frame-ancestors
L2

Valid parents that can embed this page

'none'

Frequently Asked Questions

What is the CSP Generator?

The CSP Generator is a free online tool that creates Content Security Policy headers to protect your website against XSS, clickjacking, and other injection attacks.

Is the CSP Generator free?

Yes, it is completely free with no registration required. All policy generation happens client-side in your browser.

Why do I need a Content Security Policy?

A CSP tells browsers which content sources are trusted, blocking malicious scripts and reducing the risk of cross-site scripting (XSS) attacks on your website.

Is my data safe with this tool?

Absolutely. The CSP Header Generator processes everything client-side in your browser. No data is uploaded to or stored on any server. Your content remains private on your device at all times.

Does the CSP Header Generator work on mobile devices?

Yes, the CSP Header Generator is fully responsive and works on smartphones and tablets. You can use it on any device with a modern web browser -- no app download required.

Do I need to create an account to use this tool?

No account or registration is needed. Simply open the CSP Header Generator in your browser and start using it immediately. There are no sign-up walls or usage restrictions.

How do I use the CSP Header Generator?

Simply enter your input in the provided field, adjust any settings to your preference, and the tool will process it instantly. You can then copy the result to your clipboard or download it.

Which browsers are supported?

The CSP Header Generator works in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. For the best experience, use the latest version of your preferred browser.

What is the difference between 'self', 'none', and 'unsafe-inline' in a CSP?

These are CSP source keywords that tell the browser which content a directive permits. 'self' allows resources only from your own origin (same scheme, host, and port), so a script-src of 'self' loads your own scripts but blocks third-party ones. 'none' is the strictest value: it blocks every source for that directive, which is why object-src 'none' is a common hardening step. 'unsafe-inline' re-enables inline scripts and styles written directly in your HTML, and 'unsafe-eval' permits eval()-based code; both are convenient but reopen the exact XSS hole CSP exists to close, so use a nonce or hash instead where possible. This generator lets you click these keywords directly onto each directive and shows how every choice moves your strictness score, so you can see the security trade-off as you build.

Why does my Content Security Policy not work in an HTML meta tag?

Some directives are simply ignored when a CSP is delivered through an HTML meta tag instead of a real HTTP response header. The frame-ancestors directive, which prevents clickjacking by controlling who can embed your page, only works as a header because the framing decision happens before the document parses the meta tag. The report-uri directive for collecting violation reports and the sandbox directive are ignored in meta form for the same reason. So if your anti-clickjacking or reporting rules seem to do nothing, that is usually why. Wherever you control your server configuration, prefer the HTTP header. This tool flags exactly this limitation in its Output view and gives you the raw Content-Security-Policy header alongside ready-to-paste Nginx, Apache, Express.js, and Next.js config blocks so you can deploy it the correct way.

How do I use a CSP nonce to allow a specific inline script safely?

A nonce is a random, single-use token that lets you trust one specific inline script without opening the door with 'unsafe-inline'. You add the value 'nonce-{random}' to your script-src directive, then put the matching nonce attribute on the script tag you want to allow, like <script nonce="{random}">. The browser runs only inline scripts carrying that exact token and blocks every other injected one, so an attacker who cannot guess the value cannot execute their payload. The critical rule is that the nonce must be freshly generated on every page load, never hard-coded or reused. This generator creates a cryptographically strong nonce with the browser's crypto.getRandomValues() API and gives you the formatted 'nonce-...' string to copy into both your policy and your script tags.

What is the difference between report-only mode and enforcing a CSP?

A too-strict policy silently blocks legitimate scripts, styles, or API calls, so shipping CSP straight to enforcement is risky. Report-only mode solves this. By sending the policy under the Content-Security-Policy-Report-Only header instead of Content-Security-Policy, the browser does not block anything; it only logs each violation it would have caused, sending the details to your report-uri endpoint. This lets you watch real traffic, discover which resources trip the policy, and fix the rules before any user sees a broken page. The standard safe rollout is to deploy in report-only first, monitor until the reports go quiet, then switch to the enforcing header. Use this tool's builder to assemble and tune the policy and its Test view to check specific URLs against your directives before you commit to enforcement.

Which CSP preset should I start from for WordPress or a single-page app?

Picking a sensible baseline is faster and safer than building from scratch, and the right starting point depends on your stack. The WordPress preset is more permissive because themes and plugins frequently inject inline scripts and styles, so it allows 'unsafe-inline' and common embed sources like YouTube and Vimeo to avoid breaking the dashboard and front end. The SPA preset suits React, Vue, or Angular builds: it keeps script-src tight at 'self', adds worker-src for blob workers, and opens connect-src for your API and WebSocket endpoints. There are also Strict, Moderate, and Relaxed presets covering the full lockdown-to-lenient range. Apply the closest preset in this tool, then trim or extend individual directives for your real third-party domains while the live strictness score guides you toward a harder policy.

About the CSP Header Generator

The CSP Header Generator is a free tool for building a Content Security Policy — the HTTP response header that tells a browser which sources of scripts, styles, images, fonts, and other resources it is allowed to load on your page. A well-tuned policy is one of the strongest defences against cross-site scripting (XSS), since it stops the browser from running injected or third-party scripts that you never approved. The tool is built for web developers, site owners, and security engineers who want a correct policy without memorising the syntax.

Everything happens in your browser. There is no sign-up, no upload, and nothing is sent to a server — you assemble the policy on your own device and copy the result out. That client-side design also means the tool works the moment the page loads.

Build a policy directive by directive

You construct a policy from individual directives, each controlling one type of resource. The builder supports 15 directives across CSP Levels 1 to 3, including default-src, script-src, style-src, img-src, font-src, connect-src, frame-ancestors, base-uri, form-action, and newer additions like worker-src and manifest-src. For each directive you add source values — either by clicking common suggestions such as 'self', 'none', data:, or https:, or by typing a custom origin. If you would rather start from a known-good baseline, five presets are one click away: Strict, Moderate, Relaxed, WordPress, and SPA.

To safely allow specific inline scripts, the tool also generates a cryptographic nonce using the browser's crypto.getRandomValues() API, ready to drop into both your policy and your <script> tags.

Read the strictness score as you go

A live strictness score out of 100 reflects how locked-down your policy is. It rewards the choices that matter most: a restrictive default-src, a script-src free of 'unsafe-inline' and 'unsafe-eval', object-src 'none', a defined frame-ancestors, and a report-uri for collecting violation reports. Those keywords are worth understanding:

  • 'self' allows resources only from your own origin.
  • 'none' blocks every source for that directive.
  • 'unsafe-inline' and 'unsafe-eval' re-open the door to inline and eval()-based code — convenient, but they weaken the protection CSP is meant to provide.
  • 'strict-dynamic', nonces, and hashes are the modern, safer way to trust specific scripts.

The score is a quick gut-check, not a guarantee, so still test your policy against real pages before enforcing it.

Copy the output in the format you deploy

Once the policy reads the way you want, the Output view gives you ready-to-paste snippets: the raw Content-Security-Policy: HTTP header, an HTML <meta> tag, and server config blocks for Nginx, Apache, Express.js, and Next.js. One reminder the tool surfaces: a few directives — frame-ancestors, report-uri, and sandbox — only work as a real HTTP header and are ignored inside a meta tag, so prefer the header wherever you control server configuration.

Test before you enforce

CSP failures are easy to ship because a too-tight policy silently blocks legitimate resources. The Test view lets you paste a URL — say a CDN script or analytics endpoint — and see, directive by directive, whether your current policy would allow or block it. A set of common violation examples shows the typical culprits, from inline scripts and inline styles to clickjacking attempts caught by frame-ancestors, each paired with the fix. A safe rollout pattern is to deploy in report-only mode first, watch what trips, then switch to enforcement once the reports are quiet.

Build your policy above, watch the strictness score climb, and copy it in the format that matches your stack.