Content Security Policy (CSP) Header Generator
CSP DIRECTIVES CONFIGURATION
Content Security Policy (CSP) Implementation Guide
Content Security Policy is an essential defense-in-depth HTTP header that guards against Cross-Site Scripting (XSS), data injection, and iframe clickjacking attacks.
Recommended CSP Directives
default-src 'self'— Restricts default fallback resources to same origin.script-src— Specifies trusted JavaScript sources.style-src— Controls stylesheet and font loading.frame-ancestors 'none'— Prevents iframe embedding and clickjacking.upgrade-insecure-requests— Instructs browsers to automatically upgrade HTTP requests to HTTPS.
Related Security Tools
Generate HSTS headers with our HSTS Header Generator, block clickjacking with the X-Frame-Options Generator, or test JWTs using the JWT Inspector.
Frequently Asked Questions
Common questions about this tool.
What is a Content Security Policy (CSP) header? ▼
A Content Security Policy (`Content-Security-Policy`) HTTP header restricts the sources from which scripts, styles, images, and frames can be loaded, shielding web apps from Cross-Site Scripting (XSS).
What does `default-src 'self'` mean in CSP? ▼
`default-src 'self'` serves as a fallback directive that restricts all un-specified resource types (scripts, fonts, images) to load only from the exact same origin domain.
How do nonces and hashes work in script-src directives? ▼
Nonces (`'nonce-rAnd0m'`) and SHA-256 hashes (`'sha256-...'`) allow specific inline scripts to execute while blocking unauthorized injected scripts.
What is the difference between Content-Security-Policy and Report-Only? ▼
`Content-Security-Policy-Report-Only` monitors and logs policy violations to a reporting endpoint without blocking resource loads, allowing safe staging testing.
How do I deploy CSP headers in Nginx or Cloudflare? ▼
Copy the generated `add_header Content-Security-Policy "..."` directive and paste it into your server block or Cloudflare Transform Rules.
Related Free Utilities
View all tools →ChatGPT Ad Blocker
Block ChatGPT upgrade banners, upsell promo cards, and partner app ads with a lightweight, privacy-first Manifest V3 Chrome extension.
JSON diff
JSON diff. Use this privacy-first json diff directly in your browser.
Base64 encoder
Base64 encoder. Use this privacy-first base64 encoder directly in your browser.
URL parser
URL parser. Use this privacy-first url parser directly in your browser.