Skip to content
RCE Write-up Intermediate

npx Used Confusion and It’s Super Effective

The npx command resolves a missing binary name by fetching and executing a package of the same name from the public npm registry. An attacker could register an unclaimed package name and achieve remote code execution when a developer or automated agent runs npx outside the project root.

V.M Follow

Published on depi.security

When it comes to Software Supply Chain Security, we cannot not talk about dependency confusion.

V.M., on depi.security

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely npx assumes that an unresolved binary name is also a package name and installs it from the public registry without verifying ownership.

Impact

An attacker could achieve remote code execution on developer machines and automated agents, and the authors received a $30,000 bounty after demonstrating data exfiltration.

What the attacker needed

Npx run outside the project root; binary name unclaimed on public registry; attacker registers the package name

How it was found

  1. Find a package.json that references a binary executed by npx.
  2. Check that no package with that binary name exists on the public npm registry.
  3. Register the unclaimed package name on the public registry with a malicious payload.
  4. Run npx outside the project root so the local binary is not found.
  5. npx fetches and executes the attacker's package from the public registry.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When you run a tool with npx, npm first looks for it on your computer. If it cannot find it, npm assumes the tool's name is also a package name and downloads that package from the public registry. An attacker can register a package with that name and run their own code on your machine.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by V.M

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.