Launch and other stacks

A script you trust was hijacked: the Optimizely lesson for small apps

On 16 November 2026 an attacker wrote code into Optimizely customers’ projects, and at least 178 organisations served it to their visitors from Optimizely’s own CDN for most of a day. Your app probably doesn’t use Optimizely, but it likely loads analytics, a chat widget or a tag manager in the same way, and each of those can read every form on your page. Three things limit the damage: know which outside scripts run, add a Content-Security-Policy that names where data may go (we tested it below), and keep outside scripts off sign-in and payment pages.

TL;DR

  • A script tag from another site runs with full power on your page: it can read what visitors type and send it anywhere.
  • In the Optimizely case the bad code came from a host the victims trusted, so “only load scripts from vendors we trust” didn’t help.
  • In our Chrome test, a script-src allow-list alone let a script send data out four ways. default-src 'self' stopped all four.
  • The injected code in one sampled variant pulled a second script from an unrelated domain, which a tight script-src blocks.
  • The free headers check now flags pages that load outside scripts with no limit on where they send data (PL-040).

This guide is for founders whose app was built with Lovable, Bolt, Cursor or Claude Code, and for anyone who adds analytics, A/B testing or chat widgets to a site by pasting a snippet. The incident facts come from Unit 42 (17 Nov 2026) and Socket (18 Nov 2026); we ran the browser test ourselves on 22 Nov 2026.

What happened on 16 November

Optimizely Web Experimentation lets customers add their own code to a project in a field called Project JavaScript. That code is bundled into the snippet every visitor’s browser downloads from Optimizely’s CDN. According to Optimizely, as reported by Socket, an attacker used a flaw in the account sign-up flow to get at that field in other customers’ projects and inserted malicious code.

  • Scale: Scott Helme of Report URI counted 188 infected snippets belonging to 178 organisations. Unit 42 says “at least 178”.
  • Payload: Unit 42 lists three behaviours: swapping cryptocurrency wallet addresses, skimming card details from checkout forms, and trying to deliver exploit kits to iPhones and iPads.
  • How it loaded: in the variant Socket sampled, the injected code loaded a second script from an unrelated domain. Other variants carried the payload inline or hid the address in base64.
  • Timeline: Report URI saw the snippets it monitored cleaned by 23:11 UTC on 16 November. Unit 42 says Optimizely patched the flaw, removed the code and secured affected accounts early on 17 November.

The point for small apps. The victims did nothing wrong that day. They loaded a script from a vendor they had chosen, and the vendor was hijacked. Picking trusted vendors is necessary, but it can’t be the whole defence.

Step 1: list the scripts your app runs

Open your live site, not the editor preview, and run this in the browser console. It lists every script the page has loaded so far, including ones a tag manager added after the page arrived:

list-scripts.js
// Paste into DevTools → Console on your live site, after using the page for a moment.
const mine = location.hostname.split('.').slice(-2).join('.');
const hosts = {};
for (const e of performance.getEntriesByType('resource')) {
  const h = new URL(e.name).hostname;
  if (!h.endsWith(mine)) (hosts[h] ||= new Set()).add(e.initiatorType);
}
console.table(Object.entries(hosts).map(([host, t]) => ({ host, types: [...t].join(', ') })));
// "script" = code that runs on your page. "fetch" / "xmlhttprequest" / "img" = where the page sends requests.

For each script host, ask: do we still use this, and does it need to run on every page? Old analytics tags and abandoned experiments are common. Every one you remove is one less vendor whose breach becomes yours.

Step 2: what a Content-Security-Policy really stops (our test)

We built a shop page that loads a script from a second local server. The script grabs a fake card number and tries to send it back four ways: fetch, an image request, navigator.sendBeacon and a WebSocket. We loaded the page in Chrome with four different policies and counted what reached the second server.

Policy on the pageSends that got out
No Content-Security-Policy4 of 4 (fetch, image, beacon, WebSocket)
script-src 'self' <the script’s host> only4 of 4
default-src 'self'; script-src 'self' <the script’s host>0 of 4
The same plus connect-src 'self'0 of 4

The lesson is in the second row. Many guides stop at script-src, which controls what may load. It says nothing about where loaded code may send data. That is connect-src (fetch, XHR, WebSocket, beacons) and img-src (image requests), or default-src when those two aren’t set.

Two honest limits. First, a policy doesn’t stop a script sending data to a host you allowed, so allow only what you need. Second, a script can still move the visitor to another page or submit a form, so a policy narrows the exits rather than closing all of them.

Step 3: write the policy

Start from the hosts you listed in step 1. A typical Supabase app with one analytics script looks like this:

Content-Security-Policy
Content-Security-Policy: default-src 'self';
  script-src 'self' https://cdn.your-analytics.com;
  connect-src 'self' https://YOUR-PROJECT.supabase.co wss://YOUR-PROJECT.supabase.co https://api.your-analytics.com;
  img-src 'self' data: https://YOUR-PROJECT.supabase.co;
  frame-ancestors 'self'

Send it as one line. Ship it first as Content-Security-Policy-Report-Only for a few days and watch the console for blocked requests, then switch to the enforcing header. Where to set headers on Vercel, Netlify, Cloudflare and Lovable is in the PL-040 fix. On hosts where you can’t set headers, a <meta http-equiv="Content-Security-Policy"> tag in index.html works for everything above except frame-ancestors.

Avoid * and bare schemes like https: in connect-src and img-src: they allow every server and undo the point. Some vendors document the hosts their snippet needs; use that list, not a wildcard.

Step 4: keep outside scripts off the pages that matter

Unit 42’s advice after the incident was to remove tags that aren’t essential from sensitive pages and to take payments inside hardened cross-origin frames. For a small app that means:

  • Payments: use your provider’s hosted checkout or hosted card fields (Stripe Checkout or Elements, for example). The card number is typed into the provider’s frame, which scripts on your page can’t read.
  • Sign-in and account pages: no A/B testing, heatmaps or session recorders there. They don’t need them, and these pages hold passwords and tokens.
  • Tag managers: a tag manager lets anyone with access to its dashboard add code to your site without a deploy. Limit who has that access, and turn on two-factor sign-in for it.

Check your site

The free headers check now includes PL-040: it lists the scripts your home page loads from other sites and flags the page if no policy limits where they can send data. If one of those hosts had a public compromise in the last 90 days, it says so and rates the finding medium. It reads one public page, the way a visitor’s browser does; scripts a tag manager adds later need the console snippet above.

Questions people ask

Would Subresource Integrity (SRI) have stopped this?

Not for a snippet like Optimizely’s, which changes whenever the customer edits their project, so no fixed hash can be pinned. SRI is a good fit for versioned library files from a public CDN, where the file never changes.

We don’t use Optimizely. Does this matter to us?

Yes, if your page loads any script from another site. The pattern, one vendor compromised and every customer’s visitors hit at once, has happened before with other script providers, and it will happen again.

Will a strict policy break my app?

It can, which is why you start in report-only mode. The console then lists each blocked request, and you add the hosts you really need. Supabase apps usually need the project’s https:// and wss:// addresses in connect-src.

Our visitors may have been on an affected site. What should we tell them?

If you ran Optimizely between 15 and 17 November, check your project’s change history and Optimizely’s notice to you before saying anything. If customer data may have left, our first hour after a leak runbook covers timelines and reporting clocks.

Sources

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your app for this, free.

Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.

First app free, fixes includedNever touches your database

Written by Manraj Singh Dhillon. Last checked 22 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.