Most of a Node app is third-party code. A vulnerable or malicious package runs with your app's full privileges.
The main risks:
- Known CVEs (publicly listed vulnerabilities) in outdated packages.
- Typosquatting: a fake package with a name like a popular one, such as
expresss. - Hijacked maintainer accounts that publish malicious versions of real packages.
postinstallscripts that run on install and steal secrets from CI.- Dependency confusion: the installer picks a public package that has the same name as your private one.
Defences:
- Commit the lockfile and install with
npm ci, so every build uses the exact same versions. - Run
npm auditor a tool like Dependabot in CI, and patch quickly. - Before you add a new dependency, check that it is maintained and widely used. Keep the dependency tree small.
- Use
--ignore-scriptswhere you don't need install scripts. - Scope private packages to your own registry.
Keep an SBOM (Software Bill of Materials: a list of every package and version you use). When the next major vulnerability is announced, it lets you answer "are we affected?" quickly.
- Risks include known CVEs, typosquatting, hijacked packages and malicious install scripts.
- Dependency confusion can make the installer pick a public package instead of your private one.
- Commit the lockfile and install with npm ci.
- Run npm audit or automated updates in CI.
- Check new packages, limit install scripts and keep an SBOM.
Read more
- Vulnerable Dependency Management Cheat Sheet (OWASP) (https://cheatsheetseries.owasp.org/cheatsheets/Vulnerable_Dependency_Management_Cheat_Sheet.html)cheatsheetseries.owasp.org
- Node.js Security Cheat Sheet (OWASP) (https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html)cheatsheetseries.owasp.org