Skip to content
Free Tool Arena

Glossary · Definition

ReDoS attacks

ReDoS (Regular Expression Denial of Service) is an attack where adversarial input causes a regex to take exponential time to evaluate, freezing the server. Caused by patterns with nested quantifiers like <code>(a+)+</code>. Defense: use linear-time engines (Go RE2), avoid nested quantifiers, or set timeouts.

Updated May 2026 · 4 min read
100% in-browserNo downloadsNo sign-upMalware-freeHow we keep this safe →

Definition

ReDoS (Regular Expression Denial of Service) is an attack where adversarial input causes a regex to take exponential time to evaluate, freezing the server. Caused by patterns with nested quantifiers like <code>(a+)+</code>. Defense: use linear-time engines (Go RE2), avoid nested quantifiers, or set timeouts.

What it means

Regex engines using backtracking (PCRE, Python re, JavaScript) can hit catastrophic backtracking on certain patterns. The classic example: <code>(a+)+$</code> against input <code>aaaaaa!</code>. The engine tries many combinations of how to split the &lsquo;a&rsquo;s among the inner and outer +, exhaustively. For 10 &lsquo;a&rsquo;s, it&rsquo;s milliseconds. For 30 &lsquo;a&rsquo;s, several minutes. For 50 &lsquo;a&rsquo;s, hours. Denial-of-service results: a single malicious request locks the regex thread, blocking subsequent requests. Real-world incidents: Stack Overflow outage 2016 (catastrophic regex on user input), Cloudflare incident 2019 (regex bug crashed proxies globally).

Advertisement

Why it matters

Any web app processing user-supplied regex or user-supplied input through regex is vulnerable. Bug bounties for ReDoS in popular libraries are common. Defense strategies: <strong>(1) Use RE2-based engines</strong> for user input (Go default, Python re2 module, V8 Linear). <strong>(2) Avoid nested quantifiers</strong> like <code>(a+)+</code>, <code>(a|a)*</code>. <strong>(3) Use timeouts</strong> — set max regex execution time (Node.js: implement via worker threads). <strong>(4) Audit dependencies</strong>: package.json regex helpers can carry vulnerable patterns. Tools: <code>safe-regex</code>, <code>vuln-regex-detector</code>, <code>recheck</code> auto-scan for ReDoS-vulnerable patterns.

Example

Vulnerable: <code>^(a+)+$</code> on input <code>aaaaaaaaaaaaaaaaa!</code> takes minutes. Fix: <code>^a+$</code> achieves same match in microseconds. Or use possessive quantifier (PCRE only): <code>^(a++)+$</code> prevents backtracking. Or switch to RE2.

Related free tools

Frequently asked questions

Is JavaScript regex safe?

By default, vulnerable to ReDoS like PCRE. V8 has added some protections in recent versions. For safety on user input, use timeouts via worker threads or switch to a regex library with linear-time guarantees.

What patterns to avoid?

Nested quantifiers: <code>(a+)+</code>, <code>(a*)*</code>. Alternation with overlapping branches: <code>(a|a)*</code>. Use possessive quantifiers (PCRE) or atomic groups <code>(?>...)</code>, or restructure to avoid the issue.

How do I scan my code for ReDoS?

<code>safe-regex</code> npm package, <code>recheck</code> CLI, GitHub CodeQL queries. Most production deployments include automated regex scanning in CI/CD.

Related terms