Billion Laughs Attack
A denial-of-service attack using nested XML entity definitions that exponentially expand into gigabytes of data, exhausting server memory.
Billion Laughs Attack (also called XML Bomb or Exponential Entity Expansion) is a denial-of-service attack against XML parsers that uses nested entity definitions to exponentially expand a small XML document into gigabytes of data, exhausting server memory.
How It Works
The attack defines entities that reference other entities in a nested pattern. When the parser expands the final entity, each level multiplies the expansion, creating exponential growth from a small payload.
Expansion Math
- lol = 3 bytes
- lol2 = 10 Γ— lol = 30 bytes
- Each level: 10Γ— previous
- lol9 = 10^9 Γ— 3 bytes = ~3 GB
Impact
- Memory exhaustion β†’ server crash
- CPU exhaustion during parsing
- Denial of service
Prevention
- Disable DTD processing
- Limit entity expansion depth and count
- Set maximum document size limits
- Use streaming parsers with limits