Your site runs other people's code: lessons from the Optimizely attack
In November an attacker slipped malware into a trusted A/B testing script, and it ran on Zoom, the BBC, HSBC, IKEA and 174 other organisations' sites for most of a day. None of those sites was hacked. They were running someone else's code, live, unreviewed. Here is what happened and how to stop it happening to you.
What happened
Optimizely Web is an A/B testing service. A site adds one line to every page that loads a JavaScript "snippet" from Optimizely's CDN. The snippet holds Optimizely's code, the customer's experiments, and an optional field called Project JavaScript: custom code the customer writes in the Optimizely dashboard, which runs on every page of their site.
On 16 November 2026 an attacker wrote their own code into the Project JavaScript of many customer projects. The rest of each snippet was untouched. It was still served from Optimizely's CDN, with Optimizely's certificate, from a host every affected site had already chosen to trust. The added code loaded a script from an attacker's domain. Later versions hid the address in base64, or carried the whole payload inline in case the attacker's domain was blocked.
Optimizely says an unauthorised party exploited a flaw in the Web Experimentation account signup flow to impersonate users on targeted customer accounts and insert the code. It says this was not a credentials breach, that fewer than 5% of its customers were affected, and that it closed the hole within three hours of detecting it.
Most of what we know comes from Scott Helme's investigation at Report URI, which we read in full. Report URI checked 1,611 Optimizely snippets it could find and found the code in 188 of them, belonging to 178 organisations, and says the real number is likely higher.
The day, in UTC
| Time | Event |
|---|---|
| 04:21 | First injected snippet seen (the BBC's) |
| 08:28 | The attacker's script first seen on bbc.com |
| 13:03 | Stolen cryptocurrency swept to exchanges |
| 13:43 | Card skimmer added to the payload |
| 17:13 to 17:57 | iPhone exploit kits added |
| 20:40 to 21:10 | Mass clean-up of the snippets |
| 23:11 | All infected snippets clean |
The attacker rebuilt the payload 26 times during the day, adding features as it went. The infected snippets were live for roughly 19 hours.
What the malware did
Every visitor got the same script, and every part of it was active at once:
- Wallet address swapping. It found cryptocurrency addresses on the page, in form fields, on the clipboard and in outgoing requests, and replaced them with the attacker's. Copy an address from an affected page and you could paste the attacker's. By the next morning the attacker's wallets had received about $7,150.
- Card skimming. It watched form submissions for a card number, expiry date and CVV, and sent them to the attacker. Cards typed into a payment provider's own hosted frame (Stripe, Adyen and similar) were out of its reach. Cards typed into the site's own form fields were not.
- Cookie and screenshot theft. Near wallet or payment wording it sent the page address, every cookie readable by JavaScript and a screenshot of the page.
- iPhone exploits. On iPhones and iPads it loaded known exploit chains (Coruna and DarkSword) aimed at iOS 18.6 and earlier.
Nobody knows how many cards, cookies or phones were taken. Only the crypto receipts are public, because they are on the blockchain.
The real lesson: it was not the CDN
The obvious reaction is "do not use CDNs", and it is half right. The CDN did nothing wrong: Report URI is explicit that it served exactly what it was given, and this was not cache poisoning. The weakness is a pattern, not a delivery method: your page loads code, live, from a server you do not control, that someone other than you can change at any time, and you never see the change.
That pattern covers analytics tags, A/B testing tools, chat widgets, ad scripts, tag managers, consent banners and "just paste this line" embeds. It also covers the libraries you load from a public CDN by URL. Any of them can change between one page view and the next.
So the rule is not "no CDNs". It is: no code runs on your pages that you have not seen, and nothing changes without your say-so. A CDN that serves your own reviewed files, with integrity checks, is fine. A vendor endpoint that serves whatever its dashboard holds today is not, wherever it is hosted.
Twelve controls
The first four decide what code you run. The next five tell the browser what that code may do. The last three are about noticing and limiting damage.
Decide what runs
1. Load less. Every third-party script is a standing invitation. List every script your pages load, who owns it, what it is for and who signed off on it. Remove anything nobody can justify. The safest script is the one you do not load.
2. Host it yourself and pin it. Download the library, review it, and serve it from your own domain under a versioned file name. An update is then a change you make on purpose, through your normal review, not something that happens to you overnight. For libraries from npm, commit the lock file, install with npm ci, and update deliberately rather than automatically.
3. Treat every update as a code change. A new version of a script is new code running on your customers' devices. Read the diff, or at least diff what you are about to ship against what you shipped last time. Give it a few days before adopting it, so others find the surprises first. "We always take the latest" is not a policy, it is an absence of one.
4. Use Subresource Integrity where you can. Add an integrity attribute with the file's hash to every <script> you load from another host. The browser refuses the file if a single byte changes. SRI only works on files that do not change, and a snippet like Optimizely's changes every time someone edits an experiment, so it could not have been protected this way. That is the point: if a vendor's script cannot be pinned, you are trusting the vendor's whole account security with your customers' cards. Make that a conscious decision, not a default.
Tell the browser what is allowed
5. Send a strict Content Security Policy. CSP is a response header that lists where a page may load scripts from and where it may send data. Report URI tested 256 of the affected organisations' sites: 68 had no CSP at all, 50 had one that allowed the attack anyway, and only 24 had one strict enough to block the payload. What those 24 had in common was a script-src that listed only the hosts they actually needed, so the attacker's domain was refused.
6. Do not allow unsafe-eval or unsafe-inline for scripts. The attacker shipped an inline copy of the payload that ran through eval when its own domain was blocked. At HSBC the CSP blocked the attacker's script and the data theft, but the inline copy still ran, because the policy allowed unsafe-eval, which Optimizely's own documentation tells customers to allow. If a vendor needs unsafe-eval, that is a cost of using that vendor.
7. Be careful with strict-dynamic. It tells the browser that any script loaded by a trusted script is trusted too. A compromised trusted script can then load anything it likes.
8. Restrict connect-src, form-action and frame-src. Stolen data has to leave the page. Seventeen of the affected sites still ran the payload, but their connect-src blocked the card, cookie and screenshot theft because the page could only send data to listed hosts. Wallet swapping still worked on those sites, because it happens inside the page, which is why this is a second line of defence and not a first.
9. Keep payment pages almost empty. Take card details in the payment provider's hosted fields or hosted page, not in your own form, so your page's scripts never see the number. Load no marketing, analytics or testing scripts on checkout and login pages at all. The skimmer in this attack could not read cards typed into a hosted payment frame.
Notice it, and limit the damage
10. Watch what your pages actually load. Run CSP in report-only mode first and collect the reports: they show every script, frame and connection your pages really make, including the ones you forgot. Then fetch your third-party scripts on a schedule, hash them and alert on any change. A new host in script-src reports, or a vendor file whose hash changed overnight, is exactly the signal this attack produced. Report URI's numbers show it would have been visible within minutes.
11. Make cookies unreadable to scripts. Mark session and authentication cookies HttpOnly, Secure and SameSite. The payload stole every cookie JavaScript could read; HttpOnly cookies were out of its reach.
12. Secure the vendor account like production. Anyone who can edit your tag manager or your A/B testing project can run code on every page of your site. Give those accounts single sign-on and two-factor authentication, the fewest editors possible, no shared logins, and an audit log someone actually reads. Turn off custom-code fields you do not use. Where you can, move experiments and tags to the server side, so the browser receives your page, not someone else's script.
If you use a third-party script today
- Inventory: list every script on your pages and who can change each one.
- Remove: drop what you do not need, especially on checkout and login pages.
- Self-host: move every library you can to your own domain, pinned and reviewed.
- Pin: add SRI to whatever must stay on another host and does not change.
- Policy: deploy a CSP in report-only mode this week, read the reports, then enforce it without
unsafe-eval. - Watch: alert when a third-party file changes or a new host appears.
- Accounts: lock down every vendor dashboard that can publish code to your site.
PCI DSS 4.0 already asks merchants for much of this on payment pages: an inventory of every script with a reason for each (requirement 6.4.3), and a way to detect unauthorised changes to the page (11.6.1). It is good practice on every page, not just checkout.
What we do on lancetek.com
This site loads one script, our own, from our own domain. It loads no analytics, testing, chat or advertising scripts, and the pages are plain files reviewed in git before each deploy. Two gaps showed up while we wrote this. The fonts come from Google Fonts, so the pages still depend on a third-party host for their styles. And the site does not yet send a Content Security Policy at all. Both are on our list, and they are the same advice as above: host it yourself, and tell the browser what is allowed.
Sources
- Scott Helme, Report URI: World's Largest Brands Infected With Malware Via Optimizely, 16 November 2026, updated 17 November. The source of the timeline, payload analysis, affected-organisation counts and the CSP survey.
- Optimizely: Web Experimentation Security Incident, status page, 17 and 18 November 2026. The source of the access vector and the under-5% figure.
We did not test the malware ourselves; every figure about it comes from the two sources above.