DEV Community

Cover image for A Third-Party Script Can Rewrite Your Deposit Address
Azalea
Azalea

Posted on

A Third-Party Script Can Rewrite Your Deposit Address

On November 16, people who visited Ledger's website could copy a crypto address from the page and paste someone else's. Ledger's servers weren't breached. Neither were the servers of HSBC, the BBC, Salesforce, Zoom or IKEA, which had the same problem that day. The code came from Optimizely, the A/B testing tool all of them load on their pages.

I write a lot here about what crypto apps should check before a user presses "Send". This incident is a good reminder that the page itself can be the weak point, even when your own code is fine. If you build anything that shows a wallet address, a payment form or a withdrawal screen, it's worth going through what happened and what it changes.

How Optimizely runs on a page

Optimizely Web Experimentation works the way most A/B testing tools do. You add one script tag to your site, and that snippet loads on every page. Marketing teams then change headlines, layouts and copy from the Optimizely dashboard without touching the codebase.

Two details matter here:

  1. The snippet is served from Optimizely's infrastructure, not from your servers.
  2. Projects have an optional field for custom JavaScript. Whatever goes into that field runs in every visitor's browser, with the same access to the page as your own code.

That's the feature that makes these tools useful. It's also why a compromised vendor account is as good as a compromised website.

What happened on November 16

According to Optimizely, an unauthorized party exploited a vulnerability in its Experimentation account signup flow. That gave them access to customer projects, and they added malicious code to the custom code field. Visitors' browsers then loaded it from a domain those sites already trusted (Bitcoin.com, CoinDesk).

