Search tools

Content Security Policy Builder

Choose where scripts, styles, images and other resources may load from, and get a CSP header with a security check.

Content Security Policy Builder tool

Start from
Import an existing policy
default-src Fallback for every type not listed below
script-src JavaScript
style-src CSS
img-src Images
font-src Web fonts
connect-src fetch, XHR, WebSocket (APIs, analytics)
media-src Audio and video
frame-src Pages you embed in iframes
worker-src Web workers and service workers
object-src Old plugins (Flash, <object>)
base-uri Allowed <base> URLs
form-action Where forms may submit
frame-ancestors Who may embed your page
    HTTP header (recommended)
    Meta tag (if you can’t set headers — frame-ancestors, report-uri and report-only don’t work here)

    Processing runs in your browser.

    Cross-site scripting (XSS) is one of the most common web security problems: an attacker finds a way to get their own JavaScript onto your page, then steals sessions or changes what visitors see. A Content Security Policy is a strong second line of defence. Even if a bug lets a script in, the browser won’t run it unless it comes from a source you approved.

    How a policy reads

    A policy is a list of directives separated by semicolons:

    default-src 'self'; img-src 'self' data: https:; object-src 'none'; base-uri 'self'

    This says: load everything from my own domain by default, allow images from my domain, inline data URLs and any https site, never load plugins, and only allow <base> tags pointing to my own site.

    Common sources

    • 'self' — your own origin (same scheme, host and port).
    • 'none' — nothing at all.
    • https://cdn.example.com — one specific host. *.example.com covers its subdomains.
    • data: and blob: — inline data. Fine for images and fonts, risky for scripts.
    • 'nonce-…' or 'sha256-…' — allow specific inline scripts safely.

    Rolling it out

    Start in report-only mode and browse your site with the developer console open. Every blocked resource shows up as an error that names the directive. Add the sources you really need, remove the ones you don’t, and only then switch to enforcing. Third-party tools such as analytics, chat widgets and payment forms usually need their own domains listed. Their documentation normally gives the exact CSP entries.

    How to use the Content Security Policy Builder

    1. Start from a preset: Strict, Typical website or With Google Analytics & Fonts, or import your current policy.
    2. For each directive, tick sources such as 'self' or data: and type any extra domains.
    3. Read the risks and tips the checker lists.
    4. Turn on Report-only mode to test the policy without blocking anything.
    5. Copy the HTTP header, or the meta tag if you can’t set headers.

    Features

    • 13 fetch and navigation directives, plus upgrade-insecure-requests and report-uri.
    • Presets for a strict policy, a typical site and Google Analytics with Google Fonts.
    • Imports an existing Content-Security-Policy header for editing.
    • Flags unsafe-inline, unsafe-eval, wildcard script sources, missing object-src and base-uri, and http: sources.
    • Meta tag output automatically drops directives that only work as headers.

    Frequently asked questions

    What does a Content Security Policy do?

    It tells the browser which sources a page may load scripts, styles, images and other resources from. If an attacker manages to inject a script, the browser refuses to run it unless its source is on the list.

    Why is 'unsafe-inline' risky?

    It allows any inline script to run, including one injected by an attacker, which removes most of the protection against cross-site scripting. Use nonces or hashes for the inline scripts you really need.

    Should I use the header or the meta tag?

    The HTTP header is better. The meta tag version can’t use frame-ancestors, report-uri or report-only mode, and it only applies to content after the tag. Use the meta tag when your host doesn’t let you set headers.

    How do I roll out a CSP without breaking my site?

    Send it as Content-Security-Policy-Report-Only first. The browser logs what it would have blocked in the developer console without blocking anything. Fix the policy, then switch to the enforcing header.

    Written by