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

Dependency Versioning and Semantic Versioning

Understand semantic versioning principles, version pinning vs ranges, and how version choices impact security exposure.

Dependency Versioning and Semantic Versioning

You'll learn how version numbering systems control security risk when choosing library versions.

What Is Semantic Versioning?

Semantic versioning (SemVer) uses a three-part number: MAJOR.MINOR.PATCH (e.g., 2.4.7).

  • MAJOR (2): Breaking changes that aren't backward-compatible
  • MINOR (4): New features that are backward-compatible
  • PATCH (7): Bug fixes and security patches

Think of it like apartment addresses: the building number (MAJOR) tells you the general location, the floor (MINOR) adds detail, and the unit number (PATCH) gets you to the exact door.

Version Pinning vs Ranges

When declaring dependencies, you have choices:

Version pinning locks to an exact version: requests==2.28.1

  • Security risk: You won't automatically get patch releases with security fixes
  • Security benefit: Prevents unexpected malicious updates

Version ranges allow flexibility: requests>=2.28.0,<3.0.0 or requests~=2.28.0 (compatible patches)

  • Security benefit: Automatically receive PATCH-level security fixes
  • Security risk: Broader attack surface if a malicious version enters the range

Security Impact of Version Choices

Overly strict pinning means you miss critical CVE patches unless you manually update. Overly loose ranges (like requests>=2.0.0) expose you to any compromised version published within that huge range.

The sweet spot: Pin MAJOR and MINOR, allow PATCH updates (~=2.28.0). This gets you security fixes while limiting the window for supply chain attacks.

Always pair version strategies with dependency scanning (from lesson 1259-1260) to detect when pinned versions have known vulnerabilities.

Key Takeaway: Semantic versioning guides safe dependency choices—use ranges that capture security patches (PATCH level) while limiting exposure to major changes and potential supply chain compromise.