Skip to content

Lesson 6 of 9 · 25m

Dependency Verification and Dependency Confusion

Verify package integrity and origin, prevent namespace confusion, configure private registries safely, and investigate suspicious resolution changes.

Dependency confusion works because package managers are obedient. Ask for a package name and they will resolve it according to rules many teams never inspect. If your private package name exists publicly, or your registry priority is wrong, the package manager may fetch attacker-controlled code while producing output that looks perfectly normal.

Understand resolution order

Read the package manager configuration in every environment, not just the repository:

npm config get registry
pip config list
go env GOPROXY GONOSUMDB GOPRIVATE

Typical risk controls look like this:

# .npmrc
registry=https://registry.npmjs.org/
@acme:registry=https://npm.pkg.example.internal/
//npm.pkg.example.internal/:_authToken=${NPM_TOKEN}
strict-ssl=true

Private names should be scoped or namespaced where the ecosystem supports it. Unscoped internal names like billing-utils are squatting targets.

Lockfiles and checksums catch drift — sometimes

Integrity verification matters when package content changes after resolution:

npm ci
pip install --require-hashes -r requirements.txt
go mod verify

npm ci installs from the lockfile rather than solving a fresh dependency graph. --require-hashes refuses unpinned packages. go mod verify checks module cache content against recorded hashes. These are necessary controls, but they do not protect you if the first approved lockfile entry already names a malicious package.

Private registry hygiene is boundary control

A proxy registry can cache public packages and host private packages, but only if routing is unambiguous:

acme-private/*        internal only, never proxy upstream
@acme/*               internal namespace only
public package names  upstream cache, immutable version content

If the same name can exist in both places, define priority explicitly and alert when both copies exist. Silent fallback is an attack surface.

Investigate resolution changes like incidents

A lockfile diff is often the first visible artifact of a supply-chain attack:

-"resolved": "https://npm.pkg.example.internal/billing-utils/-/billing-utils-2.1.4.tgz"
+"resolved": "https://registry.npmjs.org/billing-utils/-/billing-utils-9.9.9.tgz"

That is not a routine version bump. A private package suddenly resolving publicly, a huge version jump, an unknown maintainer, a new install script, or a new transitive dependency with network access all deserve scrutiny.

Use allowlists carefully

Allowlisting every transitive version creates operational pain and encourages blanket approval. Better controls are tiered: strict verification for release-critical dependencies, automated review for routine updates, and sandboxed installation for unfamiliar packages. The important thing is that unusual resolution paths page a human before credentials are exposed.

Field notes

  • Remove unused private names from public registries only after checking whether legitimate systems still resolve them.
  • Publication of a placeholder private package is not always safe; it can create confusion in future merges and legal ownership disputes.
  • Tokens in .npmrc, pip.conf, or Docker config often have broader rights than developers assume.
  • CI runners must use the same registry configuration as release builders, or validation is not testing the shipped resolution path.
  • Dependency confusion frequently looks like a typo or one-line config mistake. Preserve logs before fixing it.

Was this lesson helpful?

Sign in to rate