Skip to content
RCE Audit finding Beginner

NPM Dependency confusion. Unclaimed NPM Package and Scope/Org

The npm scope and package name used by the Timeswap project were unclaimed on the public registry, so an attacker could register them and publish a malicious package with a higher version number. Anyone installing the project's dependencies could then run the attacker's code on their machine.

ch13fd357r0y3r Follow

Originally disclosed on Code4rena

Submitted by ch13fd357r0y3r

I discovered an npm package and the scope of the package is unclaimed on the NPM website. This will give any User to claim that package and be able to Upload a Malicious Code under that unclaimed package. This results in achieving the Remote code execution on developers/users’ machine who depends on the timeswap repository to build it on local env.

Vulnerable Package Name: @timeswap-labs/timeswap-v1-core

Proof of Concept

  1. Create an Organization called “timeswap-labs”.
  2. Create a package called “@timeswap-labs/timeswap-v1-core” under “timeswap-labs” Organization.
  3. Attacker can able to upload malicious code on unclaimed npm package with a higher version like 99.99.99
  4. Now if any user/timeswap developer installs it by npm install package.json. The malicious pkg will be executed.

Till now “The Package is not claimed on NPM Registry, but it’s vulnerable to dependency confusion”. You can read more dependency confusion here: https://dhiyaneshgeek.github.io/web/security/2021/09/04/dependency-confusion/

Recommended Mitigation Steps

Claim the Scope name called “timeswap-labs” by following the above POC Step 1.

amateur-dev (Timeswap) confirmed and commented:

Created the organisation. Thank you.

0xleastwood (judge) commented:

I think this is an interesting attack vector and useful find!

I would normally mark findings unrelated to Solidity code as invalid, however, I think the issue here raises an interesting exploit where an attacker could inject malicious code into a smart contract dependency. As such, I think this is relevant and a valid attack path.


The original report as published on Code4rena, by ch13fd357r0y3r. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

How it worked

Root cause

Likely the project referenced an npm scope and package name that it had not registered, leaving the name free for anyone to claim.

Impact

An attacker could run arbitrary code on the machines of developers or users who install the project's dependencies, though this depends on them installing the package.

What the attacker needed

The npm scope and package name are unclaimed; A victim installs the project's dependencies

The fix

The project registered the npm scope, which prevents others from claiming it.

How it was found

  1. Create an organisation with the same name as the project's npm scope.
  2. Publish a package with the same name as the project's dependency under that organisation.
  3. Give the malicious package a very high version number so it is preferred.
  4. Wait for a developer to install dependencies, which executes the malicious package.

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 report has not been written yet. The Original tab links to the source.

When a project lists a dependency by name, the package manager fetches it from a public registry. If that name is not yet registered, anyone can register it and publish their own code under it. Because installers often pick the highest version, a malicious package with a very high version number can be pulled in and its install scripts run automatically.

What is RCE?

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

More from Timeswap contest

View all

The newest disclosed reports for this program.

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.