# ReDoS in syntax highlighting due to Rouge

Cubic-complexity regexes in Rouge lexers (Factor, GHC Core, Ceylon) let crafted fenced code blocks or source files pin GitLab CPU for 60s, causing 500/502 DoS.

- Payout: $600
- Severity: medium
- Program: GitLab
- Found by: Doyensec
- Disclosed: 2021-11-15
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1283484
- Library page: https://bugbountylibrary.com/r/h1%3A1283484
- Tags: area:oss domain:oss impact:dos kind:bounty platform:hackerone sev:medium tech:ruby technique:chained technique:source-review vuln:dos

**Target:** GitLab syntax highlighting via Rouge lexers (wiki, markdown, file viewer)
**Root cause:** Rouge lexer regexes have overlapping ambiguous groups (e.g. `"""\s+.*?\s+"""`, `^Result size of .+\s*.*}`, `.*``.*``.*"`) giving cubic worst-case backtracking when the terminating token is absent.
**Steps:**
1. Craft payload: GHC Core `'Result size of ' + ' '*3456`; Factor `'"""' + ' '*3456`; Ceylon `'"' + '`'*3456`
2. For wiki: edit page with fenced block ```ghc-core\nResult size of <spaces>\n```
3. View wiki page -> 500 after ~60s at 100% CPU
4. For file viewer: upload redos.factor/redos.ceylon to repo and view; or README.md with fenced block so every project page visit triggers it
5. For issues/comments: create/edit issue with fenced block; rendering occurs on create/edit
**How found:** Audited Rouge lexer regexes for overlapping/ambiguous quantifiers (multiple `.*`/`\s+` groups matching the same characters) and constructed inputs lacking the terminating token to force catastrophic backtracking; verified cubic scaling by doubling repeat length (8x time).
**Exploitation:** Any user able to create wiki pages, issues, comments, or push files can store a payload that triggers ReDoS on render. Concurrent requests to affected resources exhaust server CPU, causing 500/502 timeouts and blocking wiki access (home page payload blocks all wiki access).
**Escalation:** Storing payload in README.md or wiki home page makes the DoS trigger on every visit, amplifying impact without repeated attacker requests.
**Insight:** When a target embeds a syntax highlighter, enumerate its lexers for regexes with multiple adjacent greedy groups that can match the same character class; a missing terminator token forces backtracking. Test via fenced code blocks in any markdown-rendering surface (wiki, issues, README) to get stored ReDoS.

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

**GHC Core ReDoS payload recipe**

```
GHC Core (.dump-cse): `'Result size of ' + ' ' * 3456`
Factor (.factor): `'"""' + ' ' * 3456`
```

**Ceylon ReDoS payload recipe**

```
Ceylon (.ceylon): ``'"' + '`' * 3456``

As the worst-case complexity is cubic, doubling the length of the repeating part (spaces or backticks) makes processing take 8 times as long.
```

