DevTools Logo

CSP Builder & Validator

CSP Builder & Validator

Build a Content-Security-Policy visually, or audit an existing header

Policy Mode

Log violations without blocking

Directives

default-src
1
script-src
1
style-src
1
img-src
2
font-src
1
connect-src
1
media-src
1
object-src
1
frame-src
1
frame-ancestors
1
base-uri
1
form-action
1
manifest-src
1
worker-src
1
prefetch-src
1

default-src

Default policy for all content types

'self'

    Examples

    Audit an unsafe policy

    Input
    default-src 'self'; script-src 'self' 'unsafe-inline'; img-src *
    Output
    Score 55 — 'unsafe-inline' in script-src and the * wildcard in img-src flagged high; missing frame-ancestors flagged medium.

    On the Validate tab, paste a header to see exactly which directives weaken it and how to fix each one.

    Confirm a strict deny-by-default policy

    Input
    default-src 'none'; script-src 'self'; connect-src 'self'; frame-ancestors 'none'
    Output
    Score 100 — every directive explicit, no unsafe sources.

    A deny-by-default policy scores 100 in the validator because no unsafe directives or wildcards are present.

    About this tool

    A Content-Security-Policy (CSP) header turns expected XSS, framing and injection attacks into browser-side blocks. It is a single header value made of one or more directives — default-src, script-src, style-src, img-src, frame-ancestors, and so on — each with a list of allowed source expressions. A wrong choice (for example allowing 'unsafe-inline' on script-src) reopens the very doors CSP is designed to close, so a builder that lets you see each directive's effect side-by-side is faster than hand-tuning a one-line header.

    The builder follows the W3C CSP3 directive list and exposes 15 of the most-used directives with their default source sets. Each directive has a one-line description, click-to-add common sources ('self', 'none', https: scheme, 'strict-dynamic', etc.) and a button-grid of popular hostnames (CDNs, Google Fonts, Stripe, GA, GTM) so you do not have to memorize which origins your stack needs. Sources are quoted exactly the way the header parser expects — keywords with single quotes (e.g. 'self'), schemes plain (e.g. https:).

    The generated header is rendered in four formats — Standard HTTP, Nginx add_header, Apache Header always set, and a Next.js middleware snippet — plus a Report-Only mode that switches the header name and adds an optional report-uri for collecting violations without enforcing them. A live Security Score surfaces the cost of every choice: 'unsafe-inline' (-10), 'unsafe-eval' (-15), http: scheme (-20 per directive), broad https: scheme (-5 per directive). The header leaves your browser only when you copy it; nothing is uploaded.

    How to use

    1. Start with default-src 'self'

      Open default-src and confirm it has 'self'. This single directive is the fallback for every fetch type — without it you must declare every other source individually.

    2. Add the directives your stack needs

      Click script-src, style-src, img-src, font-src, connect-src, frame-src, frame-ancestors, etc. Click common-source chips or popular-domain buttons to add sources without typing URLs.

    3. Watch the Security Score as you add sources

      Each 'unsafe-inline' lowers the score by 10; each 'unsafe-eval' by 15; http: by 20; https: by 5. Aim to keep the score above 80 unless a hard requirement forces a relax.

    4. Switch to Report-Only first

      Toggle Report-Only, set the report-uri endpoint, and ship the header in monitoring mode. Once violations stop, switch to enforce mode for production.

    5. Copy the format your server uses

      Use the Standard tab for documentation, Nginx for sites-available, Apache for .htaccess, or Next.js to drop a middleware file directly into your app.

    Use cases

    Validate before you ship

    Paste a candidate CSP into the Validate tab to catch unsafe-inline or wildcards before the header reaches production.

    Score an existing site

    Copy the live Content-Security-Policy header and get a 0–100 risk score plus ranked fixes.

    Common mistakes

    Mistake:Trusting a policy because it has many directives.

    Fix:default-src is the backbone — without it, every unspecified resource type is allowed. Always set default-src.

    Mistake:Keeping 'unsafe-inline' to avoid breakage.

    Fix:Move to nonces or hashes, or 'strict-dynamic', so inline scripts are gated instead of globally allowed.

    Frequently asked questions

    References & standards