Skip to main content

Overview

ReDoS (Regular Expression Denial of Service) abuses backtracking behavior in regex engines. A crafted input forces the engine into exponential or polynomial time evaluation, stalling the application. Most languages use NFA-based engines (PCRE, Java, Python re, JavaScript). These are vulnerable. DFA-based engines (Go regexp, RE2) are immune.

How Backtracking Works

Vulnerable pattern: ^(a+)+$ Input: "aaaaaaaaaaaaaaaaab" Engine tries every combination of how (a+) groups can split the as before failing on b. With n characters, attempts grow as 2^n.

Vulnerable Patterns


Identifying Vulnerable Targets

Black-Box Detection

Send inputs that grow exponentially and measure response time:
Response time doubling with each added character = strong signal.

Source Code Audit

Look for regex applied to user-controlled input:

Exploitation

Payload Generation

General approach — find the prefix before a failing anchor, repeat the vulnerable group:
Automate with vuln-regex-detector or regexploit:

Node.js Example

Python Example


Tools


Mitigation (Reference)

  • Replace NFA engines with RE2/Hyperscan where possible
  • Enforce input length limits before regex evaluation
  • Use atomic groups or possessive quantifiers if engine supports
  • Timeout regex evaluation (Python signal, Java ExecutorService)
Test only in authorized environments. Sending ReDoS payloads to production systems without permission = unauthorized DoS.