XXE Fundamentals and XML Parsing
You'll learn how XML parsers can be tricked into fetching external resources, creating a dangerous vulnerability called XML External Entity (XXE) injection.
What is XXE?
XML External Entity (XXE) injection exploits how XML parsers handle external entities — references to data stored outside the XML document itself. When an application processes XML input without proper safeguards, attackers can define malicious external entities that the parser automatically resolves, leading to data exposure, server-side request forgery, or denial of service.
How XML Parsing Works
XML documents can include a Document Type Definition (DTD), which defines the structure and entities for that document. Entities act like variables:
<!DOCTYPE message [
<!ENTITY greeting "Hello">
]>
<message>&greeting; World</message>
The parser replaces &greeting; with "Hello" — harmless so far.
The Vulnerability: External Entities
Here's where danger enters. XML allows external entities that reference external resources:
<!DOCTYPE hack [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<data>&xxe;</data>
When a vulnerable parser processes this, it reads /etc/passwd from the server's filesystem and includes it in the XML. The attacker just read sensitive files!
Why This Happens
Many XML parsers resolve external entities by default for backward compatibility. They automatically fetch and include referenced resources without asking permission. Developers often don't realize their parser is doing this behind the scenes.
Key Takeaway: XXE vulnerabilities occur when XML parsers automatically resolve external entity references in untrusted input, allowing attackers to read local files, probe internal networks, or cause denial of service — all because parsers follow DTD instructions too obediently.