Skip to content

CSP Header Generator

Embed

Paste this where you want CSP Header Generator on your site. Adjust the height to fit.

<iframe src="https://www.browserutils.dev/embed/csp-header-generator/" width="100%" height="500" frameborder="0" loading="lazy" title="CSP Header Generator"></iframe>
<p style="font-size:12px;margin:4px 0 0"><a href="https://www.browserutils.dev/tools/csp-header-generator/">CSP Header Generator</a> by BrowserUtils</p>

Generate Content Security Policy headers.Runs in this tab.

'self''none''unsafe-inline''unsafe-eval'data:blob:https:*
Content-Security-Policy: default-src 'self'
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">

Next step

About CSP Header Generator

Free online CSP header generator. Build Content-Security-Policy headers with a visual editor for web security. It runs in your browser. Nothing is sent to a server.

Questions

What is a Content Security Policy (CSP) header?
A CSP header is an HTTP response header that tells browsers which sources of content (scripts, styles, images, etc.) are allowed to load on your page. It is one of the most effective defenses against cross-site scripting (XSS) and data injection attacks.
How do I test a CSP header without breaking my site?
Use the Content-Security-Policy-Report-Only header first, which logs violations to a reporting endpoint without actually blocking anything. Once you have reviewed the reports and fixed any issues, switch to the enforcing Content-Security-Policy header.
What does the unsafe-inline directive mean in CSP?
The unsafe-inline directive allows inline scripts and styles to execute. This weakens CSP protection significantly because XSS attacks typically inject inline code. Use nonce-based or hash-based allowlisting instead whenever possible.
How do I add the generated CSP header to my server?
Copy the generated header string and add it to your server configuration. In Nginx use add_header, in Apache use Header set, and in Express.js use res.setHeader(). You can also set it via a meta tag in HTML, though the HTTP header approach is preferred.
Does the CSP header generator work offline?
Yes. The generator builds CSP header strings using client-side logic with no server calls, so it works without an internet connection once the page is loaded.

More in Security & Privacy

All 10 security & privacy