Dependency & Supply Chain Vulnerability Scans
SecOps & SCA Sprint β Day 1
Audit vulnerable-store-api dependencies, parse CVE advisories using Trivy and npm audit, assert CVSS thresholds, and automate lockfile patch pinning.
In this lab playbook, you will assume the role of an AI SecOps & Red-Teaming Architect. Before introducing new code into production, you must establish baseline Software Composition Analysis (SCA) to identify vulnerable third-party dependencies, malicious packages, and unpinned transitive libraries in our demo enterprise microservice: vulnerable-store-api.
The official reference codebase for Day 1 is hosted in the repository. Clone the repository and navigate to day-1-sca-supply-chain to run the working solution.
git clone https://github.com/letstrnsfrm-ai/security-compliance-roadmap.git
cd security-compliance-roadmap/day-1-sca-supply-chainpackage.json, interpreting CVSS v3 vectors, and automating dependency upgrades.Initialize Target Application & Inject Outdated Dependencies
Set up the local directory for vulnerable-store-api and initialize a package manifest containing known vulnerable packages.
Create the project structure and initialize npm:
mkdir -p security-lab/day-1-sca-supply-chain
cd security-lab/day-1-sca-supply-chain
npm init -yAdd vulnerable versions of jsonwebtoken (CVE-2022-23529) and minimist (CVE-2021-44906):
{
"name": "vulnerable-store-api",
"version": "1.0.0",
"description": "Enterprise Storefront REST API with deliberate security flaws for SecOps training",
"main": "server.js",
"scripts": {
"start": "node server.js",
"security:audit": "npm audit --json > audit-report.json || true",
"security:scan": "node scripts/sca-gate.js"
},
"dependencies": {
"express": "^4.17.1",
"jsonwebtoken": "8.5.1",
"minimist": "1.2.5",
"sqlite3": "^5.1.7"
}
}Execute Software Composition Analysis (SCA)
Run native and container-based SCA scanners across the dependency tree to extract Common Vulnerability Scoring System (CVSS) telemetry.
Generate a machine-readable JSON advisory report:
npm audit --json > audit-report.json
cat audit-report.json | grep -E "severity|title"Execute Trivy to scan for High and Critical vulnerabilities:
Build Automated CI/CD SCA Gate Enforcer
Write an automated policy gate in Node.js that parses vulnerability scan reports and fails the build if any vulnerability exceeds your CVSS threshold.
#!/usr/bin/env node
const fs = require('fs');
if (!fs.existsSync('audit-report.json')) {
console.error('β audit-report.json not found! Run "npm audit --json > audit-report.json" first.');
process.exit(1);
}
const report = JSON.parse(fs.readFileSync('audit-report.json', 'utf-8'));
const vulnerabilities = report.vulnerabilities || {};
let criticalCount = 0;
let highCount = 0;
let moderateCount = 0;
for (const [pkgName, vuln] of Object.entries(vulnerabilities)) {
const severity = vuln.severity;
if (severity === 'critical') criticalCount++;
else if (severity === 'high') highCount++;
else if (severity === 'moderate') moderateCount++;
console.log(`π¦ [${severity.toUpperCase()}] ${pkgName}: ${vuln.via?.[0]?.title || 'Known vulnerability'}`);
}
console.log('\n================ SCA AUDIT SUMMARY ================');
console.log(`Critical: ${criticalCount} | High: ${highCount} | Moderate: ${moderateCount}`);
console.log('==================================================');
if (criticalCount > 0 || highCount > 0) {
console.error('π¨ POLICY VIOLATION: Build failed! Zero Critical & High CVEs permitted.');
process.exit(1);
}
console.log('β
SCA POLICY PASSED: All dependencies within acceptable risk thresholds.');
process.exit(0);node scripts/sca-gate.js
# Output: π¨ POLICY VIOLATION: Build failed! Zero Critical & High CVEs permitted.Remediate & Pin Secure Dependency Versions
Apply automated security patches, pin safe major/minor versions in package.json, and verify that the gate passes cleanly.
# Update jsonwebtoken to >= 9.0.0 and minimist to >= 1.2.8
npm install jsonwebtoken@^9.0.0 minimist@^1.2.8 --save
npm audit --json > audit-report.json
node scripts/sca-gate.js================ SCA AUDIT SUMMARY ================
Critical: 0 | High: 0 | Moderate: 0
==================================================
β
SCA POLICY PASSED: All dependencies within acceptable risk thresholds.- Understood Software Composition Analysis (SCA) principles and how transitive dependencies introduce CVEs into production.
- Audited vulnerable-store-api using native npm audit JSON outputs and cross-platform Trivy filesystem scans.
- Authored an automated Node.js CI policy gate (scripts/sca-gate.js) with zero-critical and zero-high blocking thresholds.
- Safely upgraded pinned package versions and verified compliant green exit-code status.
π§ Knowledge Check
Why is relying strictly on semantic version carats (e.g. ^4.17.1) in production package manifests considered a supply-chain security risk?