Safeguard
Supply Chain•

What does a lockfile protect against in a supply chain attack?

A lockfile blocks surprise upgrades and some package swaps. It does not vet the version it records. A clear table of what it covers and what it misses.

Safeguard Security Team
3 min read

A lockfile records the exact versions and integrity data of your dependencies, so installs are repeatable and a new upstream release cannot slip in unnoticed. It does not check that the recorded version is safe, and it does not stop an attack that happens before the version was locked.

Definition

A lockfile, such as package-lock.json, records the resolved dependency tree. The npm ci command installs from it, requires that it exists, and exits with an error if it does not match package.json, instead of updating it. Pip has a related mechanism: the require hashes option checks each requirement against a hash for repeatable installs.

What it covers

ScenarioDoes a lockfile help?
A maintainer publishes a bad new version after you lockedYes, if installs use the lockfile and you have not updated
A package is swapped on the registry under the same versionOften, when integrity hashes are recorded and checked
Dependency confusion when adding a new internal nameNot on first resolution
You update to a bad versionNo, it records the bad version
A malicious build of a vendor productNo, it is outside the package manager
A bad version already in the lockfileNo

Using it well

  1. Commit it. For applications, commit the lockfile so everyone and every build gets the same tree.
  2. Install from it in CI. Use the lockfile-strict install command, not the one that updates it.
  3. Review lockfile changes. A lockfile diff in a pull request is where a surprise dependency shows up. GitHub's dependency review shows added, removed and updated dependencies on pull requests that change manifests or lock files, including indirect ones.
  4. Treat updates as events. Each update is a decision, with a short delay and a look at what changed.

What it cannot do

It cannot judge intent. If the version you lock is malicious, the lockfile makes your install reproducibly malicious. That is why a lockfile pairs with monitoring and an inventory that can flag a version after the fact.

For buyers

When you evaluate a scanner, check that it reads lockfiles to get exact transitive versions, since manifest ranges alone do not tell you what actually shipped.

Try it yourself

Open the demo and look at how exact component versions drive the findings you see.

Click through it at your own pace, or open it full screen.

Where Safeguard fits

Safeguard offers SBOM and dependency scanning that reads your project's dependency data, and gates that can run on pull requests. The free scan is a quick way to see a lockfile turned into an inventory.

Quick check

Should libraries commit lockfiles?

Practice differs by ecosystem. Applications should commit them. Check your ecosystem's guidance for libraries.

Does npm install behave like npm ci?

No. npm install can update the lockfile, while npm ci errors on a mismatch and never writes to it.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.