Dependency Confusion Possible

Internal package names are not reserved on public registries and builds can fetch from both, so an attacker can publish a same-named public package that is installed instead.

SeverityHigh
CVSS 3.18.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H Open in the calculator
CVSS 4.09.2 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-427: Uncontrolled Search Path Element
OWASP Top 10A08:2025 Software or Data Integrity Failures
MITRE ATT&CKT1195.001 Compromise Software Dependencies and Development Tools
CategoryInsecure Design

Description

The organisation uses private packages whose names are not registered on the corresponding public registry, and its package managers are configured so that a request for one of those names may be satisfied from the public registry. An attacker who learns an internal package name can publish a package with the same name and a higher version number publicly, and a developer workstation or build server may then install it in place of the internal package. This attack, known as dependency confusion or namespace confusion, has been demonstrated against many large organisations.

Typical causes are pip used with --extra-index-url, which consults the public index as well as the private one and may choose the higher version from either; npm packages without a scope, or with a scope that is not mapped to the private registry in .npmrc; NuGet configurations with several package sources and no package source mapping; and registry proxies that merge public and private feeds for the same names.

A malicious package installed this way runs the attacker's code on developer workstations and build servers, often immediately through install scripts, with access to source code, credentials and the build environment, and from a build server the attacker can steal pipeline secrets and insert code into the software the organisation builds and ships. The attacker has to learn an internal package name, and such names often leak through public repositories, JavaScript bundles and source maps, error messages and published manifests such as package.json. They then have to wait for a build or install to pick up the package, but need no access to the organisation's systems, and automated builds make the timing reliable once those conditions are met.

The weakness is identified by listing the private package names in manifests and lock files, checking whether each name is unclaimed on the public registry, and reviewing package manager and registry configuration. It can be confirmed without harm by checking which registry a clean install resolves each name from; publishing a test package to a public registry should only be done with explicit agreement.

Remediation

Make every internal package resolve only from the private registry:

  • Use a scope or namespace that the organisation owns for all internal packages, such as an npm organisation scope, and map that scope to the private registry in the project and user .npmrc files.
  • For Python, install from a single private index that proxies the public one, using --index-url rather than --extra-index-url, and configure the proxy so that internal names are never fetched from the public registry.
  • For NuGet, enable package source mapping so that internal package ID prefixes can come only from the private feed, and reserve the prefix on the public registry where possible.
  • Register placeholder packages, or claim the namespace, on public registries for internal names that cannot be scoped.
  • Commit lock files with integrity hashes and install with commands that honour them, such as npm ci, so that builds do not silently resolve new versions.
  • Configure registry proxies and repository managers so that private and public packages with the same name are never merged.

Confirm the fix by checking, for each internal package name, that a clean install resolves it from the private registry and that the name on the public registry is claimed or blocked.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Source Code and Supply Chain Findings

Every Source Code and Supply Chain finding