npm Just Fixed Supply Chain Attacks. Then Someone Found a Loophole in 3 Weeks.
A malicious npm package called indexed-btree hid its loader inside the normal set() function rather than in install scripts, so it activated at runtime when applications called that function with a specific key. The package had 2 million weekly downloads and was linked to nine other packages, with command-and-control instructions polled from an Ethereum smart contract.
Published on medium.com
Cybersecurity
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
In June 2026, GitHub announced new npm security measures aimed specifically at supply chain attacks: blocking lifecycle scripts, requiring explicit approval for preinstall, install and postinstall, and preventing automatic dependency retrieval from remote URLs. The goal was to stop malware from executing during npm install.
By September 2026, a campaign had found a way around that model. The central package was indexed-btree, which impersonated sorted-btree, a legitimate B-tree implementation used by developers who need efficient data structures in JavaScript. The package had 2 million weekly downloads.
The important detail is where the malicious code lived. It was not in an install script. Checkmarx researchers found the malicious loader hidden inside BTree.prototype.set(), the main function that every user of the library calls constantly. When a developer installed indexed-btree, nothing suspicious happened: no preinstall hook fired, no lifecycle script ran, and npm v12's approval mechanisms saw nothing to approve. The malware only activated at runtime, when the application called set() with a specific key value.
Setup
This is a write-up of a third-party disclosure rather than a hands-on test, so there is no lab configuration to reproduce. The relevant preconditions, as described, are:
- A developer installs
indexed-btree, directly or as a transitive dependency. - The application uses the library normally and calls
set(). - The call uses the specific key value that triggers the loader.
- The host has outbound access to the Sepolia Ethereum test network, where the command-and-control contract is deployed.
The package itself was presented as a legitimate project: the operators created a legitimate-looking GitHub repository, populated a commit history and curated the developer account. The report does not give the exact trigger key value.
Finding it
The starting point was the Checkmarx disclosure. What made the finding notable was the contrast with earlier campaigns. The TanStack compromise in May and the PhantomRaven campaign both used install-time hooks, code that runs when you type npm install. The defence against those was straightforward: block the hooks and make developers explicitly approve any script that runs during installation.
indexed-btree made that defence irrelevant. The payload sat inside the library's normal code and executed when the library did its job. No amount of install-script blocking would catch it, because there was nothing to catch at install time. Checkmarx described it as "This is a well-built way to sneak past standard taint-analysis tools and most static scanners".

