Security · Retrospective
The npm attack that swapped wallet addresses, and why I pin dependencies

Two npm incidents in September are still on my mind this month, as the registry's response to them starts to take effect.
On 8 September, new versions of 18 widely used packages, among them chalk and debug, were published from the account of a maintainer who had been phished with an email about his two-factor authentication. Aikido began flagging them at 13:16 UTC. The added code targeted browsers. It hooked fetch, XMLHttpRequest and wallet interfaces such as window.ethereum, and replaced destination addresses with attacker addresses chosen to resemble the real ones.
A week later came Shai-Hulud. GitHub, which runs npm, was notified on 14 September of a self-replicating worm that spread through compromised maintainer accounts by injecting post-install scripts. It collected credentials such as GitHub tokens and cloud keys, then published infected versions of its victims' other packages. GitHub removed more than 500 packages. On 23 September CISA advised organisations to pin npm dependencies to known safe releases published before 16 September.
Pinning is advice I have followed since at least 2020, for quieter reasons.
A version range is a standing permission
In April 2020 I published @trivechain/triveasset-protocol to npm. Its package.json asks for debug at ^4.1.1. The caret accepts any 4.x release from 4.1.1 upwards. The malicious debug 4.4.2, which the registry timestamps at 13:12 UTC on 8 September, falls inside that range.
A range is a permission given in advance to whoever publishes the next version, including someone holding a stolen session. I want to remember that the next time I type a caret.
What npm ci does
The day before that package went to npm, I committed "Use package-lock since I am using npm ci to enforce version". The commit replaced a Yarn lockfile with package-lock.json, and the CI configuration installs with npm ci.
npm ci installs exactly what the lockfile records. If the lockfile and package.json disagree, it stops with an error instead of quietly updating, and it never rewrites either file. In that lockfile debug is 4.1.1, with an integrity hash of the exact package. A build stays on 4.1.1 until someone changes the lockfile, and that change is a commit someone can read.
That is the real reason I pin. An update becomes a decision with an author and a date, not a side effect of running an install on the wrong afternoon.
What a lockfile does not protect against
- The moment you lock. Anyone who updated during the hours the bad versions were live would have written them into their lockfile, with valid hashes. A lockfile preserves a decision. It does not check it.
- Your users' installs. npm's documentation says that
package-lock.jsoncannot be published and is ignored anywhere other than the root project. Anyone who installs my protocol package resolves^4.1.1for themselves. For a library, the range is what ships. - Commands that fetch at run time.
npxdownloads a package that is not already installed, at whatever version is current. My February post on Prettier and Husky tells readers to runnpx husky-init. I would now pin a version in that command. - Install scripts.
npm cistill runs lifecycle scripts, which is how the worm ran. The--ignore-scriptsflag turns them off. Some packages need them, and it is worth knowing which of yours do. - The person reading an address. The 8 September code picked addresses that looked like the originals, which defeats a quick glance. For a transfer of any size, compare the whole address on the signing device.
What I would add now
- A delay before adopting new versions. pnpm 10.16, released on 12 September, added a
minimumReleaseAgesetting. Its release notes say that in most cases such attacks are discovered quickly and the malicious versions removed within an hour. Waiting a day trades a little freshness for the time the community usually needs to notice. - Lockfile changes reviewed like code. A pull request that changes hundreds of lines of
package-lock.jsondeserves the attention I would give a change to a contract. - Short-lived, phishing-resistant publishing credentials. On 29 September GitHub set out a timetable: from October, new write-enabled granular tokens default to seven days and new TOTP setups are disabled in favour of WebAuthn and passkeys, with classic tokens to be revoked by mid-November. A six-digit code can be typed into a convincing fake page and relayed. A passkey only answers the real site.
For anyone building wallets or decentralised applications, September was a reminder that the code which shows a user an address is part of the wallet's security, whoever wrote it. A pinned, reviewed dependency tree will not stop every attack. It does mean that when something changes in my builds, I chose it.