redos-db › color-string-CVE-2021-29060
Real-world ReDoS: quadratic (n²) catastrophic backtracking
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.
Input that triggers the blow-up: "hwb(" then a run of "1" then "!". A benign input like hwb(120, 0%, 0%) matches in microseconds.
| CVE | CVE-2021-29060 |
| GHSA | GHSA-257v-vj4p-3w2h |
| Weakness | CWE-1333 (Inefficient Regular Expression Complexity) |
| Package | color-string (npm) |
| Affected | <1.5.5 |
| Patched in | 1.5.5 |
| Published | 2021-04-05 |
| Discovered by | Yeting Li |
| Complexity | quadratic (n²) |
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 commit: https://github.com/Qix-/color-string/commit/0789e21284c33d89ebc4ab4ca6f759b9375ac9d3
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 |
|---|---|
| 2505 | 11.6 ms |
| 5005 | 43.7 ms |
| 10005 | 175.8 ms |
| 20005 | 690.5 ms |
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.