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, Pythonre, 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: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: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, JavaExecutorService)
Test only in authorized environments. Sending ReDoS payloads to production systems without permission = unauthorized DoS.