What is XML External Entity (XXE)?

XML External Entity Injection is often referred to as a variant of Server-side Request Forgery (SSRF). XXE leverages language parsers that parse the widely used data format, XML used in a number of common scenarios such as SOAP & REST web services and file formats such as PDF, DOCX, HTML.

The main issue lies in XML parsers and how by default, they handle outbound network calls as well as other XML-specific features which we will get into. For a broader and more in-depth explanation of XXE, I would highly recommend going over our 2-part series first.

Python XML Libraries

In the Python ecosystem (2.X & 3.X) most if not all XML parsing is handled by the standard libraries:

And in some cases, even beautifulsoup, since as we said HTML is a subset of XML, we can parse XML using it. Good news is that minidom and etree are not vulnerable to XXE by default. As a result we’ll focus on pulldom as it’s tightly knit to sax.

Examples

The following example leverages the pulldom module as well as bottle to create a very minimal web service. It has a single endpoint, POST /pulldom that receives the request body as XML, parses it and returns it back.

Conclusion

With security, the first question when receiving an input is along the lines of, “Where is this data source coming from?”. Given that the two most popular libraries, minidom and etree are safe from XXE attacks (though vulnerable to others) you are generally good to go from the standard library.

The alternative libraries, pulldom and sax are by design, required to pull XML from remote locations, which means that you should avoid using them handling untrusted user XML in any form. Should you still opt to use the aforementioned libraries, you should wrap them with your own safe implementation that sanitizes input prior to processing it.

Vulnerabilities such as XXE and many more can be detected automatically with Acunetix, by leveraging our AcuMonitor service to detect Out-of-Band vulnerabilities.

Share this post

Juxhin Dyrmishi Brigjaj

Acunetix developers and tech agents regularly contribute to the blog. All the Acunetix developers come with years of experience in the web security sphere.