The image accompanies the point that the package had 2 million weekly downloads and that the malware hid inside a function every user calls constantly.
Exploitation
Step 1: Install the package
The victim installs indexed-btree, either directly or through a dependency. Nothing unusual happens at this stage. No preinstall hook fires, no lifecycle script runs, and npm v12's approval mechanisms have nothing to approve. The install-time controls introduced in June 2026 are not exercised at all.
Step 2: Call the poisoned function
The application uses the library as intended and calls BTree.prototype.set(). The loader is hidden inside that method. It only activates when set() is called with a specific key value, so ordinary use of the library does not trigger it.
Step 3: Fetch instructions from a smart contract
The malware does not contact a traditional command-and-control server. It polls an Ethereum smart contract on the Sepolia test network for instructions. This technique is called EtherHiding. Google's Mandiant team first documented it in 2023 while tracking a financially motivated group called UNC5142, and by 2026 Google reported that North Korea-linked actors had adopted it too.
The design matters because of takedown economics: a public blockchain cannot be seized, a hosting provider can be raided, and a domain registrar can be ordered to take down a C2, but an Ethereum smart contract, once deployed, exists as long as the network does.
Step 4: Decrypt the second stage
The malware uses X25519 key exchange to derive an AES key and decrypt a second-stage payload stored in the contract.
Step 5: Clean up
When the operators wanted to end the attack, the malware could delete its files and remove the malicious trigger from the package code to wipe its traces. This is why the absence of files on disk does not mean the host was never compromised.
Root cause
The design mistake is a mismatch between where defenders put controls and where the attacker put code. The June 2026 npm measures treated installation as the dangerous moment and gated the scripts that run then. The campaign moved the payload into ordinary library code that runs whenever the application uses the library, so the install-time gate had nothing to inspect.
Why the existing defences did not stop it:
- Lifecycle-script blocking and approval prompts only cover
preinstall,installandpostinstall. The loader was inBTree.prototype.set(), which is not a lifecycle script. - Static scanners and taint-analysis tools were, in Checkmarx's assessment, poorly suited to this construction.
- The trigger was conditional on a specific key value, so the malicious path is not exercised by normal use and is harder to observe.
- The C2 sat on a public blockchain, so domain or hosting takedowns had no target.
Impact
An attacker who gets a developer or build system to install indexed-btree and call set() with the trigger key can execute a second-stage payload on that host, with instructions delivered through a channel that cannot be taken down by conventional means. The package's 2 million weekly downloads mean the exposure was not limited to an obscure dependency.
Checkmarx linked the campaign to nine additional packages with similarly high download numbers. The report lists four of them:
| Package | Downloads |
|---|---|
btree-core |
1.9 million |
btree-leaderboard |
493,000 |
btree-range-store |
468,000 |
ordered-kv-index |
448,000 |
The operators reportedly accumulated 109 ETH through the campaign, roughly €231,000 at September 2026 prices.
The Cloud Security Alliance research note on the campaign adds a second dimension: AI and ML developer environments tend to aggregate unusually high densities of sensitive credentials, such as cloud provider keys, model-provider API tokens and vector database credentials, on build runners and developer workstations. A B-tree implementation does not sound like an AI supply chain risk, but if it runs on a machine that holds an API key, the package's name is irrelevant.
Fix
What it does record is guidance from the Cloud Security Alliance: "Runtime behaviour monitoring should be added as a complement to, not a replacement for, install-time script controls".
In practice, that means treating install-time gating as one layer and watching what dependencies do after installation as another: outbound connection monitoring, egress restrictions, and alerting on anomalous network behaviour from build runners and developer machines. The author's own changes are personal rather than product fixes: reading dependency names more carefully, including transitive ones and near-miss spellings of popular packages; paying attention to what runs at runtime rather than only at install time; and rotating credentials more often, on the reasoning that the attacker may have wiped traces before anyone notices.
Variants to test
- Runtime triggers in widely used methods. Pick a popular library and inspect its hottest code paths (setters, parsers, serialisers) for conditional branches keyed on unusual input values. A positive result is a branch that only activates for a specific argument and then performs network or crypto operations.
- Blockchain-based C2 resolution. On a host you control, watch for outbound traffic to public RPC endpoints or test networks from application processes. A positive result is a library making JSON-RPC calls to an Ethereum node during normal operation.
- Typosquat and near-miss names. Compare dependency names against popular packages for small spelling differences, and check whether the repository history and maintainer account look manufactured. A positive result is a package whose name is one character off a popular library and whose commit history is thin or recently fabricated.
- Transitive dependency review. Walk the full dependency tree rather than the direct dependencies, looking for packages that impersonate data-structure or utility libraries. A positive result is a transitive package with high download counts but no upstream project history.
- Credential exposure on build runners. Inventory which secrets are present on machines that run
npm installand application code. A positive result is cloud keys, model-provider tokens or database credentials reachable from a process that also loads third-party packages.
What happened, in plain words
In June 2026, GitHub announced a set of new safety measures for npm, the service most JavaScript developers use to download the building blocks (called packages) that their programs are made of. The measures were aimed at one specific kind of attack: supply chain attacks, where someone slips malicious code into a package that other people then download and run. The measures blocked lifecycle scripts (small scripts that a package can ask your computer to run automatically while it is being installed), required explicit approval for the three install-time scripts called preinstall, install and postinstall, and stopped packages from automatically pulling in more code from remote web addresses. The whole idea was to stop malicious code from running during npm install, the command that downloads and installs packages.
By September 2026, a campaign had found a way around that model. The central package was called indexed-btree. It was pretending to be sorted-btree, a legitimate and well-known package that implements a B-tree, which is simply an efficient way of storing and looking up sorted data inside a program. The package had 2 million weekly downloads.
The detail that matters is where the malicious code lived. It was not in an install script. Researchers at Checkmarx found the malicious loader hidden inside BTree.prototype.set(), the main function that every user of the library calls constantly. When a developer installed indexed-btree, nothing suspicious happened: no preinstall hook fired, no lifecycle script ran, and npm v12's approval mechanisms saw nothing to approve. The malware only activated at runtime, when the application called set() with a specific key value.
This article walks through that disclosure in the same order as the technical write-up, explaining each idea from scratch.
Setup
This is a write-up of a third-party disclosure rather than a hands-on test, so there is no lab configuration to reproduce. In other words, nobody in this story set up a test machine and ran the attack themselves for the article; the facts come from Checkmarx's public report. The relevant preconditions, as described, are:
- A developer installs
indexed-btree, directly or as a transitive dependency. - The application uses the library normally and calls
set(). - The call uses the specific key value that triggers the loader.
- The host has outbound access to the Sepolia Ethereum test network, where the command-and-control contract is deployed.
A few of those terms need unpacking for a complete beginner.
A dependency is another package that your package needs in order to work. A transitive dependency is a dependency of a dependency: you install package A, package A needs package B, and package B needs package C. You never chose C, but it ends up on your machine anyway. Think of it like a recipe that calls for a sauce, and the sauce's own recipe calls for a spice you have never heard of. You still end up buying the spice.
A host is simply a computer that runs software, whether it is your laptop, a server in a data centre, or a machine that builds software automatically.
Outbound access means the ability of that computer to make connections out to the internet. If a machine is locked down so it cannot talk to the outside world, malware on it has a much harder time receiving instructions.
Sepolia is a test network for Ethereum. Ethereum is a public blockchain, which is a shared record book that many independent computers keep copies of and agree on. A test network is a version of that record book used for experiments, where the money involved has no real value. A smart contract is a small program stored on that blockchain; once it is deployed, anyone can read it and interact with it, and nobody can quietly delete it.
Command-and-control, usually shortened to C2, is the channel through which malware receives orders from whoever controls it. The name comes from military language: a command centre tells units in the field what to do. In malware, the infected machine periodically asks the C2 server, "is there anything you want me to do?"
The package itself was presented as a legitimate project: the operators created a legitimate-looking GitHub repository, populated a commit history and curated the developer account. A repository is the online home of a software project, where its code and its history of changes live. A commit history is the list of saved changes, each with a message and a date. A brand-new package with one commit and no history looks suspicious; a package with months of plausible commits looks normal. The report does not give the exact trigger key value.
Finding it
The starting point was the Checkmarx disclosure. What made the finding notable was the contrast with earlier campaigns. The TanStack compromise in May and the PhantomRaven campaign both used install-time hooks, code that runs when you type npm install. The defence against those was straightforward: block the hooks and make developers explicitly approve any script that runs during installation.
indexed-btree made that defence irrelevant. The payload sat inside the library's normal code and executed when the library did its job. No amount of install-script blocking would catch it, because there was nothing to catch at install time. Checkmarx described it as "This is a well-built way to sneak past standard taint-analysis tools and most static scanners".
Two more terms from that quote. A static scanner is a tool that reads source code without running it and looks for suspicious patterns, like a proofreader who checks a document for known bad phrases. Taint analysis is a technique where the scanner tracks whether data from an untrusted source (the "taint") can reach a dangerous operation, the way you might trace whether dirty water from one pipe can reach a drinking tap. Checkmarx's point is that this particular construction was built to slip past both kinds of tool.

