DedSec Security Research ·
Here is a hypothetical. A dynamic scan of a staging environment returns three findings against XML-handling endpoints. The first, titled "XML external entity (XXE) injection" and rated high, is on /api/import, which accepts a document and returns a summary of it. The scanner sent a document whose DOCTYPE declared an entity pointing at a local file, and the summary it got back contained the first line of that file. The second, titled "Possible blind XXE" and rated medium, is on /soap/InvoiceService. Every response was an identical SOAP fault, but when the scanner pointed a payload at a host it controlled, its listener logged a DNS lookup. The third is on /upload/avatar, which takes an SVG, and the scanner reported it clean: its DOCTYPE payloads came back with the image unchanged and no error.
The first gets escalated, because high is high. The second is parked, because "possible" and a lone DNS lookup sound like a guess. The third is never looked at. As in the earlier posts in this series, each call rests on the title and the rating rather than on what the scanner observed and what that observation can prove.
This post is for whoever is holding an XXE finding from a dynamic scan, or a clean result on an XML endpoint that they are about to rely on. It covers what an entity and a DTD are mechanically, what CWE-611 is and the claim a finding has to support, the four classes of evidence and what each proves, which parsers resolve entities by default and which option turns the behaviour on, where XML hides in formats that do not look like XML, the file-disclosure channels that need no network at all, the false positives and the false negatives, the hardening each parser needs, and a triage checklist. It is the ninth post in a series about confirming DAST findings, after reflected XSS, SQL injection, OS command injection, Nuclei template matches, ffuf content discovery, path traversal, open redirect and SSRF through URL-fetch parameters. XXE overlaps the last two: an external entity can make the parser fetch a URL, which is server-side request forgery driven by a parser rather than by a URL field, and the out-of-band channel it uses is the one described in out-of-band testing and blind SSRF. This post refers back to those rather than repeating them.
Sources, and how each was checked. The passages described below were read on our test machine on 1 November 2026: the docstring of lxml's XMLParser, read through Python's help system, which states its option defaults and when they changed; the source of python-docx's XML parser, read from the installed package; and the error strings are the ones the parsers printed. CWE-611 (improper restriction of XML external entity reference), CWE-776 (the entity-expansion or "billion laughs" denial of service), the XML 1.0 specification's treatment of general, parameter, internal and external entities and of the document type definition, the SOAP, SAML, SVG, and Office Open XML (DOCX, XLSX) formats, and the libxml2 parser option constants are cited by name and described in our own words, because we had no copy of them on the machine to quote from.
The measurements were made the same day in a scratch directory on an Ubuntu 24.04 machine, inside a Linux network namespace with only a loopback interface. We confirmed the isolation before the runs: a lookup of an external name such as example.com failed, and the query for it appeared in our own logging DNS server rather than leaving the machine. The software was Python 3.12.3 (Ubuntu package 3.12.3-1ubuntu0.17), whose standard-library XML modules are built on expat, reported by the interpreter as expat_2.6.1 (system libexpat1 2.6.1-2ubuntu0.6); lxml 6.0.2, built against and bundling libxml2 2.14.6; the separate system libxml2 2.9.14 (package 2.9.14+dfsg-1.3ubuntu3.10), which we drove directly through its C entry point so that we could set each option flag explicitly; python-docx 1.2.0; and Node.js 22.22.2 with two XML libraries already present on the box, sax 1.4.1 and fast-xml-parser 5.2.5. The hardening library defusedxml was not installed, and xmllint was not present, so neither was measured; where this post mentions them it says so. We did not measure Java, .NET, PHP, Go or any particular web framework. Where this post says something about them, it is written as mechanism, not as a measurement. A logging DNS server and an HTTP listener on loopback stood in for the scanner's out-of-band host. Each file the payloads tried to read held a random token generated when the lab started, so a leak could be shown to carry a value the requester could not otherwise have known. The scripts, payloads, rendered documents and per-case results, including the listener log lines for each case, are kept. The opening scenario is hypothetical, and no number in this post measures any scanner, ours included.
An XML document can declare a document type definition, the DTD, in a <!DOCTYPE ...> block at the top. The DTD can declare *entities*, which are named substitutions. Where the body of the document later references an entity by name, the parser replaces the reference with the entity's value. There are two axes that matter for this vulnerability.
The first is general versus parameter. A general entity is referenced in the document body with an ampersand and a semicolon, as in a reference to an entity named x written &x;. A parameter entity is referenced inside the DTD itself, with a percent sign, as in %p;. Parameter entities are the more dangerous of the two, because they can be used to build further declarations, which is what the out-of-band and error-based techniques below rely on.
The second is internal versus external. An internal entity has its value written inline: a declaration that sets an entity to a literal string. An external entity gives a SYSTEM identifier, which is a URI, and its value is whatever that URI yields. file:///etc/hostname is a local file. http://host/ is a network fetch. The whole weakness is that a parser, told to resolve an external entity, will open that URI.
So the raw material of XXE is a document that declares an external entity and then references it. Whether anything happens depends entirely on the parser's configuration, and the rest of this post is mostly about measuring that configuration rather than about the payloads, which are the easy part.
CWE-611 is the server resolving an external entity reference in XML that came from input it does not control. The consequences divide into three: reading a file off the server, in band or out of band; making the server issue a request, which is SSRF by way of the parser; and, as a separate weakness tracked under CWE-776, exhausting memory or CPU through entity expansion.
The weakness is not that the application parses XML. Almost everything parses XML somewhere. The weakness is that the parser was left in, or switched into, a mode where it treats attacker-supplied external identifiers as things to fetch. So the claim a finding has to support has two halves, and a scanner often proves only a weak version of the first:
The gap between the two halves is the whole problem, because, as the measurements below show, most of the parsers we measured will, in their default configuration, parse a DOCTYPE and still refuse to resolve an external entity. A finding built only on the first half is a common false positive in this class.
In-band disclosure. The application returns the resolved entity's value in its response: a file's contents appear in a field, a summary, or an echoed value. This is the strongest evidence, and the content decides how much it proves. If the returned content is a file we planted on the server with a value the scanner could not have guessed, it proves both halves. In our lab every target file held a random token, so a response carrying that token is proof of a read. On a real system the equivalent is content specific to the host, such as a line from a configuration file or the host name. A generic success message is not enough.
There is a sharp limit on in-band disclosure that matters for triage. A general external entity substitutes the file's contents *into the XML document*, and the parser then continues parsing. If the file contains an ampersand or a <, the parse fails. We measured this directly: a file whose contents were plain text was read and returned, but a file that contained an ampersand and a <b> tag made both libxml2 builds abort with "xmlParseEntityRef: no name", and nothing came back in the parsed result. The error is a different matter. The system libxml2 2.9.14 printed the offending line of the file, token included, in its error output, so an application that returns parser errors would still have disclosed it. lxml's error named only the file and the position. This is why the out-of-band, error-based and CDATA-wrapping techniques exist: they target file contents that in-band general-entity reads cannot carry. A clean result on an in-band test can simply mean the target file was not plain text.
Error-based disclosure. The parser is steered into an error whose message contains the data. The standard mechanism uses parameter entities to build, from the file's contents, a reference to a path that cannot exist, so the parser reports the failed path and the path contains the file. We measured this against the system libxml2 2.9.14: a document that declared a parameter entity for a local file and then referenced that file's contents inside an invalid URI produced a parser error reading, in part, "Invalid URI: file:///nonexistent/" followed by the random token from the target file. The data arrived in the error text, not in the response body. Error-based disclosure matters because it works where in-band does not, and because it can work with no network: everything happened between the parser and the local disk. It depends on the application returning or logging parser error detail, which is a reason, covered below, not to.
Out-of-band callback. The document makes the parser fetch a URI on a host the attacker controls, and the attacker's listener records the request. This is the channel for blind XXE, where the response never changes. It splits into two sub-cases that are easy to confuse, and we measured both. A DNS-only callback means the parser resolved the host name but the connection did not complete. We pointed a payload at a name that resolved to an address with no route; our DNS server logged the lookup, but no HTTP request arrived. A full HTTP callback means the request reached the listener. The distinction is the same one drawn in the out-of-band post: a DNS lookup proves that something read far enough into the document to resolve a name, which is weaker than an HTTP hit, and, as that post notes, a lookup can come from a validator, a security gateway or a resolver rather than from the parser itself. An out-of-band callback proves the parser fetched a URI. Turning that into file exfiltration is a further step, and in our tests the second stage failed every time. The nested-parameter-entity technique fetched the attacker's external DTD, so the first callback arrived. The second request, which was meant to carry the file's contents in its URL, was never sent. That held even for a one-line file of letters, digits and hyphens: the file's trailing newline ended up in the URL, and libxml2 2.9.14 rejected it as an invalid URI. Its parser error printed the URL it had built, file contents included. So out-of-band exfiltration turned into error-based disclosure: the data came back in the error output, not to the listener. A file with no trailing newline, or a parser that encodes the URL differently, may behave otherwise. We did not test either.
Entity-expansion denial of service. The "billion laughs" document declares nested entities so that a small file expands to gigabytes. A variant, which we did not measure, points a parameter entity at a large external file instead. This is CWE-776, a denial of service, and it is the one evidence class a dynamic scanner should not actually fire against a running system, because confirming it means degrading or crashing the service you are testing. We sent a nested-entity document, inside a memory limit and a timeout, to the three Python standard-library modules, to lxml, and to the system libxml2. Expat 2.6.1, through all three of Python's standard XML modules, refused it with "limit on input amplification factor (from DTD and entities) breached". lxml's libxml2 2.14.6 refused it with "Maximum entity amplification factor exceeded". The older system libxml2 2.9.14 also refused it, with "Maximum entity amplification factor exceeded" and "Detected an entity reference loop". All three engines have an amplification guard that is on by default. We did not send the document to the two Node.js libraries, and fast-xml-parser does expand internal entities, so its behaviour here is unmeasured. A scanner that wants to assess exposure to this class should do it by identifying the parser and its version, not by trying to exhaust a live server's memory. A finding here should describe the mechanism and the parser, not a measured crash.
This is the measurement that decides most XXE findings, so we drove each parser over the same set of documents and recorded, for each, whether it expanded an internal entity, resolved an external general entity pointing at a local file, and fetched an external DTD or parameter entity over the network. Defaults are what matter, because a vulnerability is almost always a parser left as it came rather than one deliberately opened up.
Python standard library, on expat 2.6.1. xml.etree.ElementTree, xml.dom.minidom and xml.sax, in their default configurations, all expanded an *internal* entity. None of them resolved an *external* entity. ElementTree raised "undefined entity" on a general external entity, and minidom and the default SAX reader silently produced an empty value and made no network request. No file was read and no callback arrived from any of the three. ElementTree and minidom do not resolve external entities, and the SAX reader's external-entity feature is off by default. That feature matters. With only feature_external_ges set to True on the SAX parser, it read our planted file and returned the token. External general entities are resolved as soon as that switch is on. The parameter-entity switch, feature_external_pes, cannot be turned on at all on this build: setting it raised "SAXNotSupportedException: expat does not read external parameter entities". Our first harness set both switches in one go, so the exception masked the general-entity leak, and a separate run with one switch at a time found it. The standard library is safe here only while it is left at its defaults. A finding that claims an in-band XXE file read against stock ElementTree deserves a hard look, because stock ElementTree did not do it here. A finding against a SAX handler deserves a look at whether feature_external_ges is set anywhere.
Two caveats on the standard library. First, xml.etree.ElementInclude is a separate, opt-in XInclude helper; in our test it treated a file:// URL as a literal filename and failed, so it was not a file-read primitive here, but XInclude in general is one, as the lxml result shows. Second, "not vulnerable to external entities by default" is not "safe": these modules still process a DOCTYPE and still expand internal entities, so the amplification class is the one to reason about, and that is handled by the expat guard above.
lxml 6.0.2, on libxml2 2.14.6. The default lxml.etree parser expanded an internal entity but did not resolve an external general entity, raising "Entity 'x' not defined". An external *parameter* entity pointing at our HTTP listener was refused with "Attempt to load network entity". An external DTD subset, named in the DOCTYPE, was skipped silently, because DTD loading is off by default. The reason for the first result is a changed default, and it is worth stating precisely because so much older advice assumes the opposite. The XMLParser docstring on this build describes its resolve_entities option as taking True, False, or the value 'internal', and records that "The default used to be True and was changed to 'internal' in lxml 5.0". So lxml from version 5.0 onward resolves internal entities only, by default. We confirmed both sides of that. With resolve_entities=True set explicitly, the external general entity read our planted file and returned the token, and with the default left alone, it did not. The default is not a complete block, though. In a separate run, the default parser loaded a *local* external parameter entity, a DTD fragment on disk, and used the entity it declared. Network access is a separate question, and on this build the answer was simple. lxml made no network request in any configuration we tried. That included no_network=False alone and with load_dtd=True: our HTTP and DNS listeners logged nothing for any network payload. The bundled libxml2 2.14.6 reports no HTTP support: lxml's LIBXML_FEATURES lists catalog, html, iconv, regexp, schematron, xmlschema, xpath and zlib, and no http. That is a property of this build, not a guarantee. A custom resolver registered with the parser, or an lxml linked against a libxml2 built with HTTP support, can fetch. The version line matters too. On lxml below 5.0, the same code would have resolved external entities by default. Cite the version you measured, because this is exactly the kind of default that changes within a major API.
One more lxml result belongs here because it is a file-disclosure path that has nothing to do with entity resolution. XInclude is a separate feature, invoked explicitly. When we built a document with an xi:include element pointing at a local file and called the parser's XInclude step, it read the file and inlined its contents, returning the token, even though entity resolution was at its safe default. XInclude is its own switch and its own finding. A parser hardened against entities can still be an XInclude file-read primitive if the application calls that step on attacker input.
python-docx 1.2.0. This matters for upload endpoints, below. The package's installed source constructs its XML parser with resolve_entities=False. We parsed our entity documents through that exact parser object and saw no file read and no callback; the entity reference was left in the tree as an unresolved entity reference. So this version of python-docx does not expand external entities in the XML parts of a document by default. That is a statement about python-docx 1.2.0's own parser configuration, which we read and exercised, and not about every library that opens a DOCX.
The system libxml2 2.9.14, driven directly with explicit option flags. This is where the mechanism is clearest, because libxml2's behaviour is entirely a function of which option bits are set, and higher-level bindings differ only in which bits they set for you. With no options, it did not substitute entities at all and made no request. Setting the substitute-entities option on its own caused it to read the local file for a general entity and return it, and to attempt the network fetch for an external general entity; our HTTP listener logged the request, and the DNS server logged the lookup. Setting the load-external-DTD option on its own caused it to fetch an external DTD and parameter entity, producing a callback, even without entity substitution: that is the out-of-band channel that needs only DTD loading. Setting both gave both. The result that matters most for hardening: adding the no-network option stopped every callback, with the loader reporting "Attempt to load network entity", but it did not stop the local file read — with no-network set, the file entity still returned the token. Disabling the network does not disable local file disclosure. To stop that you must not substitute external entities and not load external DTDs in the first place.
Node.js libraries. sax 1.4.1, in strict mode, did not resolve external entities; it reported the presence of a DOCTYPE and refused an unknown entity reference with "Invalid character entity", and made no request. fast-xml-parser 5.2.5 expanded an internal entity but refused an external general entity with the explicit message "External entities are not supported" and refused a parameter entity with "Invalid entity name". Neither library read a file or produced a callback in its default configuration in our tests. As with the Python standard library, the honest summary is "did not resolve external entities by default here", not a guarantee for every Node XML library, several of which exist and some of which wrap libxml2.
The pattern across all of this: the engines we measured, in their current versions and default configurations, mostly do not resolve external entities, and the amplification guard is on. The dangerous configurations were the ones where a flag had been set, deliberately or by a wrapper, to turn resolution or DTD loading on. That is good news for defenders and a warning for triage, because it means a confident in-band XXE finding against a default-configured modern parser is worth re-checking before it is escalated.
An XXE finding is often on an endpoint that does not look like an XML endpoint, which is also where a scan most often misses one. The mechanisms below are general; we did not test these specific frameworks, and say so.
Two of the measured techniques work with the network fully blocked, and they are worth separating because a defender who stops at "we disabled outbound traffic from the parser" has not closed them.
The first is in-band and error-based local file disclosure. As measured, no-network on libxml2 2.9.14 still read the local file. If the application returns parsed content or detailed errors, file contents come back over the normal response channel with no outbound connection at all.
The second is the local-DTD technique. The error-based method usually needs an attacker-hosted DTD, but if a DTD file already exists on the server's disk, a payload can load that local DTD and redefine a parameter entity inside it to carry out the same error-based read. We measured a version of this against libxml2 2.9.14 using a DTD we had placed on the local disk as a stand-in for one shipped by the platform, and it produced the same error containing the file token, with no-network set. Operating systems and application packages often ship DTD files. The defensive point is the one that matters: blocking the network is a good control for the out-of-band and SSRF halves of XXE, and it does nothing for local file disclosure. Only not processing external entities and external DTDs closes that.
And the false negatives, which matter more because they produce a clean result with no finding to triage:
The procedure below is general practice. Point every external reference either at a listener you control or at a local file that is explicitly in scope and harmless to read, such as a file you placed for the test. Read, never write. The point is to prove resolution, not to use it.
All of this is general practice. The one rule that covers every parser we measured: do not process external entities or external DTDs on input you do not control, and keep the entity-expansion guard on. How you say that differs by library.
feature_external_ges on a SAX parser that reads untrusted input. As measured above, that one switch turns file disclosure on. The usual recommendation is the defusedxml package, which wraps the standard parsers. As documented, it refuses entity declarations and external references by default, and refuses DTDs only when forbid_dtd=True is passed. It was not installed on our machine, so this is unmeasured general practice.resolve_entities=False explicitly rather than relying on the default. The default is 'internal' from version 5.0, and it still loads local external parameter entities, as measured above. Keep no_network True, and do not set load_dtd. We ran a parser configured with resolve_entities=False, no_network=True and DTD loading off over the full payload set. No file was read, no callback arrived, and entity references were left as unresolved entity references. If you use XInclude, do not run the XInclude step on untrusted input, because it is a file-read path independent of entity settings.Static analysis models XXE as the construction or use of an XML parser whose options enable DTD processing or external-entity resolution on a source of untrusted data. The SAST false positive post covers the general failure of crediting a sanitiser against a sink it does not protect, and XXE is a clean example of its own difficulty: the dangerous property is a *default*, and a default is invisible in the code. A rule that flags a parser construction only when it sees an explicit dangerous option set will miss every vulnerable parser that is dangerous *because nothing was set* — which, on an old enough library, is the common case. A rule that flags every XML parse as XXE will fire on every safe parser on a modern library. Being precise here requires knowing the library and the version, exactly as confirming the dynamic finding did. This is where a reviewer has to check which library and which version, not just whether an option appears.
A confirmed DAST finding tells you that a deployed endpoint resolved an external reference on input, but not which parser construction in the code did it or whether another code path shares the flaw. A SAST finding tells you which parser construction processes untrusted XML, but not whether a reachable route feeds it attacker input or whether the running version's defaults make it exploitable. Each answers the other's open question, and both benefit from the same fact: the version.
Back to the three hypothetical findings.
In the scenario, the /api/import finding was real, and the scanner's single in-band read understated how many channels were open. The scanner's in-band read had returned the first line of a plain-text file. Confirmed by hand, the parser was an older XML library with external-entity resolution enabled, and both an error-based read and an out-of-band callback worked. The fix disabled external entities and external DTDs on that parser, rejected DOCTYPEs at the endpoint, and the retest ran the in-band, error-based and out-of-band channels; none returned data. The rating stayed high while open, because it was genuine.
In the scenario, the /soap/InvoiceService finding was real and the "possible, medium" rating understated it. The lone DNS lookup was the weak end of an out-of-band callback, but a follow-up with an attacker-hosted DTD produced a full HTTP request from the service's egress, and the SOAP fault, which echoed detail, carried an error-based read. It was confirmed as blind XXE with both an out-of-band and an error-based channel. The parser was hardened, and fault detail was removed from the response.
In the scenario, the /upload/avatar clean result was a false negative waiting to be checked. The SVG rasteriser used a DTD-processing parser, and the in-band test had failed only because the file it tried to read contained XML metacharacters. An out-of-band probe through a parameter entity produced an HTTP callback, and an error-based read returned file contents. The finding that the scan had marked clean was the most serious of the three on an unauthenticated endpoint.
AppSecD's dynamic and API testing runs Nuclei, Dalfox, SQLMap, Commix, Katana, Arjun, FFuf and Interactsh for out-of-band detection, plus 150+ native checks and API discovery across 50+ web frameworks. In its lifecycle this is the runtime stage: DAST and API testing run against the deployed application, because code review cannot see an injection that only appears once the application is assembled and running. Its static analysis includes dataflow taint analysis that traces source to sink across functions. Its AI layer assembles attack chains across findings, showing how separately unremarkable issues combine. Its findings are deduplicated across scans and tracked through new, reopened and fixed states, and they need maker-checker approval to close, so a finding cannot be closed unilaterally.
That is the whole claim, and data/products.ts, the single source of truth for what these products do, does not mention XXE at all. So this post does not claim that AppSecD has a dedicated XXE check, whether its Interactsh out-of-band detection is applied to XML-parsing endpoints, which documents, entities, DTDs or channels it sends, whether it tests SOAP, SAML or SVG, DOCX and XLSX uploads or alternate content types, how it tells an in-band read from an echoed payload or a validator's DNS lookup from a parser's, how it rates the severity of an XXE finding, whether its attack-chain assembly links XXE to other findings, whether its static rules account for a parser's version-dependent defaults, or how accurate any XXE detection would be. The measurements, the confirmation procedure, the fixes and the checklist above are general practice, not a description of how AppSecD works internally, and they apply to any scanner's output, ours included. The scenario in this post is hypothetical and does not describe any AppSecD deployment, user or finding.