Skip to content

// Concept and defense

CSP (Content Security Policy) in SaaS

5 minUpdated July 28, 2026By Ler em português

What CSP is

CSP (Content Security Policy) is an HTTP header that tells the browser where it may load and execute things on your page: which scripts, styles, images and connections are allowed. It is a containment layer: if an XSS manages to inject a script, a strong CSP stops that script from running or from sending the stolen data out. It does not replace escaping input; it limits the damage when something gets through.

Think of CSP as the page’s seatbelt: you do not plan to crash, but when you do, it is what holds you.

Why AI (and the dev) forgets CSP

CSP does not show up in the demo, breaks nothing visible, and is annoying to configure without breaking your own site. So it tends to be left out, or comes in too weak to protect.

  • Absent: no CSP, so any injected script runs freely.
  • unsafe-inline: allows inline scripts, which cancels much of the protection.
  • Broad wildcard (*): allows loading from anywhere, with no real containment.
  • Report-only forever: monitors but never blocks.

How to build a strong CSP

A modern, strong CSP uses a per-request nonce with strict-dynamic: each legitimate script gets a unique nonce, and the browser only executes the ones that have it. That removes the fragile domain allowlist and blocks inline scripts injected by XSS.

  • script-src with a per-request nonce + strict-dynamic; avoid unsafe-inline.
  • A restrictive default-src; object-src none; base-uri none; frame-ancestors none.
  • A connect-src limited to the real destinations (contains an XSS’s exfiltration).
  • Ship in report-only first to find what breaks, then enforce.

Where RET fits

The Promptbook shows how to check whether your CSP is genuinely strong (nonce vs unsafe-inline, wildcards, connect-src). If your SaaS displays user content or embeds third parties, Risk Review reviews the CSP alongside the XSS flows, because the two layers work together: escaping prevents, CSP contains.

Want to know whether this happens in your system?

Manual pentest for web applications, APIs and apps, from R$9,500, with the Sprint run within 7 business days. We refund 50% if we find no flaw.

See price and timeline for my case

Frequently asked questions

Does CSP replace escaping input against XSS?

No. Escaping input is the primary defense that prevents XSS; CSP is the second layer that contains the damage if a script gets through. The two together are the secure standard; either one alone leaves a gap.

Isn’t unsafe-inline necessary?

Almost never, and it greatly weakens the CSP (it allows any inline script, including one injected by XSS). The modern alternative is a per-request nonce with strict-dynamic, which executes only the legitimate script.

Does report-only CSP protect?

It blocks nothing; it only reports violations. It is great for discovering what an enforcing CSP would break before turning it on, but leaving it in report-only forever contains no attack. The goal is to reach enforce.

How do I know if mine is strong?

Check whether it uses a nonce (not unsafe-inline), whether default-src/object-src/base-uri are restrictive, and whether connect-src limits destinations. The Promptbook guides that quick audit.

Keep reading