Home / patterns

Regex denial of service (ReDoS): one crafted input that freezes your app

A developer's desk at night with one monitor showing a code editor with a long regular expression and a second monitor showing a server CPU graph spiking to 100 percent in red
Quick answer: AI-generated code loves regular expressions for checking emails, URLs, phone numbers and passwords. Some of those patterns, especially ones with a repeated group inside another repeat, can take exponentially longer on a carefully crafted input. One request can pin your server's CPU, and in Node.js that blocks every other user at the same time. It's also a risk when your app builds a regex from text the user typed.

Last updated November 11, 2026

Steps

  1. Search your code for regexes used on user input: new RegExp(, .test(, .match(, .replace( and validation libraries' custom patterns, on both the server and in API routes.
  2. Look for the risky shape OWASP calls an "evil regex": a group with repetition that contains repetition or overlapping alternatives, such as (a+)+, ([a-zA-Z]+)* or (a|aa)+.
  3. Never build a regex from user input. If users need to search, escape their text or use plain string methods like includes() instead.
  4. Limit input length before any regex runs. An email field doesn't need 10,000 characters.
  5. Rewrite risky patterns without nested quantifiers, or use a well-tested validation library instead of a hand-made pattern.
  6. Where possible, use a regex engine without backtracking (for example RE2-based libraries) for untrusted input, or set backtracking or time limits in your runtime.
  7. Add rate limiting so one client can't send these inputs over and over, and keep dependencies updated, since ReDoS bugs are often fixed in library releases.

Why it matters

MITRE tracks this as CWE-1333 (Inefficient Regular Expression Complexity): a regular expression whose worst-case complexity is inefficient and possibly exponential. MITRE lists the impact as denial of service through CPU consumption, with high likelihood, because attackers can craft inputs that cause excessive backtracking. Its mitigations are to use regexes that don't backtrack (for example by removing nested quantifiers), set backtracking limits, avoid running regexes on untrusted input, and limit input length. OWASP's ReDoS page explains that most regex engines try every possible path when a match fails, gives examples like ^(a+)+$ where each extra character doubles the work, and warns that if a regex itself is built from user input, an attacker can inject an evil pattern.

Sources

MITRE CWE-1333: Inefficient Regular Expression Complexity — https://cwe.mitre.org/data/definitions/1333.html

OWASP: Regular expression Denial of Service - ReDoS — https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS

Checked at the source on November 2, 2026.

Related patterns

Found a problem you'd rather not fix yourself?

Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.

Get it fixed by StorenTech

Vibe Security Weekly

One email a week with new failure patterns and how to fix them.

By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.