Skip to main content

Find and fix vulnerable npm dependencies

org.openrewrite.nodejs.security.DependencyVulnerabilityCheck

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.

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.

Recipe source

This recipe is only available to users of Moderne.

This recipe is available under the Moderne Proprietary License.

Options

TypeNameDescriptionExample
StringscopeOptional. Match dependencies with the specified scope. Default includes all scopes. Valid options: dependencies, devDependencies, peerDependencies, optionalDependenciesdependencies
StringtransitiveFixStrategyOptional. Strategy for handling transitive dependency vulnerabilities. report only reports them without fixing. override adds overrides/resolutions for transitive vulnerabilities. lock-file updates the lock file to resolve safe versions without modifying package.json. Default is report. Valid options: report, override, lock-fileoverride
BooleanpreferDirectUpgradeOptional. When fixing transitive vulnerabilities, first try to find higher versions of direct dependencies that include safe transitive versions. Default is true.false
StringmaximumUpgradeDeltaOptional. The maximum difference to allow when upgrading a dependency version. Use none to only report vulnerabilities without making any changes. Valid options: none, patch, minor, majorpatch
StringminimumSeverityOptional. Only fix vulnerabilities with a severity level equal to or higher than the specified minimum. Default is low. Valid options: low, moderate, high, criticalmoderate
StringcvePatternOptional. Only fix vulnerabilities matching this regular expression pattern.CVE-2023-.*
BooleanfixDeclaredVersionsOptional. 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.true
BooleanaddOverrideCommentsOptional. When enabled, adds a comment field (e.g. //overrides) alongside overrides to document which CVEs each override is fixing. Default is true.true

Usage

This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe DependencyVulnerabilityCheck

If the recipe is not available locally, then you can install it using:

mod config recipes jar install org.openrewrite.recipe:rewrite-nodejs:0.46.1

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Vulnerability report

org.openrewrite.nodejs.table.VulnerabilityReport

Lists all vulnerabilities found in project dependencies.

Column NameDescription
Source pathPath to the package.json file where the vulnerability was found.
CVEThe CVE identifier of the vulnerability.
PackageThe name of the vulnerable package.
VersionThe resolved version of the package.
Fixed versionThe version that fixes the vulnerability.
Last affectedThe last version affected by the vulnerability.
UpgradeableWhether the vulnerability can be fixed with a version upgrade within the maximum delta.
SummaryBrief description of the vulnerability.
SeveritySeverity level of the vulnerability.
DepthDepth in the dependency tree (0 = direct, 1+ = transitive).
CWEsCWE identifiers associated with this vulnerability.
Is directWhether this is a direct dependency.
Dependency pathPath showing how the vulnerable dependency is brought in.