What Is Content Security Policy? CSP Explained
What is Content Security Policy? CSP is a browser header that limits where a page loads scripts and sends data, and it decided who the Optimizely attack hurt.
A Content Security Policy (CSP) is an HTTP response header that tells the browser which sources a page may load scripts, frames, images and styles from, and which hosts it may send data to. Everything outside the list is blocked or reported. In the Optimizely incident of 16 November 2026, Report URI found that only 24 of the 159 affected organizations it evaluated blocked the payload, and every one of them did it with a restrictive CSP. This article explains what a CSP is, which directives matter and how to deploy one without breaking production.
What is Content Security Policy?
Content Security Policy is a browser security standard delivered as an HTTP header. The server lists allowed sources for each kind of resource, and the browser refuses to load or connect to anything outside that list. It is the only widely supported control that limits what a third-party script can do after it has already been loaded and is running.
The header is set by your web server, CDN or application framework, not by the scripts on the page. That matters: a compromised vendor can change its JavaScript all it likes, but it cannot change the policy your server sends, because the policy arrives before any script runs.
How does a CSP block a supply chain attack?
A compromised trusted script usually has to fetch a second stage from an attacker's domain, send stolen data to a collection server, or open a frame to an exploit page. A CSP that lists only the hosts you actually use denies all three, so the injected code runs but cannot complete its job.
The Optimizely supply chain attack that CISA added to KEV is a clean worked example. The malicious loader lived inside a legitimate file on cdn.optimizely.com, a host every affected site had deliberately trusted. Allowing that host was never the mistake. The loader then needed to pull track.js from an attacker domain, post card data and cookies back to the same domain, and load an iOS exploit kit in an iframe from two other domains. Report URI measured which policies stopped which step:
- 68 organizations had no CSP, so every step succeeded
- 50 had a CSP permissive enough that every step still succeeded
- 17 let the payload load but blocked the data theft with connect-src
- 24 blocked the payload outright with a restrictive script-src
The 17 partial cases are instructive. Their policies did not stop the script from running, but the script could not phone home, so card skimming and cookie theft failed. Address swapping still worked because it only touches the page itself. Partial protection is still protection.
The directives that decided the outcome
A CSP is a list of directives, each naming a resource type and its allowed sources. Four did the work on 16 November:
script-srccontrols where the page may load JavaScript from. A policy that lists only cdn.optimizely.com and your own hosts refuses a script tag pointing at an unknown domain.connect-srccontrols where the page may send data with fetch, XMLHttpRequest, WebSocket and sendBeacon. This is the directive that stops exfiltration even when the script itself ran.frame-srccontrols which pages may be loaded in an iframe. The iOS exploit kit arrived through a hidden iframe from an attacker domain.default-srcis the fallback for any resource type you did not list explicitly. Set it tight and open individual directives as needed.
A minimal policy for a site that loads the Optimizely snippet and nothing else from outside would look like this:
Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.optimizely.com; connect-src 'self'; frame-src 'none'
Your real policy will be longer, because real sites load fonts, analytics, video players and tag managers. The principle holds: every host on the list is a host you have chosen to trust, and nothing else gets in or out.
Why strict-dynamic and unsafe-eval undo the protection
Two keywords appear in a lot of policies because vendor documentation asks for them, and both let the Optimizely payload through.
'strict-dynamic' tells the browser that any script inserted by an already-trusted script is also trusted. It exists to make nonce-based policies workable with tag managers that inject other tags. In a supply chain attack it is a blank check: the compromised Optimizely snippet was trusted, so the attacker's script tag it inserted was trusted too.
'unsafe-eval' allows code to be executed from strings. Optimizely's own documentation tells customers to allow it. The attacker shipped a variant of the loader that carried a full inline copy of the payload and ran it through eval when the remote domain was blocked. Report URI reports that this is exactly what happened at HSBC: the CSP blocked track.js and the data theft, but the inline copy still ran.
If a vendor requires either keyword, treat that as a finding in your vendor review, not a configuration detail. Ask whether the vendor's script can be isolated to the pages that need it, and whether the function it provides justifies the exposure. The audit of third-party JavaScript on your site is where that question gets answered.
What is report-only mode?
Report-only mode is a second header, Content-Security-Policy-Report-Only, that evaluates the same policy but never blocks anything. The browser sends a violation report to an endpoint you choose for each resource the policy would have stopped. It gives full visibility of what runs on your site with no risk of breaking it.
Scott Helme, who runs Report URI, describes three positions a site can be in: no CSP at all with no visibility, a report-only policy with full visibility of what code runs and when it changes, or an enforced policy where malicious behaviour is blocked. Moving from the first to the second is where most organizations should start, because it is reversible and it costs nothing in production behaviour. Report URI's own threat intelligence pipeline first flagged the Optimizely injection on a customer site at 15:06 UTC on 16 November, more than an hour before Optimizely closed the vulnerability, and that detection came from report-only violation data.
How do you start a CSP without breaking the site?
Start in report-only mode with a policy that lists the sources you already know, collect violation reports for two to four weeks, add the legitimate sources you missed, then switch the header to enforcing. Keep a report-only header alongside a stricter draft policy afterward so you can test each tightening step before it goes live.
In practice the sequence looks like this:
- Inventory the hosts your pages legitimately load from and send to. Browser developer tools and a crawl of your own templates are enough to start.
- Write the policy with those hosts, tight
default-srcandconnect-src, and no'unsafe-eval'or'strict-dynamic'unless a vendor forces it. - Ship it as report-only with a reporting endpoint. Report URI is one hosted option; the reports are plain JSON and can be collected by anything that accepts a POST.
- Triage the violations. Most will be legitimate sources you forgot. Some will be surprises, which is the point.
- Switch to enforcing once a week passes with no legitimate violations. Keep the reporting endpoint, because an enforced policy still reports, and those reports are your alarm.
Where CSP cannot help
A CSP limits where a script loads from and where it talks to. It does not limit what a script can read or change on the page it is running in. The Optimizely payload's address swapping modified page text, form fields and the clipboard, and no policy prevented that on any of the 159 sites. Cookie theft was only blocked where connect-src stopped the upload.
Two other controls fill that gap. Subresource Integrity (SRI) lets the browser verify a script's hash before running it, which stops a modified file cold, but it only works for scripts whose content does not change, and experimentation snippets change by design. The other control is not loading the script at all on pages where the damage would be worst. That is the argument behind keeping marketing tags off payment pages: a CSP reduces what a compromised tag can do, and removing the tag from checkout reduces it to nothing.