On November 16, code injected through Optimizely’s experimentation service ran on the pages of 178 organizations, according to Report URI. I think site owners should respond by writing a content security policy that names every host a page may load scripts from and every host it may send data to, and by applying it first to login and checkout pages.
What the numbers show
Optimizely said in its incident notice that an unauthorized party exploited a vulnerability in Experimentation and used it to add malicious JavaScript to some customer projects, and that it has fixed the vulnerability and removed the injected code. Our report on the incident has the detail.
The part I want security teams to read is the test that Report URI ran afterwards. It crawled 256 hosts belonging to the affected organizations and checked each content security policy (CSP) against what the injected code needed to load and to send data out. It found 68 organizations with no CSP at all. At 50, the policy allowed both the code and the data theft. At 17, the code ran but the policy blocked the outbound data. At 24, or 15%, the policy blocked the code.
Naming Optimizely’s delivery host as a trusted source did nothing here. “Allowing cdn.optimizely.com was never going to help,” wrote Scott Helme, the author of Report URI’s analysis. “The malicious code arrived from the trusted host itself.”
According to Report URI, the 24 protected sites had a restrictive script-src directive that listed only the hosts they needed, so the browser refused the attacker’s domain when the injected loader asked for it. Two settings let the code through elsewhere. One was strict-dynamic, under which any script inserted by a trusted script is trusted too. The other was unsafe-eval, which a fallback copy of the code used when the attacker’s domain was blocked.
My argument
A CSP that lists a vendor’s host tells the browser where code may come from. It says nothing about what that vendor serves tomorrow. I would write the policy on the assumption that any third-party script on the page will, one day, carry code its owner did not write. Three rules follow from that.
- List script hosts explicitly. On pages that load third-party tags, use a host list in
script-srcand leave outstrict-dynamic, so a vendor script cannot extend trust to a domain you have never heard of. - Restrict where the page can send data. Set
connect-srcto the hosts your application calls. The 17 sites in the middle of Report URI’s table had this, and it blocked the card, cookie and screenshot theft. - Turn on reporting. A policy that reports violations tells you when a trusted script has started asking for a new domain.
I would add one design choice that sits outside CSP. Report URI found that cards entered in hosted payment iframes, such as Stripe’s or Adyen’s, were out of the skimmer’s reach, while cards typed into a site’s own form fields were exposed. Taking card data in a cross-origin iframe keeps it away from every other script on the page.
The strongest objection
The case against this is real, and marketing teams will make it. Experimentation and tag management tools work by inserting scripts and evaluating code at run time. Report URI notes that Optimizely’s own documentation tells customers to allow unsafe-eval. A strict host list breaks the next tool someone adds and creates a ticket queue for the security team. A policy that blocks outbound data also did not stop the wallet address swapping in this incident, because that happens inside the page.
I accept all three points, and they are why I would start with a small set of pages. A login page and a checkout page rarely need an A/B test badly enough to justify running an outside vendor’s code beside a password or a card field. Give those pages their own strict policy and keep experimentation tags off them. Let the marketing pages keep a looser policy with a tight connect-src and reporting switched on. That split costs one policy file and a conversation with the team that owns the tags.
The in-page swapping is a fair limit. No browser policy stops a trusted script from rewriting text on the page it runs on. For that risk the control is in the vendor account. Review which users, API tokens and integrations can edit project code, and rotate their credentials, as Report URI advises Optimizely Web customers to do now.
What I would do this week
Pull the CSP header from your login and checkout pages and read it against Report URI’s two findings. If script-src contains strict-dynamic or unsafe-eval on a page that loads a third-party tag, plan to remove one or the other. If there is no connect-src, add one in report-only mode and read a week of reports before enforcing it.
We made a related argument in October, that a WAF rule for PHP2Shell is a patch-window control only. A host allowlist has the same limit. It filters by origin, and on November 16 the origin was one that 178 organizations had already approved.
Source: Report URI: World’s Largest Brands Infected With Malware Via Optimizely
Source: Optimizely Service Status: Web Experimentation Security Incident