Skip to main content
L
Loopaloo
Buy Us a Coffee
All ToolsImage ProcessingAudio ProcessingVideo ProcessingDocument & TextPDF ToolsCSV & Data AnalysisConverters & EncodersWeb ToolsMath & ScienceGames
Guides & BlogAboutContact
Buy Us a Coffee
L
Loopaloo

Free online tools for developers, designers, and content creators. Your files are processed in your browser and are never uploaded - no accounts required. A few network utilities (like What's My IP and Currency Converter) call public APIs to do their job and say so on their pages.

support@loopaloo.com

Tool Categories

  • Image Tools
  • Audio Tools
  • Video Tools
  • Document & Text
  • PDF Tools
  • CSV & Data
  • Converters
  • Web Tools
  • Math & Science
  • Games

Company

  • About Us
  • Contact
  • Blog
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

Support

Buy Us a Coffee

© 2026 Loopaloo. All rights reserved. Built with privacy in mind.

Privacy|Terms|Disclaimer
  1. Home
  2. Web Tools
  3. CSP Builder
Add to favorites

CSP Builder

Build a Content Security Policy and see what a browser will actually apply, including the CSP3 rules that silently discard what you wrote.

Runs locally in your browserMore web toolsJump to full guide

Related reading

  • Content Security Policy: Protecting Your Website from Injection Attacks10 min read

Initializing in your browser…

You might also like

SRI Hash Generator

Build a Subresource Integrity attribute, with more than one hash if you want, and check an existing one against the file it is meant to pin.

Password Generator

Generate passwords from the Web Crypto generator by rejection sampling, with the entropy stated exactly from the alphabet, the cost of every rule computed, and crack times against four named attacker models

Certificate Decoder

Decode an X.509 certificate field by field, check which host names it covers, and verify that each certificate in a chain was signed by the one above it

CSP Builder: a worked example

Your policy uses 'unsafe-inline' for a handful of inline scripts, and you are moving to a nonce so it can be removed. You add the nonce first, intending to drop 'unsafe-inline' afterwards.

The policy you wrote

script-src 'unsafe-inline' 'self' 'nonce-8emk/+h69qBbrg9F+Fbtaw=='
What CSP Builder produces

What a browser will actually apply

script-src 'self' 'nonce-8emk/+h69qBbrg9F+Fbtaw=='

script-src  'unsafe-inline' in script-src is IGNORED, because this
            directive also carries a nonce or a hash. CSP Level 3 section
            6.7.3.2 discards it whenever either is present. Every inline
            script or style here must carry the nonce or match a hash, or
            it will be blocked. Keeping 'unsafe-inline' is still worth
            doing as a fallback for CSP Level 1 browsers, which ignore the
            nonce instead.

Adding the nonce did not widen the policy; it narrowed it, and it narrowed it before you removed anything. CSP Level 3 discards `'unsafe-inline'` outright whenever a nonce or a hash appears in the same directive, so at the moment the nonce goes in, every inline script that has not yet been given the nonce attribute stops running. Nothing in the policy text says so, no directive was removed, and the deployment looks like a widening.

The project tests do not take this from the specification. They serve a real page under each policy and record what ran: with `'unsafe-inline'` alone the inline script runs, and with a nonce beside it the same script is blocked while the nonced one runs. The same method covers `'strict-dynamic'` discarding `'self'`, a bare `self` allowing nothing where `'self'` allows the same-origin script, `frame-ancestors` being ignored in a meta element, and a report-only policy blocking nothing at all.

The advice that follows from it is the part worth keeping: do not remove `'unsafe-inline'` when you add the nonce. CSP Level 1 browsers ignore the nonce and fall back to `'unsafe-inline'`, while CSP Level 3 browsers ignore `'unsafe-inline'` and honour the nonce, so leaving both in place is what makes one policy work in both.

Build a CSP, and see what it really does

Build a Content Security Policy directive by directive, and see what a browser will actually apply. Several CSP Level 3 rules discard parts of a policy silently, so the policy you wrote and the policy that runs are not always the same thing; this tool shows both, and every rule it applies is checked against Chrome itself.

Key features

  • The effective policy shown beside the written one whenever CSP3 discards something
  • 'unsafe-inline' reported as ignored when a nonce or hash is present, with the section that says so
  • 'strict-dynamic' reported with the sources it discards, named and counted
  • The five directives with no default-src fallback labelled and reported when missing
  • The four directives a meta policy ignores flagged as errors when meta delivery is chosen
  • An unquoted keyword corrected rather than passed through as a host name
  • A 128-bit nonce per build, with the requirement to regenerate it per response stated
  • sha256, sha384 and sha512 hashes of an inline script or style, added to a directive in one click
  • Report-only as a real mode, with a warning when there is nowhere to report to
  • Six output forms, including nginx with the always flag that error responses need

How to use

  1. 1Start from a preset. The report-only one is the safe way to begin on a site that is already running.
  2. 2Enable the directives you need and pick sources for each. Keywords, scheme sources and a nonce are one click; hosts are typed.
  3. 3Read the findings. They name the rules that discard what you wrote, and the directives default-src does not cover.
  4. 4Check the effective policy if one is shown: that is what a browser will apply, and it is not always what is written above it.
  5. 5Copy the form you need. Header, nginx, Apache, Express, Netlify, or a meta element.

How it works

A Content Security Policy is a list of directives, each naming where a kind of resource may come from. The difficulty is not writing one; it is that several of the rules that decide what a policy does are applied silently, so a policy can look strict and do nothing, or look permissive and break the site.

The rule most builders miss: **a nonce or a hash makes 'unsafe-inline' be ignored.** CSP Level 3 section 6.7.3.2 discards 'unsafe-inline' entirely whenever the same directive carries a nonce or a hash source. Add a nonce to a policy that was relying on 'unsafe-inline' and every inline script without the nonce stops running, with nothing in the policy text to suggest it. This tool shows the written policy and the effective one side by side whenever they differ, and the project tests confirm the behaviour by serving a page under the policy and watching whether Chrome runs the script, rather than by quoting the specification. 'strict-dynamic' is handled the same way: it discards every host source, every scheme source and 'self' in its directive, which the tool reports by name and count.

**Some directives have no default-src fallback.** frame-ancestors, form-action, base-uri, report-uri and sandbox are not covered by default-src, however strict it is, so leaving them out leaves them unrestricted. Each is labelled in the interface and each is reported when missing, with what it costs: any site can frame the page, an injected form can submit anywhere, an injected base element can redirect every relative URL. **Four directives are ignored in a meta element:** frame-ancestors, report-uri, report-to and sandbox. A builder that hands you a meta tag containing them is handing you something that does less than it says, so choosing meta delivery here flags them as errors, which is exactly what Chrome reports in the console.

**A keyword without its quotes is a host name.** 'self' is the keyword; self is a domain, and a policy containing the second is syntactically valid, allows nothing, and reports no error anywhere. Typing an unquoted keyword into a source box corrects it rather than passing it through, and the difference is measured in the tests: a bare self allows nothing, while the corrected 'self' allows the same-origin script.

A nonce is generated for each build from the platform generator, 128 bits as the specification asks, with the reminder that a server has to produce a new one on every response. Inline scripts and styles can be hashed to sha256, sha384 or sha512 and added directly to a directive, which removes the need for 'unsafe-inline' without needing a nonce at all. The policy comes out as an HTTP header, an nginx add_header with the always flag, an Apache Header always set, an Express call, a Netlify _headers block, and a meta element when meta delivery is chosen. Report-only is a first-class mode with the right header name, and the tool points out that a report-only policy with no report-uri blocks nothing and records nothing.

Four presets are offered. The strict one is the shape the specification itself recommends, a nonce with 'strict-dynamic', which is the only arrangement that survives a page adding scripts at runtime without listing every CDN it might reach. A report-only preset is included because turning a policy straight on is how a site breaks: the way to find out what a real site does is to watch it first.

Tips & best practices

  • Deploy report-only first and read the reports. Turning a policy straight on is the usual way a site breaks.
  • Set object-src to 'none'. The specification recommends it outright, and plugin content bypasses most other restrictions.
  • On nginx, use the always flag. Without it the header is omitted on error responses, which is where an attacker would rather be.

Practical scenarios

  • Turning a policy on without breaking the site

    Start with the report-only preset, deploy it, and read the violation reports before switching to enforce.

  • Moving from unsafe-inline to a nonce

    The tool shows that adding the nonce makes unsafe-inline stop applying, which is the step that breaks inline scripts that were not updated.

  • Working out why a directive is doing nothing

    Between strict-dynamic discarding host sources, a nonce discarding unsafe-inline, and a keyword missing its quotes, most silent CSP failures are one of three things, and each is named here.

  • Replacing X-Frame-Options

    frame-ancestors is the replacement, has no default-src fallback, and does nothing in a meta tag. All three are stated on the directive itself.

Frequently asked questions

I added a nonce and my inline scripts stopped working. Why?

Because a nonce makes 'unsafe-inline' be ignored. CSP Level 3 section 6.7.3.2 discards it whenever the directive also has a nonce or a hash, so every inline script now needs the nonce attribute. Keeping 'unsafe-inline' in the policy is still worth doing as a fallback for CSP Level 1 browsers, which ignore the nonce instead, and the tool says so rather than telling you to remove it.

Why does my policy not stop other sites framing my page?

frame-ancestors has no default-src fallback. However strict default-src is, leaving frame-ancestors out leaves framing unrestricted. The same is true of form-action, base-uri, report-uri and sandbox.

Can I put the policy in a meta tag?

Mostly. frame-ancestors, report-uri, report-to and sandbox are ignored in a meta element, and a report-only policy in a meta element is ignored entirely. Choose meta delivery here and those are flagged, which is the same thing Chrome prints in the console.

What does strict-dynamic actually do?

It says to trust scripts loaded by an already-trusted script, and in exchange it discards every host source, scheme source and 'self' in the same directive. It only does anything alongside a nonce or a hash. The tool lists what it discarded so the effect is visible rather than surprising.

Should I use a nonce or a hash?

A nonce if your server renders the page and can put a fresh value on every response. A hash if the inline block never changes, since it is static and needs no server involvement. A hash covers the exact bytes between the tags, whitespace included, so a formatter run will break it.

Why does the tool change what I typed?

Only when what you typed would not do what you meant. A keyword without quotes is a host name to a browser, so typing self gives 'self'. A policy containing a bare self is valid, allows nothing, and produces no error at all, which makes it a hard thing to find on your own.

Is a policy enough to stop XSS?

No. It is a second line of defence for when the first one fails. A policy with 'unsafe-inline' in script-src provides very little, and one with 'unsafe-eval' or a wildcard script-src provides essentially none; the tool says so where it applies. Escaping output correctly is still the first job.

Related tools and how they differ

  • SRI Hash Generator: Generates SHA-256/384/512 integrity hashes for a specific JS/CSS file; use it to pin a CDN asset against tampering, after CSP has whitelisted its source.
  • URL Safety Analyzer: Scores a single inbound URL for phishing and homograph tricks before clicking; use it to vet a link you received, not to set your site's load policy.

Further reading

  • Content Security Policy: Protecting Your Website from Injection Attacks10 min read

Private by design

This runs as client-side JavaScript. Keys, tokens, payloads, and other inputs never leave your device.