The safest way to prevent XML bomb attacks is to disable entity expansion when parsing untrusted
-data. How this is done depends on the library being used. Note that some libraries, such as
-recent versions of libxmljs (though not its SAX parser API), disable entity expansion
-by default, so unless you have explicitly enabled entity expansion, no further action is needed.
+data. Whether this can be done depends on the library being used. Note that some libraries, such as
+lxml, have measures enabled by default to prevent such DoS XML attacks, so
+unless you have explicitly set huge_tree to True, no further action is needed.
+
+We recommend using the defusedxml +PyPI package, which has been created to prevent XML attacks (both XXE and XML bombs).
-The following example uses the XML parser provided by the node-expat package to
-parse a string xmlSrc. If that string is from an untrusted source, this code may be
-vulnerable to a DoS attack, since node-expat expands internal entities by default:
+The following example uses the xml.etree XML parser provided by the Python standard library to
+parse a string xml_src. That string is from an untrusted source, so this code is be
+vulnerable to a DoS attack, since the xml.etree XML parser expands internal entities by default:
-At the time of writing, node-expat does not provide a way of controlling entity
-expansion, but the example could be rewritten to use the sax package instead,
-which only expands standard entities such as &:
+It is not possible to guard against internal entity expansion with
+xml.etree, so to guard against these attacks, the following example uses
+the defusedxml
+PyPI package instead, which is not exposed to such internal entity expansion attacks.