Plain definition
Definition of Content Security Policy (CSP)
An HTTP response header that instructs a browser which sources of scripts, styles, frames, and network requests a web page is allowed to load and run.
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-<random>'; frame-ancestors 'none'Worked example
Consider a made-up markdown billing portal called LedgerPage at `https://app.ledgerpage.example` that renders user-submitted invoice notes and embeds Stripe Checkout links. To reduce the blast radius if an attacker ever slips unsanitized HTML into a note, the founder wants a tight Content Security Policy. Rather than flipping on a blocking policy blind during launch week, the team deploys `Content-Security-Policy-Report-Only` first with `default-src 'self'; script-src 'self' 'nonce-r4nd0m'; connect-src 'self' https://api.stripe.com; frame-ancestors 'none'; report-to csp-endpoint`.
Over 48 hours of staging and beta traffic, violation reports catch one forgotten inline analytics snippet and a font CDN domain (`fonts.gstatic.com`). Once the founder adds a per-request cryptographic nonce to the legitimate script tag and allowlists `font-src`, LedgerPage switches the header from `Report-Only` to enforced `Content-Security-Policy`. Now unauthorized inline `<script>` injections fail to execute and `frame-ancestors 'none'` blocks malicious iframes from framing the billing screen.
Why it matters when you launch
MDN highlights four core protections CSP gives a web app: blocking unauthorized scripts to mitigate cross-site scripting (XSS), restricting iframe embedding (`frame-ancestors`) to stop clickjacking, upgrading insecure requests to HTTPS, and optionally enforcing Trusted Types. Even with React or Next.js escaping text by default, third-party embeds, markdown renderers, and analytics snippets regularly introduce injection surface.
Rolling out CSP in `Content-Security-Policy-Report-Only` mode first is a huge time-saver for small teams. You discover every external font, Stripe script, webhook widget, or customer-support script your app legitimately loads and collect structured JSON violation reports before enforcing hard browser blocks that could silently break checkout on launch day.
Common mistakes
- Adding `'unsafe-inline'` and `'unsafe-eval'` to `script-src` just to silence errors, wiping out most of CSP's protection against injected XSS scripts.
- Deploying an enforced CSP header straight to production without testing `Content-Security-Policy-Report-Only`, accidentally blocking payment scripts or login widgets.
- Reusing a static nonce string across cached HTML responses instead of generating a fresh per-response nonce, making the nonce predictable to attackers.
- Relying on CSP as your only XSS defense instead of sanitizing untrusted HTML and markdown inputs on the server.
Tools and guides that use it
Free tool
Live Launch Readiness CheckerInspect any live URL for HTTPS, title, meta description, canonical, Open Graph cards, JSON-LD and AI search crawler access.Free tool
SaaS Privacy Policy & Terms GeneratorGenerate clean, developer-friendly Privacy Policy and Terms of Service agreements for Stripe, Google OAuth, and product launches.Founder guide
The Next.js Technical SEO Launch Checklist (2026)What to check before and after launch day: crawlability, metadata, canonical URLs, structured data, sitemaps, internal links, Core Web Vitals and AI crawlers.Founder guide
SEO for Next.js SaaS Sites: App Router Setup Guide (2026)Configure Next.js App Router metadata, canonicals, static prerendering, sitemaps, sanitized JSON-LD, Open Graph images, and Search Console verification for an indie SaaS.Related glossary terms
Official sources
Pritam Ghosh runs Hauntboard and maintains this glossary.
Published · Updated
Building something real? Launch it in public.
A person reviews every launch on Hauntboard, and every view and visit it sends your site is published on your launch page. Free to submit.