Course contentsShow
← Security
Lesson 1280 of 3,05226. Application Security - Supply ChainFree lesson

Dependency Resolution and Lock Files

How package managers resolve dependencies and why lock files are critical for reproducibility.

Dependency Resolution and Lock Files

You'll learn how package managers figure out which library versions to install and why lock files are essential for keeping your builds secure and consistent.

Understanding Dependency Resolution

When you declare a dependency like requests >= 2.0, your package manager must decide which exact version to install. This process is called dependency resolution. The package manager looks at your direct dependencies, then recursively checks their dependencies (transitive dependencies), trying to find a compatible set of versions that satisfies all requirements.

Think of it like planning a dinner party: you need to find a date that works for all your guests, considering their availability and conflicts. Similarly, the package manager must find versions that don't conflict with each other.

The Problem Without Lock Files

Without a lock file, running npm install or pip install on different days might install different versions of the same library. Even if you specify mylib >= 1.5, you might get version 1.5 today and 1.9 next week (if it was just released). This is dangerous because:

  • Reproducibility breaks: Your colleague's build might differ from yours
  • Security vulnerabilities: A new version might contain an exploitable bug
  • Supply chain attacks: An attacker who compromises a dependency can inject malicious code into "updates"

Lock Files to the Rescue

Lock files (package-lock.json, Pipfile.lock, Cargo.lock) record the exact version of every dependency installed, creating a snapshot. When someone else runs the install command, they get the identical versions you tested with. This guarantees reproducible builds and gives you control over when dependencies change.

Key Takeaway: Lock files freeze your dependency tree to exact versions, ensuring every build is identical and giving you control over when security-critical updates are adopted.