Security ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Security Tools

Content Security Policy (CSP) Generator

Build a Content-Security-Policy with source checks and risk warnings for each directive, then export it as a header, meta tag, Nginx, Apache or _headers rule.

View all tools
ResultUpdates as you type
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'

Before going live, try report-only mode and check the browser console for anything that would be blocked.

How to use Content Security Policy (CSP) Generator

Edit the sources for each directive, add others such as media-src one per line, and set an optional report URL. Choose the output format, tick report-only or upgrade-insecure-requests if needed, and copy the line.

  1. Fill in the directivesEdit the sources for default-src, script-src, img-src and the rest; leave a box empty to omit it.
  2. Add extras and optionsAdd other directives one per line, a report-uri, upgrade-insecure-requests or report-only mode.
  3. Choose a format and copyPick HTTP header, meta tag, Nginx, Apache or a _headers file, read any warnings, then copy.

What the default policy allows

The starting policy is default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'. Scripts, fonts and API calls may only come from your own origin, images may also load from any HTTPS host or data URIs, inline styles are allowed, plugins are blocked and no other site can frame the page. Sources are checked as you type: an unquoted keyword such as self is corrected to 'self', and semicolons, commas or invalid hosts stop the output.

Warnings worth taking seriously

Allowing 'unsafe-inline' in script-src without a nonce, hash or 'strict-dynamic' lets injected inline scripts run, which removes most of the XSS protection a CSP offers; 'unsafe-eval' and broad sources such as *, https: or data: in script-src are flagged too. A meta tag can't carry frame-ancestors, report-uri or sandbox, and report-only mode only works as an HTTP header. Analytics, ads and third-party APIs usually need their domains in connect-src as well as script-src. Roll out in report-only mode first and watch the browser console.

Accuracy and data handling

A format or strength result covers only the checks shown here and does not replace a full security review or secure key management. The calculation runs in your current browser; the tool code does not send the input to a processing API.

Often Used Together

Next step

FAQ

What is a Content Security Policy?

CSP is an HTTP response header that tells the browser which sources a page may load scripts, styles, images, frames and other resources from. A strict policy limits the damage of cross-site scripting (XSS).

How do I allow several third-party domains?

List them in the same directive, separated by spaces, for example 'self' https://a.example.com https://b.example.com. Each source is validated and duplicates are removed.

My site broke after adding a CSP. What now?

Open the browser console to see which resource was blocked and by which directive, then add that source. Trying report-only mode first lets you find these problems without blocking anything.

Should I use the meta tag or the HTTP header?

Prefer the header. The meta tag helps when you can't change server headers, but browsers ignore frame-ancestors, report-uri and sandbox in it, and it can't be used for report-only mode.

More Security Tools

Related tools