+Parsing XML input with external entity (XXE) expansion enabled while the input +is controlled by a user can lead to a variety of attacks. An attacker who +controls the XML input may be able to use an XML external entity declaration +to read the contents of arbitrary files from the server's file system, perform +server-side request forgery (SSRF), or perform denial-of-service attacks. +
+
+The Rust libxml crate (bindings to C's libxml2
+library) exposes several XML parsing functions that accept a parser options
+argument. The options XML_PARSE_NOENT and
+XML_PARSE_DTDLOAD enable external entity expansion and loading of
+external DTD subsets, respectively. Enabling these options when parsing
+user-controlled XML is dangerous.
+
+Do not enable XML_PARSE_NOENT or XML_PARSE_DTDLOAD
+when parsing user-controlled XML. Parse XML with safe options (for example,
+using 0 as the options argument) to disable external entity
+expansion.
+
+In the following example, the program reads an XML document supplied by the +user and parses it with external entity expansion enabled: +
++The following example shows a corrected version that parses with safe options: +
+