Skip to content
ScanAnt

Content-Security-Policy generator and checker

Build a CSP header from presets or by hand, copy it as a header or a meta tag, or paste an existing policy to get warnings about unsafe-inline, wildcards and missing directives. Everything runs in your browser.

Runs in your browser

Runs in your browser. Nothing is sent or stored.

Start from a preset

Presets are starting points. Replace placeholders such as YOUR-PROJECT and test every page before enforcing.

HTTP header

Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests

Meta tag

<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests">

A meta tag ignores frame-ancestors and cannot report violations. Use the header when you can.

Review of this policy

No weak spots found by these checks.

How it works and what to look for

What CSP does

Content-Security-Policy tells the browser which sources may load scripts, styles, images and connections for your page. If an attacker manages to inject a script tag, a good policy stops the browser from running it, which makes cross-site scripting much harder to exploit.

Start strict, then loosen

Begin with default-src self and add only the hosts your app really needs, such as your API, analytics or payment provider. Set object-src to none, base-uri to self and frame-ancestors to self or none. These three are often forgotten and each closes a real attack path.

What to avoid

The keyword unsafe-inline in script-src lets injected inline scripts run, which defeats most of the point. unsafe-eval allows eval and similar string-to-code calls. A bare star or a scheme such as https: allows scripts from almost anywhere. Use nonces or hashes for inline scripts instead.

Roll it out safely

Ship the policy as Content-Security-Policy-Report-Only first and watch what it would block. Fix the legitimate sources, then switch to enforcing. Prefer the HTTP header: a meta tag works for most directives but cannot set frame-ancestors, report-uri or sandbox.

Questions

Where do I put the generated header?

Add it as a response header in your server, CDN or framework config, for example in next.config headers or your hosting dashboard. If you cannot set headers, use the meta tag as a fallback.

Why does my app break after adding CSP?

Inline scripts, inline styles, third-party widgets or API hosts are usually blocked. Open the browser console, read the violation messages and add only the sources you need. Report-Only mode helps.

Do the presets work as they are?

They are a starting point. Replace placeholders such as YOUR-PROJECT, and test every page. Frameworks that inject inline code need a per-request nonce.

Is my policy sent anywhere?

No. Building and checking happen locally in your browser, and nothing you type is uploaded.

Does CSP replace other security headers?

No. It works alongside Strict-Transport-Security, X-Content-Type-Options and Referrer-Policy. A full scan shows which ones your site is missing.

Related security checks

Scan your whole site for free

One tool checks one thing. The free scan reads your public pages the way a visitor sees them and reports headers, exposed keys, outdated libraries and more. No signup.

Scan your whole site free →