Skip to content

How to Fix npm audit High Vulnerabilities

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix npm audit High Vulnerabilities. We cover key concepts, practical examples, and best practices.

The Problem

npm audit reports high or critical vulnerabilities in your dependencies, indicating known security issues in packages that could be exploited in production.

Quick Fix

Step 1: Run npm audit fix

Auto-fix compatible vulnerabilities:

npm audit fix

For breaking changes, use --force (careful with major version changes):

npm audit fix --force

Step 2: Check the audit report

Understand which packages are affected:

npm audit
=== npm audit security report ===
High            Prototype Pollution
Package         lodash
Patched in      >=4.17.21
Dependency of   express-handlebars
Path            express-handlebars > lodash

Step 3: Update the direct dependency

If a sub-dependency is vulnerable, update the parent:

npm install express-handlebars@latest

Step 4: Use overrides to force a sub-dependency version

When the direct dependency has not updated its vulnerable sub-dependency:

{
    "overrides": {
        "lodash": "4.17.21"
    }
}

Then run:

npm install

Step 5: Replace deprecated packages

Some packages are no longer maintained:

# Replace request (deprecated) with node-fetch or axios
npm uninstall request
npm install node-fetch

Update your imports accordingly.

Step 6: Audit only production dependencies

Dev dependencies are not exposed in production:

npm audit --production

This focuses on vulnerabilities that actually affect production.

Prevention

  • Run npm audit in CI to fail builds on high vulnerabilities.
  • Use npm outdated to track outdated packages.
  • Enable Dependabot or Renovate for automated dependency updates.
  • Pin exact versions for critical dependencies.
  • Regularly review and remove unused dependencies.

Common Mistakes with npm audit

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world NODE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Should I always run npm audit fix --force?

No. --force installs breaking changes that may break your application. Review the changes manually first. Run npm audit to see what would change, then update packages individually after testing. Prefer targeted upgrades over bulk fixes.

What does it mean when a vulnerability has no fix?

The maintainer has not released a patched version, or the package is deprecated. Your options: switch to an alternative package, contribute a fix, suppress the warning with npm audit --json and manual review (for false positives), or use a runtime protection tool like Helmet.js.

How do I suppress a specific vulnerability warning?

npm audit --json > audit.json

Review the findings manually. For false positives, use npm audit --production to exclude dev dependencies or use advisory ignore lists. Do not blindly suppress warnings. Each should be reviewed and documented.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro