XML and JSON Parser Vulnerabilities
You'll learn how attackers abuse parser behavior to exhaust server resources—even without injecting malicious code.
Beyond Code Injection
While XXE (XML External Entity) attacks inject malicious payloads, parsers themselves can become weapons through their normal processing behavior. Attackers craft specially-structured documents that exploit how parsers handle expansion, nesting, and memory allocation—causing denial of service without touching application logic.
The Billion Laughs Attack
Imagine a compressed file that expands into terabytes. XML entities work similarly:
<!DOCTYPE bomb [
<!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;">
]>
<bomb>&lol3;</bomb>
Each entity expands exponentially. By the 9th level, your server processes billions of "lol" strings, exhausting memory in seconds.
Deeply Nested Structures
Both XML and JSON parsers can choke on extreme nesting:
{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{...}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
Parsers using recursive algorithms consume stack space with each level. After hundreds or thousands of nested brackets, the stack overflows or memory runs out.
Resource Exhaustion Tactics
Attackers leverage:
- Large documents: Multi-megabyte files with millions of elements
- Attribute bombing: XML tags with thousands of attributes
- Deep arrays: JSON arrays nested 10,000 levels deep
- String duplication: Entity expansion creating gigabyte-sized strings
These attacks succeed because parsers faithfully process every element, oblivious to resource constraints.
Defense Strategy
Set hard limits: maximum document size, nesting depth, entity expansion count, and parse time. Disable entity expansion entirely if external entities aren't needed. Use streaming parsers for large documents instead of loading everything into memory.
Key Takeaway:
Parser vulnerabilities exploit legitimate processing behavior—defend by enforcing strict resource limits on document size, nesting depth, and entity expansion before parsing begins.