How do I build a Content Security Policy header online?
Configure 17 CSP directives (default-src, script-src, style-src, img-src, and more) using visual controls with source value options. Choose from framework presets for Next.js, React, WordPress, or API servers. See a real-time security analysis with a letter grade. Export as HTTP header, meta tag, or Nginx/Apache/Vercel/Netlify config. Everything runs in your browser.
default-src: 'self' script-src: 'self' style-src: 'self' 'unsafe-inline' img-src: 'self' data: connect-src: 'self' https://api.example.com
Content-Security-Policy:
default-src 'self';
script-src 'self';
style-src 'self' 'unsafe-inline';
img-src 'self' data:;
connect-src 'self'
https://api.example.com;CSP Header Builder
Build Content Security Policy headers visually with framework presets, security analysis, and multi-format output.
Directives
Fetch Directives
Document Directives
Navigation Directives
Output Format
Generated Policy
Content-Security-Policy: upgrade-insecure-requests
Security Analysis
Policy Stats
Tips & Best Practices
Start with Content-Security-Policy-Report-Only
A misconfigured CSP breaks your site — scripts stop loading, styles disappear, images fail. Deploy as Content-Security-Policy-Report-Only first to log violations without blocking. Monitor report-uri endpoints for a week, fix legitimate sources, then switch to enforcing mode.
'unsafe-inline' for scripts defeats the purpose of CSP
script-src 'self' 'unsafe-inline' allows any inline <script> tag, which is exactly what XSS attacks inject. Use nonces (script-src 'nonce-abc123') or hashes instead. Most frameworks (Next.js, Nuxt) support CSP nonces. 'unsafe-inline' for styles is less dangerous but still not ideal.
Build a CSP for Next.js with Google Analytics
Start with default-src 'self'; script-src 'self' 'nonce-{random}' https://www.googletagmanager.com; img-src 'self' https://www.google-analytics.com; connect-src 'self' https://www.google-analytics.com. Next.js 14+ supports nonce-based CSP via middleware. Test with Report-Only first.
frame-ancestors replaces X-Frame-Options for clickjacking protection
frame-ancestors 'none' (equivalent to X-Frame-Options: DENY) prevents your site from being embedded in iframes on other domains. Unlike X-Frame-Options, CSP frame-ancestors supports multiple domains and is the modern standard. Set both for backward compatibility with older browsers.
Frequently Asked Questions
What is a Content Security Policy (CSP) and why do I need one?
How do I create a Content Security Policy header?
What does 'unsafe-inline' mean in CSP and should I avoid it?
Related Generate Tools
Box Shadow Generator
Design CSS box shadows visually with multiple layers, presets, and live preview
Flexbox Generator
Build CSS flexbox layouts visually with live preview, item config, and presets
Grid Generator
Build CSS grid layouts visually with columns, rows, gap, item placement, and presets
Border Radius Generator
Design CSS border-radius visually with per-corner controls, unit selection, and presets