Documentation Index
Fetch the complete documentation index at: https://docs.bytejmp.com/llms.txt
Use this file to discover all available pages before exploring further.
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
| Pattern | Why Vulnerable |
|---|---|
(a+)+$ | Nested quantifiers — $ forces failure, exponential backtracking |
(a|aa)+$ | Alternation overlap — engine tries all branch combos before failing |
([a-zA-Z]+)*$ | Outer * + inner + over same charset — exponential splits |
(a*)*$ | Nested Kleene stars — exponential empty-match combinations |
^(\w+\s?)*$ | Anchors force full-string match — exponential partition of word chars |
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
| Tool | Use |
|---|---|
| regexploit | Generate exploit strings for vulnerable patterns |
| vuln-regex-detector | Static analysis — detect vulnerable patterns |
| ReDoS checker | Online — paste pattern, get verdict + exploit string |
| regex101 | Online — build and debug regex with step-by-step match trace |
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.