Vulnerable npm and NuGet Packages: Audit, Pin and Update Safely

Find vulnerable npm and NuGet packages, including transitive ones, automate updates with Dependabot or Renovate, and block typosquatting and bad releases.

By Victor Sanchez

Vulnerable npm and NuGet packages show up in almost every scan we review, and most of them are packages nobody on the team chose directly. On the enterprise applications we work on, a large share of the dependency findings came from transitive packages, pulled in by something else. Outdated packages are the slow risk. Compromised packages are the fast one: in September 2025, phishing gave attackers access to the npm account of a maintainer of chalk, debug and other widely used libraries, and malicious versions were published to the registry.

Outdated vs compromised packages: what is the difference?

Outdated / vulnerableCompromised / malicious
What it isA legitimate version with a known CVEA version published by an attacker, or a look-alike package
How you find itAdvisory databases, auditsOften only after the community reports it
DefenseUpdate on a cadenceLockfiles, a release-age delay, no install scripts, provenance

Other well-known cases: event-stream (2018), where a new maintainer added a malicious dependency, and the xz Utils backdoor (CVE-2024-3094), inserted by a contributor over years. Supply chain failures now have their own category in the OWASP Top 10:2025 (A03).

How to audit npm dependencies

# Install exactly what the lockfile says; fails if package.json and the lockfile disagree
npm ci

# Report known vulnerabilities; fail the build on high or critical
npm audit --audit-level=high

# Production dependencies only
npm audit --omit=dev

# Verify registry signatures and provenance attestations
npm audit signatures

Be careful with npm audit fix --force: it can install versions outside your declared ranges, including major upgrades. Treat it like any other breaking change, with a branch and tests.

Install scripts

Packages can run preinstall and postinstall scripts on your machine and in CI. That is how many malicious packages execute. Turn them off by default and allow them only for the packages that really need them:

# .npmrc
ignore-scripts=true

How to find vulnerable NuGet packages, including transitive ones

# .NET 9 SDK and earlier
dotnet list package --vulnerable --include-transitive

# .NET 10 SDK: noun-first form
dotnet package list --vulnerable --include-transitive --format json

--include-transitive is not the default, and without it you only see what you reference directly. Since the .NET 8 SDK, restore also runs NuGet Audit and raises warnings NU1901 to NU1904 (low to critical). By default it audits only direct packages unless the project targets net10.0 or later, so set the mode explicitly and fail on high and critical:

<!-- Directory.Build.props -->
<PropertyGroup>
  <NuGetAudit>true</NuGetAudit>
  <NuGetAuditMode>all</NuGetAuditMode>
  <NuGetAuditLevel>low</NuGetAuditLevel>
  <WarningsAsErrors>$(WarningsAsErrors);NU1903;NU1904</WarningsAsErrors>
  <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

When a transitive package is vulnerable, first try upgrading the direct package that brings it in. If that does not help, Central Package Management with transitive pinning lets you force a fixed version in Directory.Packages.props. dotnet nuget why <package> shows the path.

Lockfiles and pinning

  • Commit the lockfile (package-lock.json, packages.lock.json).
  • Install from it in CI: npm ci and dotnet restore --locked-mode fail instead of silently resolving new versions.
  • Pin direct dependencies to exact versions in applications, and let your update bot propose changes.
  • Use one internal feed or a proxy when possible, to reduce package-substitution attacks.

Dependabot or Renovate: automate the updates

Either tool opens pull requests for new versions. As of mid-2026, Dependabot waits three days after a release before opening a version update by default (the cooldown setting). Renovate has a similar minimumReleaseAge option. A delay of a few days gives the community time to catch malicious releases before they reach you. Security updates are not delayed.

# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "nuget"
    directory: "/"
    schedule: { interval: "weekly" }
    cooldown: { default-days: 5, semver-major-days: 30 }
    groups:
      microsoft: { patterns: ["Microsoft.*", "System.*"] }
  - package-ecosystem: "npm"
    directory: "/web"
    schedule: { interval: "weekly" }
    cooldown: { default-days: 5 }

How to spot typosquatting before you install

  • Check the exact name, the publisher and the repository link. reqeusts is not requests.
  • Be suspicious of a brand-new package with few downloads that "replaces" a popular one.
  • Read the diff a new dependency adds to the lockfile: a small utility that pulls in 80 packages deserves a question.
  • When an AI assistant suggests a package, verify that it exists and is the one you think. See reviewing AI-generated code.

An upgrade cadence that works

WhatWhen
Critical or exploited CVESame day or next business day
High severityWithin the sprint
Patch and minor updatesWeekly, grouped PRs, after the cooldown
Major versions and frameworksPlanned per quarter, with regression tests

Framework upgrades deserve their own plan; we cover that in our .NET migration playbook.

Pitfalls

  • Auditing direct dependencies only.
  • Running npm install in CI instead of npm ci.
  • Merging bot PRs without tests, or ignoring them until there are 60.
  • Suppressing advisories without a written reason and an expiry date.
  • Updating the day a release appears, before anyone has looked at it.

Checklist

  • Lockfiles committed; CI installs with npm ci and --locked-mode.
  • npm audit and NuGet Audit with transitive scanning in CI, failing on high and critical.
  • Install scripts disabled by default.
  • Dependabot or Renovate configured with a cooldown and grouping.
  • New dependencies reviewed for name, publisher and size.
  • A written upgrade cadence by severity.

Key takeaways

  • Most of your risk is in transitive dependencies. Scan them.
  • Lockfiles plus npm ci make builds repeatable and harder to poison.
  • A short release-age delay is cheap protection against malicious versions.
  • Update on a cadence, not in a panic.

Sources

Need help with vulnerable dependencies?

Santhor audits npm and NuGet dependencies in existing applications, fixes vulnerable and outdated packages without breaking behavior, and sets up the automation that keeps them current. We are based in Costa Rica and work nearshore with teams in the U.S. and Latin America. Tell us about your project.

More articles ยท Contact Santhor