Find and fix vulnerable npm dependencies

Proprietary

This software composition analysis (SCA) tool detects and upgrades dependencies with publicly disclosed vulnerabilities. This recipe both generates a report of vulnerable dependencies and upgrades to newer versions with fixes. This recipe by default only upgrades to the latest patch version. If a minor or major upgrade is required to reach the fixed version, this can be controlled using the maximumUpgradeDelta option. Vulnerability information comes from the GitHub Security Advisory Database, which aggregates vulnerability data from several public databases. Every change to package.json is followed by regenerating its lock file.

Customizing Vulnerability Data

Extend this recipe and override baselineVulnerabilities(ctx) to replace the bundled advisory database, or override supplementalVulnerabilities(ctx) to add organisation-specific advisories alongside the bundled data.

org.openrewrite.nodejs.security.DependencyVulnerabilityCheck

Optional

Match dependencies with the specified scope. Default includes all scopes.

Strategy for handling transitive dependency vulnerabilities. report only reports them without fixing. override adds overrides/resolutions for transitive vulnerabilities. lock-file fixes them only by upgrading the direct dependencies that pull them in (see preferDirectUpgrade) and regenerating the lock file, never with overrides; the rest are only reported. Default is report.

preferDirectUpgradeBoolean

When fixing transitive vulnerabilities, first try to find higher versions of direct dependencies that include safe transitive versions. Default is true.

The maximum difference to allow when upgrading a dependency version. Use none to only report vulnerabilities without making any changes.

Only fix vulnerabilities with a severity level equal to or higher than the specified minimum. Default is low.

Only fix vulnerabilities matching this regular expression pattern.

fixDeclaredVersionsBoolean

When enabled, also upgrades version specifiers declared in package.json that specify vulnerable versions, even if the lock file already resolves to a safe version. Default is false.

addOverrideCommentsBoolean

When enabled, adds a comment field (e.g. //overrides) alongside overrides to document which CVEs each override is fixing. Default is true.

mod run . --recipe=org.openrewrite.nodejs.security.DependencyVulnerabilityCheck

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.