The image accompanies the point that the package had 2 million weekly downloads and that the malware hid inside a function every user calls constantly.
Exploitation
Step 1: Install the package
The victim installs indexed-btree, either directly or through a dependency. Nothing unusual happens at this stage. No preinstall hook fires, no lifecycle script runs, and npm v12's approval mechanisms have nothing to approve. The install-time controls introduced in June 2026 are not exercised at all.
Why this step matters: the June 2026 defences were built on the assumption that installation is the dangerous moment. A hook here is a point where the package manager pauses and lets the package run its own code. If the package never asks to run anything at install time, the guard has nothing to guard against. It is like a security check at a building entrance that only inspects bags: someone who walks in with nothing in their hands passes without a second look, even if they pick up something dangerous once inside.
Step 2: Call the poisoned function
The application uses the library as intended and calls BTree.prototype.set(). The loader is hidden inside that method. It only activates when set() is called with a specific key value, so ordinary use of the library does not trigger it.
A function is a named block of code that does one job and can be called whenever that job is needed. A method is a function that belongs to an object, which is a bundle of data plus the operations that work on it. BTree.prototype.set() is the method that stores a value under a key in the B-tree, the way you would put a folder into a filing cabinet under a label. A key is that label. A prototype in JavaScript is the shared template that all objects of a given kind inherit their methods from, so putting code in BTree.prototype.set() means every B-tree object in the program uses that code.
A loader is the small piece of code whose only job is to bring in and start the real malicious code, the second stage. It is the door handle rather than the room behind it.
The conditional trigger is the clever part. The malicious branch only runs when set() receives one particular key value. Normal use of the library never supplies that value, so the bad path stays dormant and is hard to observe.
Step 3: Fetch instructions from a smart contract
The malware does not contact a traditional command-and-control server. It polls an Ethereum smart contract on the Sepolia test network for instructions. This technique is called EtherHiding. Google's Mandiant team first documented it in 2023 while tracking a financially motivated group called UNC5142, and by 2026 Google reported that North Korea-linked actors had adopted it too.
To poll means to ask repeatedly at intervals, like checking your letterbox every few minutes rather than waiting for a delivery notification. A traditional C2 server is an ordinary web server somewhere on the internet, reachable at an address. The malware asks it for orders, and the defender's job is to find that server and shut it down.
The design matters because of takedown economics: a public blockchain cannot be seized, a hosting provider can be raided, and a domain registrar can be ordered to take down a C2, but an Ethereum smart contract, once deployed, exists as long as the network does.
A hosting provider is a company that rents out servers and internet connections. A domain registrar is a company that sells and manages domain names, the human-readable addresses like example.com. Both can be pressured by law enforcement or courts to cut off an attacker. A public blockchain has no single owner to pressure: thousands of independent computers keep copies of it, and the contract stays readable and usable as long as that network runs. That is the whole appeal of EtherHiding for an attacker.
Step 4: Decrypt the second stage
The malware uses X25519 key exchange to derive an AES key and decrypt a second-stage payload stored in the contract.
This sentence is dense, so here is each piece.
Encryption is scrambling data so that only someone with the right secret can unscramble it. The secret is called a key. Decryption is the unscrambling.
AES is a widely used encryption algorithm, a standard recipe for scrambling data.
X25519 key exchange is a method that lets two parties who have never met agree on a shared secret key over a channel that an eavesdropper can see, without ever sending the key itself. The everyday comparison is two people each mixing their own colour of paint into a shared pot in public: an observer sees the pots but cannot separate the mixture back into the original colours. The agreed key is then used with AES to decrypt the payload.
A payload is the part of the malware that actually does the damage, as opposed to the loader that fetches and starts it. A second-stage payload is one that is downloaded or decrypted after the first piece is already running, which keeps the initial package small and makes the full attack harder to spot in advance.
Storing the encrypted payload in the smart contract means the attackers can change what the malware does later without ever touching the package again. The package on npm stays the same; only the contents of the contract change.
Step 5: Clean up
When the operators wanted to end the attack, the malware could delete its files and remove the malicious trigger from the package code to wipe its traces. This is why the absence of files on disk does not mean the host was never compromised.
This is the part that should change how you think about evidence. If you inspect a machine after an attack and find nothing, that does not prove the machine was clean. It may mean the attacker tidied up. The everyday comparison is a burglar who puts the furniture back exactly where it was: the missing silverware is the only clue, and only if you know to count it.
Root cause
The design mistake is a mismatch between where defenders put controls and where the attacker put code. The June 2026 npm measures treated installation as the dangerous moment and gated the scripts that run then. The campaign moved the payload into ordinary library code that runs whenever the application uses the library, so the install-time gate had nothing to inspect.
Why the existing defences did not stop it:
- Lifecycle-script blocking and approval prompts only cover
preinstall,installandpostinstall. The loader was inBTree.prototype.set(), which is not a lifecycle script. - Static scanners and taint-analysis tools were, in Checkmarx's assessment, poorly suited to this construction.
- The trigger was conditional on a specific key value, so the malicious path is not exercised by normal use and is harder to observe.
- The C2 sat on a public blockchain, so domain or hosting takedowns had no target.
Impact
An attacker who gets a developer or build system to install indexed-btree and call set() with the trigger key can execute a second-stage payload on that host, with instructions delivered through a channel that cannot be taken down by conventional means. The package's 2 million weekly downloads mean the exposure was not limited to an obscure dependency.
A build system is a machine or service that automatically assembles and tests software, often running many installs a day without a person watching each one. That makes it an attractive target: it holds credentials and it runs code unattended.
Checkmarx linked the campaign to nine additional packages with similarly high download numbers. The report lists four of them:
| Package | Downloads |
|---|---|
btree-core |
1.9 million |
btree-leaderboard |
493,000 |
btree-range-store |
468,000 |
ordered-kv-index |
448,000 |
The operators reportedly accumulated 109 ETH through the campaign, roughly €231,000 at September 2026 prices. ETH is the currency of the Ethereum network.
The Cloud Security Alliance research note on the campaign adds a second dimension: AI and ML developer environments tend to aggregate unusually high densities of sensitive credentials, such as cloud provider keys, model-provider API tokens and vector database credentials, on build runners and developer workstations. A B-tree implementation does not sound like an AI supply chain risk, but if it runs on a machine that holds an API key, the package's name is irrelevant.
A credential is anything that proves who you are to a system: a password, a key, a token. An API is a way for one program to talk to another program over the internet, and an API token is the secret string that proves the calling program is allowed to do so. A cloud provider key is the same idea for renting computing power from a company like a cloud host. A vector database is a store for the numerical representations that AI systems use to compare and search text or images. A build runner is the machine that executes a build. A developer workstation is simply a developer's own computer.
The point is that these machines hold many secrets at once. A package that steals them does not need to be an AI tool itself; it only needs to run on the same machine.
Fix
What it does record is guidance from the Cloud Security Alliance: "Runtime behaviour monitoring should be added as a complement to, not a replacement for, install-time script controls".
Runtime behaviour monitoring means watching what a program actually does while it runs, rather than only checking it before it starts. The everyday comparison is a shop that checks bags at the door and also keeps cameras on the shop floor: the door check alone would have missed this attack entirely.
In practice, that means treating install-time gating as one layer and watching what dependencies do after installation as another: outbound connection monitoring, egress restrictions, and alerting on anomalous network behaviour from build runners and developer machines. Egress restrictions are rules that limit where a machine is allowed to connect out to. Alerting means setting up a system to notify someone when something unusual happens. Anomalous simply means out of the ordinary.
The author's own changes are personal rather than product fixes: reading dependency names more carefully, including transitive ones and near-miss spellings of popular packages; paying attention to what runs at runtime rather than only at install time; and rotating credentials more often, on the reasoning that the attacker may have wiped traces before anyone notices. Rotating credentials means replacing secrets with new ones on a schedule, so that a stolen secret stops working after a while.
Variants to test
These are things a defender can look for, written for someone starting out.
-
Runtime triggers in widely used methods. Pick a popular library and inspect its hottest code paths (setters, parsers, serialisers) for conditional branches keyed on unusual input values. A positive result is a branch that only activates for a specific argument and then performs network or crypto operations. A setter is a method that stores a value; a parser turns raw text into structured data; a serialiser turns structured data back into text for storage or sending. A conditional branch is an if-this-then-that in code. A crypto operation is anything that encrypts, decrypts or signs data.
-
Blockchain-based C2 resolution. On a host you control, watch for outbound traffic to public RPC endpoints or test networks from application processes. A positive result is a library making JSON-RPC calls to an Ethereum node during normal operation. An RPC endpoint is an address a program can send requests to in order to talk to a blockchain node. JSON-RPC is a standard format for those requests, a structured way of asking a remote program to do something.
-
Typosquat and near-miss names. Compare dependency names against popular packages for small spelling differences, and check whether the repository history and maintainer account look manufactured. A positive result is a package whose name is one character off a popular library and whose commit history is thin or recently fabricated. Typosquatting is registering a name that looks almost identical to a trusted one, hoping people mistype or misread it.
-
Transitive dependency review. Walk the full dependency tree rather than the direct dependencies, looking for packages that impersonate data-structure or utility libraries. A positive result is a transitive package with high download counts but no upstream project history. The dependency tree is the full map of everything your project pulls in, at every level.
-
Credential exposure on build runners. Inventory which secrets are present on machines that run
npm installand application code. A positive result is cloud keys, model-provider tokens or database credentials reachable from a process that also loads third-party packages. An inventory here means a written list of what secrets live where, so you can judge the damage if one machine is compromised.
Glossary
- API: a way for one program to talk to another program over the internet.
- API token: a secret string that proves a program is allowed to use an API.
- AES: a widely used standard algorithm for encrypting data.
- Alerting: setting up a system to notify someone when something unusual happens.
- Anomalous: out of the ordinary.
- B-tree: an efficient way of storing and looking up sorted data inside a program.
- Blockchain: a shared record book kept and agreed on by many independent computers.
- Build runner: a machine that automatically assembles and tests software.
- Build system: a machine or service that automatically builds and tests software.
- C2 (command-and-control): the channel through which malware receives orders from its operator.
- Cloud provider key: a secret that proves a program may rent computing power from a cloud company.
- Commit history: the list of saved changes to a software project, each with a message and a date.
- Conditional branch: an if-this-then-that in code that runs different paths depending on the input.
- Credential: anything that proves who you are to a system, such as a password, key or token.
- Crypto operation: anything that encrypts, decrypts or signs data.
- Decryption: unscrambling data that was encrypted.
- Dependency: another package that your package needs in order to work.
- Dependency tree: the full map of everything a project pulls in, at every level.
- Developer workstation: a developer's own computer.
- Domain registrar: a company that sells and manages domain names.
- Egress restrictions: rules that limit where a machine is allowed to connect out to.
- Encryption: scrambling data so only someone with the right secret can unscramble it.
- EtherHiding: hiding malware instructions in a public blockchain, such as an Ethereum smart contract.
- Ethereum: a public blockchain that can store programs called smart contracts.
- ETH: the currency of the Ethereum network.
- Function: a named block of code that does one job and can be called when needed.
- Hook: a point where the package manager pauses and lets a package run its own code.
- Host: a computer that runs software.
- Hosting provider: a company that rents out servers and internet connections.
- Inventory: a written list of what secrets live where.
- JSON-RPC: a standard format for sending structured requests to a remote program.
- Key (encryption): the secret used to encrypt and decrypt data.
- Key (data): the label under which a value is stored in a data structure.
- Lifecycle script: a script a package can ask your computer to run automatically during installation.
- Loader: the small piece of code whose job is to fetch and start the real malicious code.
- Method: a function that belongs to an object.
- npm: the service most JavaScript developers use to download and install packages.
- Outbound access: the ability of a computer to make connections out to the internet.
- Package: a reusable block of software that developers download and build on.
- Parser: code that turns raw text into structured data.
- Payload: the part of malware that actually does the damage.
- Poll: ask repeatedly at intervals.
- Prototype: in JavaScript, the shared template that objects of a kind inherit their methods from.
- Repository: the online home of a software project, where its code and change history live.
- Rotating credentials: replacing secrets with new ones on a schedule so stolen ones stop working.
- RPC endpoint: an address a program can send requests to in order to talk to a blockchain node.
- Runtime: the time while a program is actually running.
- Runtime behaviour monitoring: watching what a program does while it runs, not only before it starts.
- Second-stage payload: a payload fetched or decrypted after the first piece is already running.
- Sepolia: a test network for Ethereum, used for experiments with no real money.
- Serialiser: code that turns structured data back into text for storage or sending.
- Setter: a method that stores a value.
- Smart contract: a small program stored on a blockchain that anyone can read and interact with.
- Static scanner: a tool that reads source code without running it and looks for suspicious patterns.
- Supply chain attack: slipping malicious code into a package that other people then download and run.
- Taint analysis: tracking whether data from an untrusted source can reach a dangerous operation.
- Transitive dependency: a dependency of a dependency, which you never chose but still end up with.
- Typosquatting: registering a name that looks almost identical to a trusted one.
- Vector database: a store for the numerical representations AI systems use to compare and search text or images.
- X25519 key exchange: a method that lets two parties agree on a shared secret key over a channel an eavesdropper can see.