Scott Helme of Report URI, a service that monitors scripts running on websites, checked 1,611 Optimizely snippets and found 188 infected ones across 178 organizations. The names in the reports include Ledger, HSBC, the BBC, CNN, Salesforce, Zoom, GitLab, IKEA, Equifax and Air France-KLM. CoinDesk counted six crypto or trading businesses among them (Ledger, IG Group, OANDA's Coinpass, Interactive Investor, TMS Brokers and Betashares) and about 32 banks and financial companies.

The payload wasn't a single trick. It was a kit:

  • Address swapping. It looked for crypto addresses in form fields and in copied text and replaced them with the attacker's.
  • Card skimming. It captured card numbers typed into payment forms.
  • Session theft. It copied cookies and took screenshots.
  • Device attacks. It served exploit kits to older iPhones and iPads.

Timeline (UTC)

The rough sequence, pieced together from Bitcoin.com and Shattered.io's summary of StepSecurity's analysis. Some timestamps come from secondary reporting, so treat them as approximate.

Time Event
Nov 9 Two domains later tied to the attack are registered
Nov 13 Hudson Rock sees similar code on three other web services
Nov 16, 05:23 The payload server's domain is registered
Nov 16, 08:10 The first crypto clipper build appears
Nov 16, 13:03 Stolen funds are swept to exchanges
Nov 16, ~17:56 The last payload variant goes live after several edits
Nov 16, 20:40–21:10 Mass cleanup of infected snippets, Ledger's at 20:41
Nov 16, 21:52 One infected snippet is still live

What the companies said

Optimizely said it blocked access to the vulnerable path, deployed a fix, removed the injected code, ended active sessions, revoked tokens, reset access for affected accounts and notified customers. It's still investigating.

Ledger said the issue on its site is fixed and that it doesn't affect Ledger devices or users' private keys (The Block). That's consistent with the analyses: the attack hit the website layer, not the signing device.

How much was stolen

On-chain, not much. Report URI put the amount that reached attacker wallets at about $7,000 by Monday evening. StepSecurity's update the next day estimated about $6,600 across eight attacker wallets, four of which never received anything. Card numbers, cookies and phone compromises don't show up on-chain, so the real damage is unknown and probably a lot higher.

Why this hits crypto products harder

A stolen card can be blocked and the charge disputed. A crypto transfer to a swapped address is final. There's no chargeback, and the user usually notices only when the funds don't arrive.

The attack also abuses the exact habit we teach. Don't type addresses by hand, copy them from a source you trust. On November 16 the trusted source was the official website of a hardware wallet company.

And nothing looks broken. The page renders, the address looks like an address, the transaction confirms. From the user's side, everything worked.

Why the usual defenses didn't stop it

Content Security Policy

CSP lets you list which origins may serve scripts. It's the first thing people mention after an injection, and it's worth having. But here the malicious code came from Optimizely's own domain, which every affected site had allowed on purpose. A policy like this would have let it through:

Content-Security-Policy: script-src 'self' https://cdn.optimizely.com
Enter fullscreen mode Exit fullscreen mode

CSP still helps against other injections, and its reporting endpoint can tell you when unexpected scripts show up. It just can't protect you from a domain you've chosen to trust.

Subresource Integrity

SRI pins a script to a known hash, so the browser refuses to run it if the file changes:

<script
  src="https://cdn.example.com/lib.min.js"
  integrity="sha384-..."
  crossorigin="anonymous"></script>
Enter fullscreen mode Exit fullscreen mode

That works for a library version that never changes. An experimentation snippet changes every time someone edits a test, which is the whole point of it, so in practice nobody pins it. It's a useful exercise to list which third-party scripts on your site can't be pinned. Those are the ones that can change without a deploy.

What to change if your product shows an address

1. Keep marketing scripts off sensitive pages

Deposit addresses, withdrawal forms and payment fields don't need A/B tests. The simplest fix is to not load experimentation, analytics or chat widgets there at all.

If you load them from your own code, a route check is enough to start:

const SENSITIVE_PATHS = ['/deposit', '/withdraw', '/checkout', '/send'];

const isSensitive = SENSITIVE_PATHS.some((path) =>
  window.location.pathname.startsWith(path)
);

if (!isSensitive) {
  loadExperimentScript(); // your Optimizely / analytics loader
}
Enter fullscreen mode Exit fullscreen mode

Then back it up with a strict policy on those routes, so a script added through a tag manager later can't slip in:

Content-Security-Policy: script-src 'self'; connect-src 'self' https://api.yourapp.com; frame-ancestors 'none'; report-to csp-reports
Enter fullscreen mode Exit fullscreen mode

A stronger option is to move these flows to a separate subdomain, like pay.yourapp.com, that only ever loads your own code. The OWASP cheat sheet on third-party JavaScript goes deeper into isolation options like this one.

2. Know what runs on those pages

Keep a short inventory of third-party scripts per route, and monitor it. CSP reporting, a script monitoring service or a scheduled check that compares the scripts on /deposit against an allowlist all work. This campaign was spotted by people who watch scripts across many sites, not by the affected sites.

3. Give users a second way to check the address

Long hex strings are hard to compare. Split the address into groups so people can actually read it:

function groupAddress(address, size = 4) {
  return address.match(new RegExp(`.{1,${size}}`, 'g')).join(' ');
}

groupAddress('0x52908400098527886E0F7030069857D2E4169EE7');
// "0x52 9084 0009 8527 886E 0F70 3006 9857 D2E4 169E E7"
Enter fullscreen mode Exit fullscreen mode

Show a QR code next to it, and where you can, confirm the address in a place the web page can't touch: the hardware wallet screen, the mobile app, or an email.

4. Treat pasted addresses as untrusted

If your app accepts an address from the clipboard (the paste event gives you the raw text), show it back clearly before sending, and warn when it doesn't match anything the user has saved:

addressInput.addEventListener('paste', (event) => {
  const pasted = event.clipboardData.getData('text').trim();
  const known = savedAddresses.includes(pasted);

  showConfirmation({
    address: groupAddress(pasted),
    warning: known ? null : 'This address is not in your saved list. Check every character.',
  });
});
Enter fullscreen mode Exit fullscreen mode

To be honest about the limits: a malicious script running on the same page can patch these checks too. They're speed bumps for clipboard malware on the user's device. The real fix for this incident is point 1.

What users can do

For the person sending money, the habit that would have caught this is simple: check the whole address before you confirm, not just the first and last few characters. Clipboard malware and address poisoning both work best on people who only glance at the edges. This wallet security checklist covers it, along with a few other habits worth having, like keeping a separate low-balance wallet for unfamiliar dApps.

If you sent crypto on November 16 after copying an address from a big brand's website, compare the destination with the address you meant to use.

The takeaway

Your page is only as safe as the most permissive script on it. If that page shows a deposit address, your A/B testing tool has the same power over it as your own code. Decide which pages actually need it.

Sources

Top comments (0)