Safeguard
Supply Chain•

Should a golden path template ship a committed lockfile?

Yes: a golden path template should commit a lockfile and make CI install from it. Here is how npm, Gradle and pip each enforce exact dependency versions.

Safeguard Security Team
4 min read

Yes. A golden path template should commit a lockfile and make CI install strictly from it, so every build resolves the same dependency versions that were reviewed. Without one, a new release can change what you ship between two builds of the same commit.

What a lockfile gives a platform team

A lockfile records the exact resolved versions, including indirect dependencies. For a platform team, that turns "what is in this service?" from a guess into a file you can read, diff and scan. It also makes a pull request that changes dependencies visible, because the lockfile diff shows every version that moved.

The template matters because new services copy it. If the first commit has no lockfile, most teams never add one.

How each ecosystem enforces it

EcosystemCommit thisCI command or settingWhat happens on drift
npmpackage-lock.jsonnpm ciExits with an error if the lock and package.json disagree
Gradlelock files from dependency lockingDependency locking on, STRICT mode in CIBuild fails on mismatched resolution; STRICT also fails if lock state is missing
piprequirements.txt with hashes--require-hashesInstall fails if a hash does not match

The npm documentation says npm ci requires an existing package-lock.json or npm-shrinkwrap.json, and that if dependencies in the lock do not match package.json, it exits with an error instead of updating the lock. That is the behavior you want in CI.

Gradle's documentation warns that dynamic versions such as 1.+ can cause builds to change unexpectedly, and describes dependency locking, with a STRICT mode that also fails when a locked configuration has no lock state. You can update specific entries with the --update-locks flag.

pip's hash-checking mode, added in pip 8.0, uses hashes embedded in a requirements file to protect against remote tampering and network issues. It is all or nothing: once on, every requirement needs a hash.

Put it in the template, then test it

  1. Generate the lockfile in the template's own CI and commit the result.
  2. Set the CI install step to the strict command from the table.
  3. Add a check that fails when the lockfile is missing or changed by the build.
  4. Document the one command developers run to update the lock on purpose.

Keep the update path easy. If updating the lock is painful, people will bypass the strict install, and the control erodes.

Common objections

Teams sometimes say lockfiles freeze them on vulnerable versions. They do, until you update them, which is why you pair the lock with automated update pull requests. A lockfile makes updates deliberate and reviewable, not absent.

Another worry is merge conflicts in large lockfiles. Regenerating the file after a rebase usually resolves them. A short note in the template README saves many support questions.

Where Safeguard fits

A lockfile gives a scanner a precise inventory to work from. Safeguard reads dependency manifests and lockfiles to build SBOMs and scan for known vulnerabilities, then uses reachability analysis to help you sort what matters. A free scan is at gold.safeguard.sh/scan. For the wider pipeline picture, see what belongs in a golden pipeline.

Try it yourself

Open the inventory and look at how much of the list is indirect dependencies, which is exactly what a lockfile pins.

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

Quick check

Is npm install fine in CI if we have a lockfile?

Prefer npm ci. Per the npm docs it fails when the lock and package.json disagree, while npm install can update the lock.

Do libraries need lockfiles too?

Applications should always commit one. For libraries the practice varies, so decide per ecosystem, but commit one for the library's own CI so builds are repeatable.

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.