CVE-2021-43307: Semver regex Denial of Service Vulnerability

LOW
Advisory Identifier: GHSA-4x5v-gmq8-25ch
CWE-1333
Published
Advisory Summary

CVE-2021-43307 is a LOW denial of service vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Semver regex libraries in the npm ecosystem. The issue involves regular expression denial of service in semver-regex. Remediation is available by upgrading affected packages to version 3.1.4, 4.0.3.

CVE-2021-43307 at a Glance

CVE Identifier CVE-2021-43307
GHSA Identifier GHSA-4x5v-gmq8-25ch
Severity LOW
CVSS v3.1 Base Score N/A
CWE Classification CWE-1333: Inefficient Regular Expression Complexity
Affected Product Semver regex
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2021-43307

To remediate this vulnerability, upgrade all affected Semver regex dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

semver-regex fixed: 3.1.4
npm install semver-regex@3.1.4
semver-regex fixed: 4.0.3
npm install semver-regex@4.0.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls semver-regex

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2021-43307, inspect your project dependencies using npm:

npm ls semver-regex

Analyze the terminal output to locate any version of Semver regex in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.1.4), your application is affected.

Note: The npm ls semver-regex command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1333: Inefficient Regular Expression Complexity, where the product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. In Semver regex, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

An exponential ReDoS (Regular Expression Denial of Service) can be triggered in the semver-regex npm package, when an attacker is able to supply arbitrary input to the test() method

CVE-2021-43307 Affected Semver regex Versions

2 component(s)
Fixed Versions:
3.1.44.0.3
Product / Package Ecosystem Affected Versions Fixed Version
semver-regex
npm
< 3.1.4
3.1.4
semver-regex
npm
≥ 4.0.0
< 4.0.3
4.0.3

References

Frequently Asked Questions

What is CVE-2021-43307?
CVE-2021-43307 is a security vulnerability in Semver regex involving Regular expression denial of service in semver-regex under CWE-1333: Inefficient Regular Expression Complexity.
Which Semver regex versions are affected?
Affected versions include releases prior to 3.1.4, 4.0.3 across affected packages: semver-regex.
What version fixes CVE-2021-43307?
Upgrading to 3.1.4, 4.0.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is semver-regex affected?
Yes, semver-regex is affected in releases prior to 3.1.4, 4.0.3. Upgrade your dependency to 3.1.4, 4.0.3 or later.
What CWE is associated with CVE-2021-43307?
CVE-2021-43307 is classified under CWE-1333: Inefficient Regular Expression Complexity (The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential.).
How can I check npm dependencies for CVE-2021-43307?
Run the dependency tree command: 'npm ls semver-regex'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-4x5v-gmq8-25ch",
  "modified" : "2023-07-19T19:58:13Z",
  "published" : "2022-06-03T00:01:00Z",
  "aliases" : [ "CVE-2021-43307" ],
  "summary" : "Regular expression denial of service in semver-regex",
  "details" : "An exponential ReDoS (Regular Expression Denial of Service) can be triggered in the semver-regex npm package, when an attacker is able to supply arbitrary input to the test() method",
  "severity" : [ ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "semver-regex"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.1.4"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "semver-regex"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0"
      }, {
        "fixed" : "4.0.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-43307"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/sindresorhus/semver-regex/commit/d8ba39a528c1027c43ab23f12eec28ca4d40dd0c"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/sindresorhus/semver-regex"
  }, {
    "type" : "WEB",
    "url" : "https://research.jfrog.com/vulnerabilities/semver-regex-redos-xray-211349"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1333" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-06-03T22:26:33Z",
    "nvd_published_at" : "2022-06-02T14:15:00Z"
  }
}