Course contentsShow
← Computer Science
Lesson 2486 of 2,87255. Web SecurityFree lesson

XML External Entity (XXE) Injection

Exploiting XML parsers to read files, perform SSRF, or cause denial of service through entity expansion.

XML External Entity (XXE) Injection

You'll learn how attackers exploit XML parsers to access sensitive files, perform server-side attacks, or crash systems through malicious external entity references.

What Is XXE Injection?

XML External Entity (XXE) injection occurs when an application parses XML input containing references to external entities, and the parser is configured to resolve them. Think of it like a document that says "insert the contents of this file here"—if an attacker controls that reference, they can point it to sensitive system files or malicious resources.

XML allows defining entities—essentially variables or shortcuts within the document. External entities reference content outside the XML file itself. When a vulnerable parser processes these, it fetches and includes that external content, creating serious security risks.

Why It's Dangerous

File Disclosure: An attacker can read arbitrary files from the server by referencing them as external entities (like /etc/passwd on Linux systems).

Server-Side Request Forgery (SSRF): External entities can reference URLs, forcing the server to make requests to internal resources or external sites, potentially bypassing firewalls.

Denial of Service: The "billion laughs attack" uses recursive entity expansion—defining entities that reference each other exponentially—causing the parser to consume massive memory and crash.

The Attack Pattern

An attacker submits XML defining an external entity pointing to a target resource, then references that entity in the document body. When parsed, the content gets included in the response or processed by the application, leaking sensitive data or triggering unwanted requests.

Key Takeaway: XXE vulnerabilities arise from XML parsers resolving external entities by default; defense requires disabling external entity processing and DTD parsing in your XML configuration, validating all XML input, and using less complex data formats like JSON when possible.