DefusedXML
DefusedXML provides XML bomb protection for Python standard library modules, currently at version 0.7.1. The library aims to prevent denial of service attacks by handling malicious XML documents safely.
Warnings
- breaking Support for Python 2 will be removed in version 0.8.0.
- deprecated The defusedxml.cElementTree module is deprecated.
Install
-
pip install defusedxml
Imports
- ElementTree
from defusedxml.ElementTree import ElementTree
Quickstart
from defusedxml.ElementTree import fromstring
xml_data = '<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]><foo>&xxe;</foo>'
try:
root = fromstring(xml_data)
print(root)
except Exception as e:
print(str(e))