Courses

XML External Entity Injection
OSWE · Chapter 22

XML External Entity Injection

XML External Entity (XXE) injection abuses XML parsers that resolve external entity references by default, letting an attacker read local files, perform SSRF, or cause denial of service — entirely from a maliciously crafted XML document.

Key concepts

  • The classic PoC declares an external entity pointing at a local file (`file:///etc/passwd`) and references it inside the XML body so the parser inlines the file contents into the parsed result.
  • XXE can also be used for SSRF by declaring an entity pointing at an internal-only HTTP URL instead of a local file.
  • The single most effective fix is disabling DTD processing and external entity resolution entirely at the parser level — most modern XML libraries default to safe behavior, but many still ship unsafe-by-default in older configurations.
  • XXE is frequently reachable through unexpected surfaces: SOAP APIs, file uploads (DOCX/XLSX are ZIP archives of XML), and even SVG image uploads.

Example

<?xml version="1.0"?>
<!DOCTYPE data [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<data>&xxe;</data>

Try it yourself

On a lab XXE challenge, submit the classic file-read payload above against an endpoint that parses XML, and confirm whether the response reflects the target file's contents.

@ Daniel Burlacu