Content Security Policy Builder
Visually build CSP headers with preset templates, per-directive controls, validation warnings, strictness scoring, and report-only mode.
Updated
Content Security Policy Builder
Visually build Content Security Policy headers with preset templates, per-directive controls, validation warnings, and strictness scoring.
Preset Templates
Use Content-Security-Policy-Report-Only header (monitors violations without enforcing)
0 directives enabled
Directives
Frequently Asked Questions
What is CSP?
An HTTP header controlling which resources a browser can load, preventing XSS and data injection attacks.
Enforced vs report-only?
Enforced blocks violations. Report-only allows them but reports — useful for testing before enforcement.
Why avoid unsafe-inline/eval?
unsafe-inline allows exploitable inline scripts. unsafe-eval enables dynamic code execution. Both significantly weaken CSP protection.
Is the Content Security Policy Builder free to use?
Yes, the Content Security Policy Builder is 100% free with no registration, no hidden fees, and no usage limits. All processing happens locally in your browser, ensuring complete privacy.
Does the Content Security Policy Builder work on mobile devices?
Yes, the Content Security Policy Builder is fully responsive and works on smartphones and tablets. You can use it on any device with a modern web browser -- no app download required.
Do I need to create an account to use this tool?
No account or registration is needed. Simply open the Content Security Policy Builder in your browser and start using it immediately. There are no sign-up walls or usage restrictions.
How do I use the Content Security Policy Builder?
Simply enter your input in the provided field, adjust any settings to your preference, and the tool will process it instantly. You can then copy the result to your clipboard or download it.
Which browsers are supported?
The Content Security Policy Builder works in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. For the best experience, use the latest version of your preferred browser.
What is the difference between default-src and script-src in a CSP?
default-src is the fallback directive: it sets the allowed sources for any resource type you have not explicitly configured, so locking it to 'none' or 'self' creates a deny-by-default baseline. script-src is a specific override that controls only where JavaScript can load from, and it takes precedence over default-src for scripts. Because scripts are the main vector for cross-site scripting, you almost always want a tight script-src even if default-src is already restrictive — for example default-src 'self' with a separate script-src 'self' that adds a nonce. Other per-type directives like style-src, img-src, and connect-src work the same way, narrowing one resource type while default-src covers the rest. This builder lets you set default-src once and override individual directives only where needed.
How do I add a CSP header in Nginx or Apache?
On Nginx you add the policy inside a server or location block with add_header Content-Security-Policy "your policy here" always; the always flag ensures the header is sent even on error responses like 404s. On Apache you use Header set Content-Security-Policy "your policy here" inside the relevant VirtualHost or .htaccess, with mod_headers enabled. In both cases the value is the full directive string, and you reload the server for it to take effect. Getting the syntax exactly right by hand is error-prone, so this builder generates ready-made copy-paste snippets for Nginx, Apache, Express.js, and Next.js from whatever policy you configure. Build your directives visually, pick your server, and paste the generated block straight into your config.
Why can't I use frame-ancestors or report-uri in a meta tag CSP?
A CSP can be delivered two ways: as a Content-Security-Policy HTTP response header or as an HTML <meta http-equiv="Content-Security-Policy"> tag in the page head. The meta-tag method is convenient when you cannot edit server config, but the spec deliberately ignores certain directives in that context. frame-ancestors, report-uri, report-to, and sandbox only work when sent as a real HTTP header, because they must be known before the page renders or relate to response-level reporting. If clickjacking protection matters to you, frame-ancestors must come from the header, not the meta tag. This builder lets you switch between header and meta output formats and warns you which directives get dropped in meta mode, so you do not ship a policy that silently loses its anti-clickjacking protection.
How does the strictness score work and what makes a CSP score higher?
Each change recalculates a strictness score out of 100, graded Weak, Fair, Good, or Excellent. The score rewards genuinely protective choices rather than just the presence of a policy. You earn the most points for a restrictive default-src ('none' beats 'self'), a script-src with no unsafe-inline or unsafe-eval keywords, object-src 'none', and a defined frame-ancestors. Adding base-uri, form-action, a clean style-src, and other narrowing directives nudges the number up further, while wildcard sources and the unsafe keywords hold it down. Enabling report-only mode lowers the score slightly, since a report-only header offers no real blocking until you enforce it. The Analysis tab itemizes exactly what is driving your score, so you can see which weak spots to fix to move from Good to Excellent.
What is a nonce or hash in a CSP and when should I use one instead of unsafe-inline?
A nonce is a random token your server generates per page load and places both in the CSP and on each trusted <script> tag; the browser only runs scripts carrying the matching nonce. A hash works similarly but identifies a specific inline script by its sha256 fingerprint, with no per-request token needed. Both let you keep necessary inline scripts while removing 'unsafe-inline', which would otherwise allow any injected inline script to run and defeat your XSS protection. Pairing a nonce with 'strict-dynamic' also lets trusted scripts load their own dependencies without whitelisting every domain. This builder includes nonce and sha256 placeholder source values and recommends switching from unsafe-inline to a nonce- or hash-based approach. Configure script-src with a nonce placeholder here, then wire the real token in on your server.
Related Tools
Free Website Speed Test
Analyze website page load time, performance metrics, and optimization opportunities. Free, fast, and works entirely in your browser with no sign-up required.
Free Mobile Friendly Test
Check if your site is optimized for mobile devices. Free, fast, and works entirely in your browser with no sign-up required.
Free Meta Tag Extractor
Extract and review all meta tags from any webpage for SEO and social media analysis. Free, fast, and works entirely in your browser with no sign-up required.
Free Website Screenshot Tool
Capture full-page or viewport screenshots of any webpage for design review and testing. Free, fast, and works entirely in your browser with no sign-up required.
About the Content Security Policy Builder
The Content Security Policy Builder turns a notoriously fiddly security header into a point-and-click exercise. Instead of hand-writing a long Content-Security-Policy string and hoping the syntax is right, you tick the directives you need, choose their allowed sources, and the tool assembles a valid policy for you in real time. It is aimed at developers, site owners, and security-minded teams who want XSS and injection protection without memorising the full CSP specification.
A Content Security Policy is an HTTP response header that tells the browser exactly which origins are allowed to load scripts, styles, images, fonts, frames, and other resources. When a page tries to load something the policy does not permit, the browser blocks it. That single mechanism shuts down most cross-site scripting (XSS) attacks, blocks unauthorised data exfiltration, and — through frame-ancestors — defends against clickjacking.
Build a policy directive by directive
The builder exposes 15 standard fetch and navigation directives, including default-src, script-src, style-src, img-src, connect-src, frame-ancestors, base-uri, form-action, and worker-src. Enable any directive and assign source values from a curated list: keywords such as 'self', 'none', 'strict-dynamic', nonce and sha256 placeholders, and scheme sources like https:, data:, and blob:. You can also add custom domains (for example https://cdn.example.com or *.example.com) to whitelist your CDN, analytics, or embedded media providers.
If you would rather not start from scratch, six preset templates pre-fill sensible configurations:
- Basic Secure — a
'self'-based policy that covers the common directives - Strict — locks
default-srcto'none'and explicitly allows only what is needed - Permissive — a loose starting point for legacy sites still using inline code
- WordPress — accounts for inline scripts, Google Fonts, and YouTube/Vimeo embeds
- Next.js — handles the inline and eval requirements of the framework
- SPA (React/Vue) — tuned for single-page apps and blob workers
Score your policy and catch weak spots
Every change updates a strictness score out of 100, graded from Weak through Fair, Good, and Excellent. The score rewards genuinely protective choices — a restrictive default-src, a script-src free of unsafe keywords, object-src 'none', and a defined frame-ancestors — and the Analysis tab spells out what is driving it.
Two danger sources are flagged on sight. 'unsafe-inline' permits exploitable inline scripts and is the single most common reason a CSP fails to stop XSS; 'unsafe-eval' allows eval() and other dynamic code execution. The builder marks both with warnings and suggests safer nonce- or hash-based alternatives. Recommendations also nudge you toward missing protective directives like base-uri and form-action.
Test safely, then ship to any server
CSP can break a site if a legitimate resource gets blocked, so the builder includes a report-only mode. This emits the Content-Security-Policy-Report-Only header, which logs violations to an optional reporting endpoint without actually blocking anything — the recommended way to validate a policy in production before enforcing it. Note that this drops the strictness score slightly, since a report-only header offers no real protection until you switch to enforcement.
When the policy is ready, copy it as a raw HTTP header or as an HTML <meta http-equiv> tag (the tool reminds you that frame-ancestors, report-uri, and sandbox cannot be set via a meta tag). Ready-made snippets are generated for Nginx, Apache, Express.js, and Next.js, and you can download the result as a file.
Everything runs entirely in your browser. No policy, domain, or configuration is sent to a server, there is no sign-up, and the Content Security Policy Builder works on any modern browser, mobile included.