What Is a CSP Header Builder?
A CSP header builder creates Content Security Policy headers through an interactive interface. CSP is one of the most important web security headers — it tells browsers exactly which content sources are trusted, blocking all others. But writing CSP directives by hand is notoriously error-prone, with a strict syntax and dozens of directives to configure.
This tool walks you through each directive, explains what it controls, and generates a valid CSP header string. It helps you build a policy that protects against XSS and injection attacks without accidentally blocking the scripts, styles, and resources your site needs to function.
How to Use This Tool
- Set your default source — Choose the fallback policy for all resource types. Most sites start with 'self' to allow only same-origin content by default.
- Configure each directive — Add allowed sources for scripts, styles, images, fonts, frames, and API connections. The tool explains each directive and provides common examples like CDN domains and analytics services.
- Enable reporting — Set a report-uri endpoint to receive CSP violation reports. Start with Report-Only mode to test your policy without breaking anything.
- Copy the header — The tool outputs the complete Content-Security-Policy header value along with server-specific implementation snippets for Apache (generate rules with our .htaccess Generator), Nginx, and common frameworks.
Worked example: the default policy, tested in Chromium
The tool starts with default-src 'self'; upgrade-insecure-requests. On October 12, 2026 we served a test page with that header in Chromium, then delivered the same policy through the tool's <meta> output.
| What the page tried | Result |
|---|---|
| Inline <script> | Blocked (no 'unsafe-inline', as intended) |
| Script file from its own origin | Runs |
| <base href="https://evil.test/"> | Allowed: every relative URL on the page now points at evil.test |
| frame-ancestors 'none' and report-uri in the <meta> version | Ignored, with a console warning for each |
- default-src does not cover everything. CSP3 lists base-uri, form-action, frame-ancestors (and sandbox, report-uri) as directives with no fallback. Our test page's base element was hijacked under the default policy. Add at least
base-uri 'self'; form-action 'self'; frame-ancestors 'self'(or 'none'), andobject-src 'none'. - Use the header, not <meta>, when you can. frame-ancestors, report-uri and sandbox only work as an HTTP header; in the <meta> output Chromium drops them. A <meta> policy also only applies to content after the tag.
- Report-Only means renaming the header yourself. The tool always writes Content-Security-Policy. To test without breaking the site, change it to Content-Security-Policy-Report-Only (header, nginx or Apache formats; Report-Only is not allowed in <meta>) and add a report-uri.
- Leave "block mixed content" off. block-all-mixed-content is deprecated (MDN); browsers now upgrade or block mixed content anyway, and upgrade-insecure-requests (on by default) covers the rest.
- Be careful with the CDN shortcuts. The chips add whole hosts such as cdn.jsdelivr.net and unpkg.com, which serve any npm package, so an attacker who can inject a script tag can load a library from there. Google's 2016 study found most host-allowlist policies bypassable this way; nonces or hashes with 'strict-dynamic' are the stronger pattern for scripts.
- Formats: HTTP header line, <meta> tag, nginx add_header … always, and Apache Header set; for Netlify or Vercel, copy the header line without its "Content-Security-Policy:" name into their headers file.
Sources
Checked on .
Frequently Asked Questions
📖 Learn More
Related Article HTTP Status Codes Guide → Related Article How to Write JSON-LD Schema →Built by Derek Giordano · Part of Ultimate Design Tools