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.node.dependencies.DependencyVulnerabilityCheck

Optional

addMarkersBoolean

Report each vulnerability that is not fixed as a search result marker on the package.json dependency that brings it in, so the diff view shows which dependencies pull in vulnerable transitives. By default these markers are omitted, making it easier to see version upgrades within the diff.

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 suggesting a dependency version upgrade. Use none to only report vulnerabilities without making any changes. Patch version upgrades are the default and safest option, as patch releases assert full backwards compatibility with no breaking changes. Minor version upgrades can introduce new features but do not typically include breaking changes. Major version upgrades will typically require code changes above and beyond this recipe.

Only fix vulnerabilities with a severity level equal to or higher than the specified minimum. Vulnerabilities are classified as low, moderate, high, or critical based on their potential impact. Default is low, which includes all severity levels.

Only fix vulnerabilities matching this regular expression pattern. This allows filtering to specific CVEs or CVE ranges. For example, CVE-2023-.* will only check for CVEs from 2023, CVE-(2022|2023)-.* will check for CVEs from 2022 or 2023, CVE-2021-44228|CVE-2022-23305 will check for those specific CVEs. If not specified, all CVEs will be checked (subject to other filters).

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.node.dependencies.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.