
Outdated JavaScript Dependencies
What outdated JavaScript dependencies expose (XSS, prototype pollution, RCE), how to find them with npm audit, Snyk and OSV-Scanner, and how to keep them patched.
Description
An application with outdated JavaScript dependencies ships library versions that have published vulnerabilities. The bugs are documented in the NVD and the GitHub Advisory Database, and many come with public exploit code, so the work of finding the flaw has already been done.
npm, yarn and pnpm make it cheap to pull in packages, and each package pulls in its own. A typical application ends up with hundreds or thousands of transitive dependencies (dependencies of dependencies). Most of them nobody on the team chose directly, and any one of them can be the vulnerable version.
Testers and attackers look for these because the vulnerability is already public, exploit code often exists, update cycles slip, and transitive packages rarely get reviewed at all.
Supply chain angle
A vulnerable or compromised package affects every application downstream of it. One bad release of a popular library can reach thousands of projects.
Impact
Depends entirely on the library and where it runs:
| Bug class | Typical source |
|---|---|
| Cross-site scripting | Old front-end libraries (jQuery, template helpers) that write unsanitized HTML |
| Remote code execution | Server-side packages that deserialize or evaluate input |
| Prototype pollution | Deep-merge and query-string helpers; can lead to RCE or privilege escalation depending on the gadgets available |
| Denial of service | Regular expressions with catastrophic backtracking (ReDoS), unbounded parsing |
| Data theft | Malicious package releases that read environment variables and API keys |
| Authentication bypass | Bugs in token validation libraries |
| Path traversal | Archive extraction and file-serving packages |
Common vulnerable dependencies
High-risk categories
| Category | Examples | Typical issue |
|---|---|---|
| Serialization | serialize-javascript, node-serialize | Code injection, RCE |
| Template engines | handlebars, mustache, pug | Template injection |
| Archive and file handling | tar, unzip, yauzl | Path traversal during extraction |
| XML/HTML parsers | xml2js, cheerio | Parser bugs, prototype pollution |
| Authentication | jsonwebtoken, passport | Token validation bypasses |
| Cryptography | crypto-js, old OpenSSL bindings | Weak defaults and implementations |
| Image processing | sharp, jimp | Memory corruption in native code |
| HTTP clients | request, axios | SSRF and redirect handling |
Examples of major vulnerabilities
- lodash before 4.17.12: prototype pollution (CVE-2019-10744)
- jQuery before 3.5.0: XSS in HTML manipulation methods (CVE-2020-11022, CVE-2020-11023)
- express before 4.17.3: denial of service (process hang) through a
__proto__key in its bundledqs(CVE-2022-24999) - moment before 2.29.2: path traversal in locale loading (CVE-2022-24785)
- serialize-javascript before 3.1.0: code injection (CVE-2020-7660)
- handlebars before 4.7.7: RCE through template compilation (CVE-2021-23369)
Detection
Automated vulnerability scanning
npm audit is built into npm and checks the lockfile against the advisory database:
npm audit
npm audit --audit-level high
npm audit --json # Machine-readable outputyarn audit does the same for Yarn projects:
yarn audit
yarn audit --level high
yarn audit --jsonSnyk uses its own vulnerability database and can keep watching a project after the first scan:
npx snyk test
snyk monitor # Continuous monitoringPackage analysis tools
npm-check-updates lists packages with newer versions available:
npx npm-check-updates
npx ncu -u # Update package.jsonaudit-ci fails a CI build when vulnerabilities above a threshold are found:
npx audit-ci --moderate # Fail on moderate+ vulnerabilitiesOSV-Scanner reads lockfiles from many ecosystems and checks them against OSV.dev:
osv-scanner --lockfile package-lock.jsonManual analysis
On a test where you only have the front end, read library versions out of the JavaScript bundles and file banners and look them up in the advisory databases. With source access, read package.json and the lockfile, and trace why a transitive package is present with npm ls <package> or yarn why <package>.
CI/CD integration
Run the audit in the build pipeline:
# GitHub Actions example
- name: Run security audit
run: |
npm audit --audit-level high
npx audit-ci --highRemediation
Immediate actions
Update dependencies to current stable versions:
npm update
# Or for major version updates
npx npm-check-updates -u && npm installApply the fixes npm knows about. --force allows major version bumps, so run the tests afterwards:
npm audit fix
npm audit fix --force # For breaking changesCommit the lockfile and install from it, so every build gets the same versions:
# Commit package-lock.json or yarn.lock to version control
npm ci # Install from lock file exactlyDependency management strategy
Apply security updates weekly, minor versions monthly and evaluate major upgrades quarterly. Dependabot or Renovate can open the pull requests, with automatic merging for patch-level security fixes and alerts for critical advisories.
Pin versions deliberately. An exact version never moves, ^ accepts minor and patch updates, ~ accepts only patch updates:
{
"dependencies": {
"express": "4.18.2", // Exact version
"lodash": "^4.17.21", // Compatible version
"react": "~18.2.0" // Approximate version
}
}Choosing packages
Before adding a package, check whether it is still maintained, how quickly past advisories were fixed and how many projects depend on it. Fewer dependencies means fewer things to patch: drop unused packages, prefer small focused libraries over large frameworks where it makes sense, and look at bundle analysis output to see what is actually shipped.
Further mitigations
Subresource Integrity (SRI) makes the browser refuse a CDN file whose hash has changed:
<script src="https://cdn.example.com/lib.js"
integrity="sha384-hash"
crossorigin="anonymous"></script>A Content Security Policy limits where scripts can load from. The example below still allows 'unsafe-inline', which gives up most of the XSS protection; drop it if the application can live without inline scripts:
Content-Security-Policy: script-src 'self' 'unsafe-inline' https://trusted-cdn.comnpm audit signatures checks registry signatures and provenance attestations for installed packages. (npm install --package-lock-only only rewrites the lockfile; it does not verify anything.)
npm install --package-lock-only # Verify integrity
npm audit signatures # Verify package signaturesMonitoring and alerting
Keep watching after the first scan. Snyk monitoring and GitHub Dependabot alerts both report new advisories against packages you already use:
# Snyk monitoring
snyk monitor
# GitHub security alerts
# Enable in repository settingsBlock deployments that would ship high or critical vulnerabilities:
# Fail deployments on high/critical vulnerabilities
script:
- npm audit --audit-level high || exit 1Prevention
Development practices
Review new dependencies before they are added and keep a list of approved packages with the reason each one is there. Put dependency checks in code review and CI. For supply chain risk, watch for maintainer changes and unexpected new releases, and publish internal packages to a private registry so a public package with the same name cannot be pulled in by mistake.
Infrastructure controls
A private registry proxy (Verdaccio, Artifactory, Nexus) can cache and scan packages, require approval for new ones and block known-vulnerable versions.
In containers, keep build tooling and dev dependencies out of the runtime image. On current npm, --omit=dev replaces the older --only=production flag used below:
# Multi-stage builds to minimize attack surface
FROM node:18-alpine AS builder
COPY package*.json ./
RUN npm ci --only=production
FROM node:18-alpine AS runtime
COPY --from=builder /app/node_modules ./node_modulesVerification
Testing updated dependencies
Run the test suites after every upgrade:
npm test
npm run e2e-tests
npm run security-testsThen check the main application flows by hand for behaviour changes, and re-run the audit to confirm nothing new came in with the upgrade:
npm audit --audit-level moderate
npx snyk testTracking progress
Count vulnerable dependencies over time, measure how long critical advisories take to patch, and check that every repository is actually scanned. Include dependency analysis in regular penetration tests.
Example configurations
package.json security configuration
{
"scripts": {
"audit": "npm audit --audit-level moderate",
"audit-fix": "npm audit fix",
"security-check": "npx snyk test && npm audit"
},
"engines": {
"node": ">=18.0.0",
"npm": ">=8.0.0"
}
}GitHub Actions security workflow
name: Security Audit
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm audit --audit-level high
- run: npx snyk testDependabot configuration
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
reviewers:
- "security-team"References
- OWASP: Using Components with Known Vulnerabilities
- CWE-1104: Use of Unmaintained Third Party Components
- npm Security Best Practices
- Node.js Security Best Practices
- Snyk's State of Open Source Security Report
Next steps
If you find outdated dependencies during a test, map the whole dependency tree, then rank the findings by whether the vulnerable code path is reachable and exposed, not by CVSS alone. A vulnerable server-side parser that handles user input matters far more than a dev-only build tool. Related:
OAuth 2.0 Misconfigurations and Token Theft
Stealing OAuth 2.0 codes and tokens through redirect_uri bypasses, missing state checks, implicit flow leaks, Referer leaks and scope escalation.
Path Traversal and Local File Inclusion
Exploiting path traversal and local file inclusion, with filter bypasses, PHP wrappers, null bytes and log poisoning for RCE.