or style attributes). This defeats the main protection of CSP because XSS injected as inline scripts would execute. For scripts, use nonces (script-src 'nonce-{random}') or hashes (script-src 'sha256-{hash}') instead. For styles, consider moving inline styles to external files."}},{"@type":"Question","name":"What is the difference between frame-src and frame-ancestors?","acceptedAnswer":{"@type":"Answer","text":"frame-src controls which sources your page can load in iframes. frame-ancestors controls which external sites can embed your page in an iframe — it's a modern replacement for the X-Frame-Options header. To prevent clickjacking, set frame-ancestors 'none' (no embedding) or frame-ancestors 'self' (same origin only)."}},{"@type":"Question","name":"How do I deploy CSP without breaking my site?","acceptedAnswer":{"@type":"Answer","text":"Use Content-Security-Policy-Report-Only first — same header format, but violations are only reported (via report-uri) without blocking content. Set report-uri to a logging endpoint, check the violation reports, adjust your policy, then switch to Content-Security-Policy. Many services like Report URI, Sentry, and Datadog can receive CSP reports."}},{"@type":"Question","name":"What is upgrade-insecure-requests?","acceptedAnswer":{"@type":"Answer","text":"This directive tells browsers to automatically upgrade all HTTP requests to HTTPS before sending them. It's useful when migrating a site from HTTP to HTTPS — it fixes mixed content issues without manually updating every resource URL. It does NOT affect the page URL itself, only sub-resource requests (images, scripts, styles, etc.)."}}]} Skip to main content

CSP Header Builder

Build a Content Security Policy header visually. Toggle directives, set allowed sources per directive, and get a ready-to-use CSP string with nginx and Apache config snippets. CSP is the most effective defense against XSS attacks.

✓ 13 CSP directives ✓ nginx + Apache snippets ✓ report-uri support ✓ Runs 100% in your browser

Frequently Asked Questions

What is a Content Security Policy (CSP)?▼

CSP is an HTTP response header that tells browsers which sources of content (scripts, styles, images, fonts) are allowed to load on a page. It's one of the most effective defenses against Cross-Site Scripting (XSS) and data injection attacks. By whitelisting trusted sources, you prevent injected malicious scripts from executing.

What does default-src do?▼

default-src is the fallback directive — it applies to any fetch directive that isn't explicitly set. If you set default-src 'self', then script-src, style-src, img-src, etc. all default to 'self' unless overridden. Always set default-src as a safe baseline before adding more permissive rules for specific directives.

Why is 'unsafe-inline' risky?▼

'unsafe-inline' allows inline scripts and styles (<script>...</script> or style attributes). This defeats the main protection of CSP because XSS injected as inline scripts would execute. For scripts, use nonces (script-src 'nonce-{random}') or hashes (script-src 'sha256-{hash}') instead. For styles, consider moving inline styles to external files.

What is the difference between frame-src and frame-ancestors?▼

frame-src controls which sources your page can load in iframes. frame-ancestors controls which external sites can embed your page in an iframe — it's a modern replacement for the X-Frame-Options header. To prevent clickjacking, set frame-ancestors 'none' (no embedding) or frame-ancestors 'self' (same origin only).

How do I deploy CSP without breaking my site?▼

Use Content-Security-Policy-Report-Only first — same header format, but violations are only reported (via report-uri) without blocking content. Set report-uri to a logging endpoint, check the violation reports, adjust your policy, then switch to Content-Security-Policy. Many services like Report URI, Sentry, and Datadog can receive CSP reports.

What is upgrade-insecure-requests?▼

This directive tells browsers to automatically upgrade all HTTP requests to HTTPS before sending them. It's useful when migrating a site from HTTP to HTTPS — it fixes mixed content issues without manually updating every resource URL. It does NOT affect the page URL itself, only sub-resource requests (images, scripts, styles, etc.).

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →