What is a Content Security Policy (CSP) header?
A Content Security Policy is an HTTP response header that tells the browser which origins may load or execute scripts, styles, images, fonts, XHR, frames, workers, and other resource types. It is one of the most effective ways to reduce the blast radius of cross-site scripting (XSS): unexpected inline script, eval, or third-party loads can be refused or reported. Searchers often look for a CSP generator, nginx Content-Security-Policy example, or CSP directive list — this page gives you a working baseline you can tighten for your stack.
How to use this CSP builder (step by step)
- Choose enforcing CSP or Report-Only. Use report-only in staging or production first so violations show up in logs without breaking users while you fix assets.
- Click a preset (Typical SPA, Stricter scripts, etc.) or enable directives manually. Edit space-separated sources such as
'self',https://cdn.example.com,data:, or nonce/hash tokens emitted by your framework. - Optionally use Import from file to load an existing policy from disk. The parser recognizes a bare directive string or a line that starts with
Content-Security-Policy:. - Press Copy policy value when your config expects only the semicolon-separated directives, or Copy full header line when you paste directly into server or CDN configuration. Fix violations reported in the console, then switch from report-only to enforcement.
Directive guide: default-src, script-src, frame-ancestors, and reporting
default-src is the usual starting point: it applies when a more specific directive is absent. Most teams combine it with explicit script-src and style-src rules so reviews are explicit. frame-ancestors replaces many uses of X-Frame-Options for clickjacking defense—values like 'none' or a list of partner origins are common. For observability, add report-uri or report-to alongside the Reporting API headers your infrastructure supports. When you evaluate tokens and digests for inline script, the hash generator can help compute SHA-256 hashes for small static snippets in controlled setups.
Deploying CSP on nginx, Apache, CDNs, and application frameworks
After you copy the header, attach it at the edge or origin: nginx uses add_header Content-Security-Policy "..."; Apache uses Header set from mod_headers. Platforms like Vercel, Netlify, and Cloudflare Workers expose static response header maps. Frameworks such as Next.js can set headers in config; verify output with the HTTP header checker on a preview URL before promoting to production.
Keywords and topics this CSP tool supports
Teams search for CSP unsafe-inline alternative, Content-Security-Policy-Report-Only example, block mixed content CSP, and upgrade insecure requests. This builder encodes those ideas as toggles and short descriptions so you can align policy with OWASP-style guidance while staying framework-agnostic. For API tokens used in tests—not in CSP itself—see the JWT encoder and JWT decoder.
Related security utilities on this site
Explore the full security and encryption tools section, or open a focused utility below.
- Password Strength Meter — Score password entropy, estimate crack time, and get practical hardening tips.
- bcrypt Hash Generator — Generate bcrypt hashes with configurable cost for secure password storage testing.
- AES Encrypt & Decrypt — Encrypt and decrypt text with AES-256 and a passphrase—runs fully in your browser.
- RSA Key Pair Generator — Create 1024–4096 bit RSA public/private key pairs locally for demos and dev workflows.
- Security Headers Checker — Analyze security-related HTTP headers on any URL with graded guidance to harden responses.
- JWT Encoder — Build HS256-signed JWTs from custom header and payload for API and auth testing.
- HMAC Generator — Create HMAC-SHA256 or HMAC-SHA512 signatures with a secret for webhook and API verification.
- SSL Certificate Decoder — Paste PEM certificates to read subject, issuer, SANs, and validity windows.
- .htaccess Generator — Assemble common Apache .htaccess rules for redirects, HTTPS, caching, and access control.