Phase 6: Supply Chain Security & Slopsquatting · 50 min · pip-compile · npm ci · hashlib
Lockfile Enforcement & Hash Verification
Pin versions. Verify hashes. Block substitution. Enforce in CI.
Hiring signal: Engineers who can enforce lockfile pinning and hash verification in CI demonstrate production-grade supply chain security skills and prevent package substitution attacks.
What you will learn
- Enforce lockfile pinning to prevent version drift in AI-generated code
- Implement hash verification to detect package substitution attacks
- Prevent package substitution by regenerating dependency trees from approved lockfiles
- Apply the agent-cicd pattern for dependency gates in CI
The Problem
Even with allowlists (Lesson 3) and SBOMs (Lesson 4), there's one more attack vector: package substitution. An attacker compromises a legitimate package on the registry, replacing version 1.2.3 with malicious code while keeping the same version number. Without lockfile pinning and hash verification, your CI/CD will install the compromised version. This lesson covers lockfile enforcement and hash verification to prevent substitution attacks.
The Package Substitution Attack
1. Your lockfile says: requests==2.28.0
↓
2. Attacker compromises PyPI account of requests maintainer
↓
3. Attacker uploads malicious code as requests 2.28.0 (same version)
↓
4. Your CI runs: pip install -r requirements.txt
↓
5. pip downloads "requests 2.28.0" -- but it's the attacker's version
↓
6. Malicious code executes in CI
↓
7. Attacker steals CI/CD tokens, source code, secrets
Defense: Lockfile Pinning + Hash Verification
1. Your lockfile says: requests==2.28.0 --hash=sha256:abc123...
↓
2. Attacker uploads malicious code as requests 2.28.0
↓
3. Your CI runs: pip install --require-hashes -r requirements.txt
↓
4. pip downloads "requests 2.28.0"
↓
5. pip calculates SHA-256 hash of downloaded package
↓
6. Hash doesn't match abc123... (attacker's code has different hash)
↓
7. pip REFUSES to install -- ERROR: Hash mismatch
↓
8. CI fails, merge blocked, attack prevented
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Lockfile Pinning, The Agent-CICD Pattern for Dependency Gates, Build It — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy