Skip to main content

Free 30-min security demo  — We'll scan your real code and show live findings, no commitment Book Now

Offensive360
Academy Vulnerable Dependencies
Beginner · 15 min

Vulnerable Dependencies

Learn how CVEs in third-party packages and transitive dependencies create exploitable attack surfaces.

1 CVEs in npm, pip, and Maven Packages

Modern applications depend on hundreds or thousands of third-party packages. Each dependency — and its transitive dependencies — is a potential attack vector if a security vulnerability (CVE) is discovered.

The scale of the problem:

  • A typical Node.js app has 500-1000+ transitive dependencies
  • The average time between CVE disclosure and patching in production: 60+ days
  • Log4Shell (2021): CVE in a Java logging library affected millions of systems

Direct vs transitive dependencies:

{
  "dependencies": {
    "express": "^4.18.0",       // Direct — you chose this
    "lodash": "^4.17.21"        // Direct — but has had prototype pollution CVEs
  }
}
// express depends on:
//   path-to-regexp (has had ReDoS vulnerabilities)
//   qs (has had prototype pollution CVEs)
// These are TRANSITIVE — you may not know they exist!

Attackers scan for vulnerable dependencies using the npm audit API or public CVE databases to find targets running known-vulnerable package versions.

2 Dependency Scanning, Lock Files, and Automated Alerts

Implement systematic dependency management to detect and remediate vulnerable packages before attackers exploit them.

Lock files prevent version drift:

# package-lock.json (npm) or yarn.lock pins EXACT versions
# Without lock files, npm install might pull different versions
# With lock files: reproducible installs, no surprise upgrades

# Always commit lock files to source control
git add package-lock.json  # Never .gitignore this!

Audit commands:

npm audit                  # Check for CVEs in npm packages
npm audit fix              # Auto-fix compatible updates
pip-audit                  # Python packages
mvn dependency-check:check # Maven (OWASP plugin)

Automated alerting (GitHub Dependabot):

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "npm"
    directory: "/"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 10
    ignore:
      - dependency-name: "*"
        update-types: ["version-update:semver-major"]

Knowledge Check

0/3 correct
Q1

What is a transitive dependency?

Q2

Why should package lock files (package-lock.json) always be committed to source control?

Q3

How does GitHub Dependabot help with dependency security?

Code Exercise

Add Dependency Audit to CI

The CI pipeline builds and tests the app but does not check for vulnerable dependencies. Add an npm audit step that fails the build if high severity vulnerabilities are found.

yaml