What is ReDoS?
Regular Expression Denial of Service (ReDoS) happens when a regex engine spends excessive time backtracking on crafted input. Engines based on non-deterministic finite automata with backtracking (including JavaScript's RegExp) can exhibit exponential or very steep polynomial time on ambiguous patterns such as nested quantifiers or overlapping alternation.
Vulnerable patterns to watch
Classic examples include nested (a+)+, overlapping branches like (a|aa)+, and adjacent quantifiers over overlapping character classes (for example \d+\d+ or \s+\s+) where the engine can split the same span in many ways before failing a later constraint.
Real-world incidents
Cloudflare, July 2019: a complex WAF regex led to catastrophic backtracking on certain payloads and contributed to a major global outage. The incident underscored how a single ambiguous pattern at the edge can amplify into wide impact.
Cloudflare, November 2025: a lengthy partial outage was not caused by ReDoS — a configuration file grew past a hard-coded limit after duplicated rows from a database change. It still illustrates fail-closed concerns: systems that process externally influenced data without strict bounds can fall over from size or complexity whether the trigger is regex, configuration, or payload shape.
Stack Overflow, July 2016: a ReDoS in markdown trimming regex caused a partial outage, showing that even "simple" string cleanup can be dangerous on adversarial Unicode and whitespace.
How to fix or mitigate
- Rewrite the pattern to remove nested quantifiers and ambiguous splits. Example: prefer
\w+(?:\s+\w+)*over(\w+\s*)+. - Atomic-style matching in JS via the
regexnpm package (lookahead emulation). Native(?>...)groups are not in standard JavaScript yet (TC39 Stage 1 as of 2026); Java, PCRE, Python 3.11+, and .NET may offer native equivalents. - Linear-time engines for critical paths: RE2 (Node
re2, Go,google-re2in Python), Rust'sregexcrate — typically no backreferences or lookarounds. - Cap untrusted input length before matching; bound work even when the pattern is imperfect.
Further reading: OWASP ReDoS.