# Regexes with large repetitions on empty sub-expressions take a very long time to parse

Rust regex crate's memory-based DoS mitigations were bypassed by repeating empty sub-expressions, causing unbounded CPU consumption during regex compilation.

- Payout: $4,000
- Severity: high
- Program: Internet Bug Bounty
- Found by: addisoncrump
- Disclosed: 2022-03-22
- CVE: CVE-2022-24713
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1518036
- Library page: https://bugbountylibrary.com/r/h1%3A1518036
- Tags: area:oss domain:oss impact:dos kind:bounty platform:hackerone sev:high tech:rust technique:source-review vuln:dos

**Target:** rust-lang/regex crate compiler (regex parsing/compilation)
**Root cause:** DoS mitigations limited memory usage of compiled regex, but repetitions of empty sub-expressions allocate zero bytes, so `(?:){N}` and nested repetitions `(?:){64}{64}...` bypass the memory cap while forcing exponential compile-time work.
**Steps:**
1. Identify service accepting untrusted regexes compiled with regex crate <=1.5.4.
2. Send payload `(?:){4294967295}` to force 4294967295 empty sub-expression instances (zero-byte allocations, bypassing memory mitigation).
3. Escalate with nested repetitions `(?:){64}{64}{64}{64}{64}{64}` to force 64^6 instances and exponential compile time.
4. Observe CPU exhaustion and service unavailability.
**How found:** Researcher reasoned that existing mitigations were memory-usage based, hypothesized that zero-byte allocations (empty sub-expressions) would evade them, and tested large repetition counts and nested repetitions.
**Exploitation:** Attacker submits crafted regex to any endpoint that compiles user-supplied regexes with the vulnerable crate; the compiler loops allocating/processing empty sub-expression repetitions, consuming effectively infinite CPU and denying service.
**Escalation:** Chaining repetitions-of-repetitions (`(?:){64}{64}{64}{64}{64}{64}`) converts linear-ish blowup into exponential time complexity relative to regex length.
**Insight:** When a DoS defense caps a resource (memory), look for inputs that accomplish the same amplification while consuming zero of that resource—empty sub-expressions, zero-width constructs, or nested quantifiers are prime candidates.

## Proof of concept (copied exactly from the original report)

**Nested repetition payload causing exponential blowup**

```
(?:){64}{64}{64}{64}{64}{64}
```

