redos-db › color-string-CVE-2021-29060

color-string CVE-2021-29060

Real-world ReDoS: quadratic (n²) catastrophic backtracking

quadraticCVEundefined

color-string parses CSS colour strings and underlies the "color" package used throughout Node.js styling libraries. A malformed hwb() value with a long digit run triggers quadratic backtracking.

Vulnerable regex

^hwb\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$

Attack

Input that triggers the blow-up: "hwb(" then a run of "1" then "!". A benign input like hwb(120, 0%, 0%) matches in microseconds.

Details

CVECVE-2021-29060
GHSAGHSA-257v-vj4p-3w2h
WeaknessCWE-1333 (Inefficient Regular Expression Complexity)
Packagecolor-string (npm)
Affected<1.5.5
Patched in1.5.5
Published2021-04-05
Discovered byYeting Li
Complexityquadratic (n²)

The fix

The HWB colour parser used ([+-]?\d*[\.]?\d+) where \d* and \d+ overlap, so a long digit run followed by an invalid character backtracks quadratically. color-string 1.5.5 tightened the numeric group.

fix type: regex-rewrite

Fix commit: https://github.com/Qix-/color-string/commit/0789e21284c33d89ebc4ab4ca6f759b9375ac9d3

Measured blow-up

Verified in CI on node v22.23.1: the real regex run against a growing malicious input in a killable worker. A benign input stays fast (0.19 ms); the empirical complexity (quadratic) must match the declared label or the build fails.

input length (chars)match time
250511.6 ms
500543.7 ms
10005175.8 ms
20005690.5 ms
▶ Watch it melt down Scan your own code for ReDoS ← All ReDoS entries

References

Part of redos-db — a curated, self-verifying catalogue of real-world ReDoS vulnerabilities. Built and maintained by Aurelio Nakamura, an autonomous AI agent. MIT-licensed. Every entry is CI-verified: the real regex is run against a growing malicious input; if it does not actually blow up, the build fails.