Skip to content

Dependency confusion checker

Free, no sign-up

Paste a package.json and find dependency names that do not exist on the public npm registry, where an attacker could register them. Sends package names only.

Read in your browser. When you press the button, only the dependency names go to registry.npmjs.org, one request per name.

This tool asks the public npm registry directly from your browser. It sends the names of the dependencies in the package.json you paste, one request per name. Versions, scripts and the rest of the file stay in your browser, and nothing is sent to HardenKit.

How to use the dependency confusion checker

  1. Paste your package.json, or load the example.
  2. Press the button: each dependency name is looked up on registry.npmjs.org.
  3. Read the findings: unscoped names that are not public come first.
  4. Move private packages into a scope you own and map that scope to your registry in .npmrc.

About this tool

Dependency confusion is an attack on projects that mix public and private packages. A company publishes an internal package, say billing-core, to its own registry. An attacker registers the same name on the public npm registry with a higher version number. Any install that asks the public registry, or a proxy that merges both and prefers the higher version, now downloads the attacker’s code. Alex Birsan showed in 2021 that this worked against dozens of large companies.

This checker takes the dependency names from your package.json and asks the public registry whether each one exists. An unscoped name that does not exist is the dangerous case: it is almost certainly private, and anyone can register it today. A scoped name that does not exist is safe only if the scope itself belongs to you on npmjs.com and your .npmrc sends that scope to your own registry.

Know the limits. The check sees names, not your registry configuration, so it cannot say whether an install would really go to the wrong place. A name that exists publicly may be the right package or may already be an impostor; the checker cannot tell which. It does not look at the lockfile or at nested dependencies. Treat it as a list of names to protect, not as proof of safety.

Sources

Questions

How do I prevent dependency confusion in npm?

Publish private packages under a scope that you have registered on npmjs.com, and add a line such as @your-org:registry=https://your-registry to .npmrc so that scope is only ever fetched from your registry. Commit the lockfile, and install in CI with npm ci, which follows the lockfile’s URLs and hashes.

Why are unscoped private names the risky ones?

The public registry gives an unscoped name to whoever asks first. A scope is different: only its owner can publish under it. So @your-org/billing-core cannot be taken by a stranger once you own @your-org, while billing-core can.

Does a lockfile protect me?

Largely, while it is used. npm ci installs exactly the URLs and hashes in the lockfile, so a new public package with the same name is not picked up. The exposure returns whenever dependencies are resolved afresh: npm install after a range change, a deleted lockfile, or a tool that ignores it.

A name is reported as existing publicly, but it is our private package. What now?

Then someone else holds that name on the public registry, and it may be an attack already. Look at the package on npmjs.com: who published it, when, and what its install scripts do. Check your install logs for where the package was fetched from, and move to a scoped name.

What does the checker send to npm?

One request per dependency name to registry.npmjs.org, which reveals that name and your IP address to npm. If the names of your internal packages are themselves confidential, do not use this page; check them from a machine you control with npm view.

Related tools