Security headers · CSP · static export
Check what your CSP actually allows
Paste the policy you ship, or the header block your server returns. CSPForge parses every directive, scores the policy and the headers around it, and names the line that lets an attacker in. Then build the corrected version and export it for your platform. No account, no upload, no cookies.
- 100% in the tab
- No upload
- No account
- No cookies
- Works offline after load
In short
CSPForge is a free browser tool that audits a Content-Security-Policy together with the main security headers, scores them from 0 to 100 with a letter grade, and exports a corrected policy for Cloudflare Pages, Nginx, Apache, Vercel or an HTML meta tag. Parsing, scoring and generation all run locally in the tab: nothing is uploaded, no account is needed, and no cookie or local storage is written.
Audit a policy
100% localPaste a Content-Security-Policy string or a whole header block. Strict-Transport-Security, X-Content-Type-Options, Referrer-Policy and Permissions-Policy are scored too.
Build a policy
live scoreToggle a directive, add the hosts you really use, and the score follows as you type. Space separates tokens; the quotes around keywords are optional here.
Response headers
Export the configuration
_headers · nginx · apache · vercel · metaThe file below follows the last build. Copy it, or download it for the platform you deploy to.
How it works
01 / 03- 01
Paste and parse
A policy string or a full header block. Unknown directives, duplicate copies and a Report-Only policy are reported instead of being silently accepted.
- 02
Read the score
The policy carries 80% of the grade and the headers 20%. Every deduction names the directive or header it comes from and what to write instead.
- 03
Build and export
Toggle the directives, add the hosts you actually use, then copy a _headers file, an nginx add_header block, a .htaccess, vercel.json or a meta tag.
Guide
CSP / headersWhat a Content-Security-Policy really decides
A CSP is a list of instructions the browser applies to the document it just received. It does not sanitize anything, and it is not a substitute for escaping output: it limits what the page is allowed to load and execute, so an injected script tag either runs with full access to the page or is refused before it runs. That difference is the whole value of the header.
Two consequences follow. First, a CSP only helps when it is strict in the places that execute code: script-src, and the directives that can reach it indirectly, object-src and base-uri. A policy that locks down images but leaves script-src open changes almost nothing. Second, a policy is an inventory of what your site loads. If you cannot list the origins, an audit answers the next question for you: which line is the weak one.
Report-Only mode is a separate header. Content-Security-Policy-Report-Only sends violation reports and blocks nothing, which is the right way to stage a policy, and a trap if it is left in place for a year.
How a policy is read: directives and fallback
A policy is a semicolon separated list of directives. Each directive is a name followed by a whitelist of sources: a host (https://cdn.example.com), a scheme (https:), a keyword ('self', 'none'), a nonce ('nonce-r4nd0m') or a hash ('sha256-…'). The first occurrence of a directive wins; a second copy is ignored by the browser and quietly does nothing, which is why duplicates are worth reporting.
default-src is the fallback for the directives that are not listed. That is convenient and easy to misread: script-src, style-src, img-src, font-src, connect-src, frame-src and media-src inherit from it, but base-uri, form-action and frame-ancestors do not. A policy with only default-src 'self' therefore leaves base-uri and form-action completely open, which is a common and invisible gap.
CSPForge follows those rules literally: it applies the effective source list to each check, marks a finding against the directive that actually governs the behaviour, and lists the directives it parsed so you can see exactly what the browser would see.
The directives that carry the security
script-src is where nearly all risk lives. 'unsafe-inline' re-enables inline script, and with it every injected <script>, onerror= handler and javascript: URL. 'unsafe-eval' re-enables eval, new Function and string timers, turning data injection into code execution. A bare * or an http: source is nearly as bad: any host, or any host that can be spoofed on the wire, may serve code to your page. The modern alternative is a nonce or a hash, or 'strict-dynamic' with a nonce, which lets the trusted script load its own dependencies.
object-src and base-uri are the two cheap wins. Plugins are gone, so object-src 'none' costs nothing. An injected <base href> rewrites every relative URL in the page, including the URL of a script with a relative src, so base-uri 'none' closes a real path that script-src alone does not.
frame-ancestors replaces X-Frame-Options for clickjacking. Anything other than 'none' or a short list of embedders lets another site put your page in a frame and place invisible buttons over it.
form-action is not inherited from default-src. Without it an injected form can post a password field to an attacker's origin, which is exactly the pattern credential phishing uses.
The score: policy 80%, headers 20%
Two numbers are computed separately. The policy score starts at 100 and subtracts a fixed penalty for each rule the policy breaks: for example 18 for 'unsafe-inline' in the effective script source, 15 for 'unsafe-eval', 6 for a missing object-src, 5 for a missing base-uri. The header score is the same idea over HSTS, X-Content-Type-Options, Referrer-Policy and Permissions-Policy, normalised to a 0 to 100 scale. The overall grade is 80% policy plus 20% headers, so a perfect policy with no headers scores 80 instead of a misleading 100.
Grades are A+ from 95, A from 90, B from 80, C from 70, D from 60, E from 40 and F below that. A missing policy scores zero. The penalties are opinionated, not official: they weight the checks that change exploitability, and they are identical in the two implementations this site is tested with, so the number is reproducible rather than a mood.
Headers that belong next to the policy
| Header | Value to ship | What it stops |
|---|---|---|
Strict-Transport-Security | max-age=31536000; includeSubDomains | A first request downgraded to http, and the cookie or credential theft that follows |
X-Content-Type-Options | nosniff | A browser guessing a type and running an uploaded text file as script |
Referrer-Policy | strict-origin-when-cross-origin | Full URLs leaking to third parties in the Referer header |
Permissions-Policy | geolocation=(), camera=(), microphone=() | An embedded frame or a compromised script asking for device permissions |
COOP and CORP are recommended as well, and shown as advice rather than scored: Cross-Origin-Opener-Policy: same-origin separates your window from the page that opened it, and Cross-Origin-Resource-Policy: same-site stops another origin from embedding your responses. Both are easy to add once the rest is clean.
Deploying the policy: five formats, one meaning
_headers on Cloudflare Pages is a plain text file at the output root: one path pattern, then indented Name: value lines. Nginx needs one add_header per header inside the server block, with always so error pages get them too. Apache uses Header always set inside mod_headers. Vercel takes a JSON array of route patterns and key/value pairs. A <meta http-equiv> tag carries the policy and nothing else: HSTS and the other headers have no meta equivalent, so a meta-only deployment is a partial one.
Wherever the policy lands, keep two habits. Ship it to staging first and watch the violation reports, and keep the source list as short as the site allows. A policy copied between projects is usually wrong in both directions: too loose for one, and blocking a font or an analytics call for the other.
A short checklist before you deploy
- No
'unsafe-inline'or'unsafe-eval'in the effectivescript-src. Move inline code to a file or give it a nonce. object-src 'none',base-uri 'none',frame-ancestors 'none'unless embedding is a product feature.form-action 'self'plus the payment or identity origin if a form posts there.upgrade-insecure-requestspresent, and nohttp:source left in the policy.- A reporting endpoint:
report-towith aReport-Toheader, or the olderreport-uri. - Duplicates removed, spelling checked. A typo in a directive name is accepted by the parser and ignored by the browser.
- HSTS with a max-age of at least six months, and the other three headers present on every response, including errors.
FAQ
9Is CSPForge free, and do I need an account?
Does my policy or header block leave the browser?
Why does a reasonable-looking policy score so low?
object-src, base-uri or frame-ancestors is easy to forget and still exploitable, and the four security headers are part of the grade. The findings list shows each deduction so you can disagree with a specific one.Can I use it on a policy with a nonce?
'nonce-…' or 'strict-dynamic' is scored as written. Rotating nonces change per response; the structure is what is audited.Does it fetch my site and check the live headers?
curl -sI https://your.site | grep -i -E 'content-security|strict-transport|x-content|referrer|permissions' gives you the block in one line.Which is better, a meta tag or a real header?
Is 'unsafe-inline' ever acceptable?
How do I know the exported file is correct?
_headers is written in the Cloudflare format. Copy the file, deploy, then curl -sI your own domain and paste the response back into the audit tab: the score you see is the score on the wire.