Principle:0sec labs 0 Dependency Locking
| Knowledge Sources | |
|---|---|
| Domains | Tooling, Dependency_Management, Reproducibility |
| Last Updated | 2026-10-30 00:00 GMT |
Overview
A mechanism that pins every direct and transitive dependency in a project to an exact resolved version and integrity hash, guaranteeing reproducible installs across environments.
Description
Dependency Locking is the practice of recording the fully resolved dependency graph — including all transitive dependencies, their versions, and cryptographic integrity hashes — in a lockfile that is committed to version control. It solves the problem of floating version specifiers (e.g., ^1.2.0) producing different dependency trees over time or across machines as new versions are published.
A lockfile captures three things a package.json alone cannot:
- Exact versions: The specific version resolved for every package in the tree, not just a range.
- Integrity hashes: A sha512 hash per resolved package, enabling tamper and corruption detection.
- Override propagation: A mechanism to force a minimum version of a transitive dependency across the entire tree, used to apply security patches to packages deep in the dependency graph.
This ensures that pnpm install --frozen-lockfile in CI produces a byte-identical node_modules tree to what a developer committed, eliminating "works on my machine" dependency drift and supply-chain surprises.
Usage
Apply this principle when managing any multi-package monorepo or project where reproducible builds and supply-chain integrity are required. It is the right choice whenever:
- CI must fail if dependencies have drifted from the committed lockfile.
- Security advisories require forcing a patched version of a transitive dependency.
- Multiple developers or pipelines must produce identical dependency trees.
Theoretical Basis
The core invariant is a deterministic resolution function:
# Abstract algorithm (NOT real implementation)
def resolve(manifests, overrides, registry):
tree = {}
for manifest in manifests:
for dep, specifier in manifest.dependencies.items():
# Apply override if one exists for this package
if dep in overrides:
specifier = overrides[dep]
# Resolve to exact version from registry
exact = registry.resolve(dep, specifier)
# Record integrity hash for tamper detection
tree[dep] = {
"version": exact.version,
"integrity": exact.integrity_sha512,
}
return tree # This tree is the lockfile
The lockfile is the output of this resolution, persisted so future installs skip resolution entirely. The frozen install mode verifies that the manifests still hash to the same lockfile, failing if a specifier changed without a lockfile regeneration.