CSP Policy Builder
Build your Content-Security-Policy header directive by directive. Each setting shows an explanation of what it does and the security trade-off.
Preset
Directives
Security Score
—Header
Frequently Asked Questions
What is Content-Security-Policy?▼
CSP is an HTTP response header that tells browsers which sources are allowed to load scripts, styles, images, fonts, and other resources. A well-configured CSP is one of the most effective defenses against XSS attacks — even if an attacker injects a script tag, the browser won't execute it unless the source is allowlisted.
What is default-src?▼
default-src is the fallback for all resource fetch directives (script-src, style-src, img-src, etc.). Any directive you don't explicitly set falls back to default-src. Always set a restrictive default-src ('self' or 'none') and only loosen specific directives you need.
Why is 'unsafe-inline' dangerous?▼
'unsafe-inline' allows inline <script> and <style> blocks. This defeats XSS protection because injected inline scripts execute freely. Use nonces (a random per-request value in script-src 'nonce-{value}') or hashes (sha256-{hash}) instead. For styles, move inline styles to external .css files.
What is report-uri / report-to?▼
report-uri (legacy) and report-to (modern) tell the browser where to POST violation reports when a resource is blocked by CSP. Use Content-Security-Policy-Report-Only header with report-to while auditing — no resources are blocked, only violations reported. Then switch to Content-Security-Policy when confident.
How do I test CSP without breaking my site?▼
Use the Content-Security-Policy-Report-Only header first. Set report-to to a service like report-uri.com or your own endpoint. Monitor violations for 1-2 weeks. Iterate until violations stop, then switch to enforcing CSP. The Report-Only header never blocks anything — safe to test in production.
Related Products
on GumroadDevPlaybook Interview Vault
210+ real technical interview questions with model answers, asked at Google, Meta, Amazon, Microsoft, Stripe, and Shopify. Covers Frontend (55), Backend (55), System Design (50), and DSA (50). Available in English and Traditional Chinese.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Interview Vault
210 technical interview questions with model answers, key points, and follow-up questions. Covers Frontend, Backend, System Design, and DSA — bilingual English + Traditional Chinese (ZH-TW). PWYW from $29.
Buy on Gumroad →You Might Also Need
Webhook Tester
Generate realistic webhook test payloads for GitHub, Stripe, Slack, and custom services. Get a curl command to send the payload to your local endpoint. Inspect headers, payload size, and content-type.
Open free tool →
WebSocket Tester
Connect to any WebSocket server, send and receive messages in real time, and inspect the message log with timestamps and byte sizes. Free online WebSocket client.
Open free tool →
WebP Converter
Convert PNG, JPG, or GIF images to WebP format in your browser. Drag-and-drop upload, quality slider, before/after file size comparison. No files sent to any server.
Open free tool →
More Free Tools
Related Articles
WebAssembly (WASM) for Web Developers: A Practical Guide (2026)
Learn WebAssembly (WASM) from scratch — what it is, when to use it, how to compile Rust and C++ to WASM, real-world use cases, and tools every web developer needs to know.
Base64 Encoding Explained: When to Use It and When to Avoid It
Base64 encoding explained: when to use it in APIs, image data URIs, and auth tokens. Real-world examples and common pitfalls for web developers.
HTML Encoder Decoder Online: Escape & Unescape HTML Entities Free
Encode and decode HTML entities online for free. Learn when to escape HTML, which characters must be encoded, and how to prevent XSS vulnerabilities using an HTML encoder decoder.
HTML Entity Encoder/Decoder: Complete Guide for Web Developers
Master HTML entity encoding and decoding: when to use it, XSS prevention, and code examples in JavaScript, Python, and Node.js with a free online tool.
URL Encoding 101: encodeURIComponent vs encodeURI vs rawuriencode
The complete guide to URL encoding in JavaScript and Python. Covers when to use encodeURIComponent, encodeURI, and how to handle special characters correctly.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →