Dependency Confusion: A Namespace Takeover Story
The organisation's npm namespace was unclaimed, so anyone could register it and publish packages under the organisation's name. An attacker could then distribute malicious packages that developers might install, though the text does not show this actually happening.
Published on medium.com
In the world of software development, we often focus on securing our code, but sometimes the risks lie in the dependencies we rely on. I recently stumbled upon a bug that perfectly illustrates this, which I like to call “Dependency Confusion: Namespace Takeover.” Here’s how it all went down.
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 the organisation referenced an internal or private package namespace that was never registered on the public npm registry, leaving the name free for anyone to claim.
Impact
An attacker could publish packages under the organisation's name, which could lead to severe security issues if developers installed them, although the text does not demonstrate this occurring.
What the attacker needed
Organisation uses an unregistered public namespace; attacker can register that namespace
The fix
The organisation should register and control its namespace on the public registry, or otherwise ensure its package names cannot be claimed by outsiders.
How it was found
- Find a file on the target that lists package names associated with the organisation.
- Look up those package names on npmjs.com.
- Observe that the organisation's namespace returns a 404, meaning it is unclaimed.
- Register the namespace to confirm it can be taken over.
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.
Software projects often use small building blocks called packages, downloaded from a public library such as npm. If a company's name is not already registered there, someone else can register it and upload packages that look official. Other developers might then download and run that attacker's code without realising it is not the real thing.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.