Dependency Pinning - FOSSA

Dependency Pinning

Dependency pinning is the practice of locking software dependencies to specific versions to ensure build reproducibility, stability, and security in the software supply chain.

What is Dependency Pinning?

Dependency pinning is the practice of explicitly specifying exact versions of software dependencies rather than using version ranges or latest version references. This technique locks dependencies to specific, verified versions to ensure build reproducibility, prevent unexpected changes, and protect against supply chain attacks.

Unlike flexible version constraints (such as ^1.2.3 or >=2.0.0), pinned dependencies use exact version specifications (like 1.2.3 exactly) or cryptographic checksums to guarantee that the same code is used in every build.

Why Dependency Pinning Matters

Supply Chain Security

When dependencies aren't pinned, builds can automatically incorporate new versions that may introduce:

Pinning dependencies creates a stable foundation where each component has been vetted before use.

Build Reproducibility

Unpinned dependencies lead to "works on my machine" problems when different environments pull different versions. Pinning ensures:

Change Management

Dependency pinning transforms dependency updates from automatic, unpredictable events to explicit, controlled changes:

Common Dependency Pinning Techniques

Various strategies exist for pinning dependencies, each with different security and usability tradeoffs:

1. Version Pinning

The most basic approach specifies exact versions in package manifest files:

NPM (package.json):

{
  "dependencies": {
    "express": "4.17.1",
    "lodash": "4.17.21"
  }
}

Python (requirements.txt):

requests==2.27.1
flask==2.0.1

2. Lockfile Utilization

Most modern package ecosystems use lockfiles that record exact versions of both direct and transitive dependencies:

Lockfiles should be committed to version control and used consistently across environments.

3. Checksums and Integrity Verification

Beyond version numbers, checksums verify that dependency content matches expectations:

4. Vendoring

Vendoring takes pinning further by copying dependency code directly into the project repository:

5. Centralized Artifact Repositories

Organizations can maintain internal mirrors of dependencies:

Challenges of Dependency Pinning

While essential for security, dependency pinning introduces challenges:

1. Update Management

Pinned dependencies don't automatically receive updates, requiring:

2. Transitive Dependency Complexity

Direct dependencies have their own dependencies, creating complex trees:

3. Developer Experience

Strict pinning can impact developer workflows:

Best Practices for Dependency Pinning

1. Lockfile Discipline

2. Automated Update Workflows

3. Verification and Vetting

4. Documentation