Skip to content
medium

XXE via XInclude

An XInclude attack is the way to achieve XXE-style file reads when you only control part of an XML document and cannot add a DOCTYPE: you inject an `xi:include` element referencing a local file, and a parser with XInclude processing enabled substitutes the file's contents into the document.

Target formats
Plain XMLSOAPServer-built XML
Affected parsers
Java (XIncludeAware)libxml via XIncludePython lxml (xinclude)
Impact
Local file disclosureSSRF

How it works

Many applications take client data and embed it inside a larger XML document they build server-side, then parse the whole thing. You cannot add a DOCTYPE because you do not control the top of the document — but you can inject elements into the part you supply.

XInclude is a W3C spec that lets one XML document pull in another. By injecting an xi:include element with the XInclude namespace and an href pointing at a file, you get the same file-read primitive without ever declaring an entity.

Which parser configuration makes it work

Requires XInclude processing to be enabled on the parser (for example a Java factory with setXIncludeAware(true), or lxml with xinclude() called). It does not need DOCTYPE control, which is what makes it useful against embedded-XML endpoints.

Representative payloads

Replace callback hosts and target paths with your own authorized test values.

XInclude file read
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include parse="text" href="file:///etc/passwd"/>
</foo>

parse="text" returns raw bytes and tolerates files that are not well-formed XML.

XInclude to an internal URL (SSRF)
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="http://169.254.169.254/latest/meta-data/"/>
</foo>

Detection

As a tester, inject an xi:include into any field that ends up inside server-built XML and check for the file contents. As a defender, look for the XInclude namespace (http://www.w3.org/2001/XInclude) or xi:include elements in data that originates from clients, and check whether your parser has XInclude enabled at all — it usually should not be.

  • xi:include elements or the XInclude namespace in client data
  • File contents surfacing in responses from endpoints that embed user XML
  • Parser configured with XIncludeAware(true) processing untrusted input

Remediation

Disable XInclude processing on the parser (setXIncludeAware(false) in Java; do not call .xinclude() in lxml) — it is off by default in most stacks and should stay off for untrusted input. Because XInclude bypasses the DOCTYPE, disabling only DOCTYPE is not sufficient here: you must also null the resolver / disable external resource loading so xi:include cannot fetch file:// or http:// targets. Encode or reject client data before embedding it into server-built XML.

Fix checklist

  • Disable XInclude awareness on the parser (primary fix)
  • Null the resolver / disable external resource loading
  • Do not embed raw client data into server-side XML — encode or validate first
  • Remember DOCTYPE-only hardening does not stop XInclude

Parser-specific configuration: Java, Python, PHP.

Related techniques

References