Esc
  • Jump to
  • The board
  • All launchesSort and filter by week or category
  • Open statsEvery number, in public
  • Maker storiesApps that stopped hiding
  • Submit a launch
  • AICategory
  • AnalyticsCategory
  • API & BackendCategory
  • Audio & VoiceCategory
  • AutomationCategory
  • CommunityCategory
↑↓ to move↵ to openPress / anywhere
Sign in

What is 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.

Updated · Building

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.

Formula / syntaxContent-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

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.

Launch free →

On the board

All →

Still hiding your app?

Put it on the board. Reviewed by a person, free to launch.

Launch free
Submit a launch