diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/library%2Fxml.html | |
new repository
Diffstat (limited to 'devdocs/python~3.12/library%2Fxml.html')
| -rw-r--r-- | devdocs/python~3.12/library%2Fxml.html | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fxml.html b/devdocs/python~3.12/library%2Fxml.html new file mode 100644 index 00000000..3db9b4c2 --- /dev/null +++ b/devdocs/python~3.12/library%2Fxml.html @@ -0,0 +1,32 @@ + <span id="xml-processing-modules"></span><span id="xml"></span><h1>XML Processing Modules</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/xml/">Lib/xml/</a></p> <p>Python’s interfaces for processing XML are grouped in the <code>xml</code> package.</p> <div class="admonition warning"> <p class="admonition-title">Warning</p> <p>The XML modules are not secure against erroneous or maliciously constructed data. If you need to parse untrusted or unauthenticated data see the <a class="reference internal" href="#xml-vulnerabilities"><span class="std std-ref">XML vulnerabilities</span></a> and <a class="reference internal" href="#defusedxml-package"><span class="std std-ref">The defusedxml Package</span></a> sections.</p> </div> <p>It is important to note that modules in the <a class="reference internal" href="#module-xml" title="xml: Package containing XML processing modules"><code>xml</code></a> package require that there be at least one SAX-compliant XML parser available. The Expat parser is included with Python, so the <a class="reference internal" href="pyexpat#module-xml.parsers.expat" title="xml.parsers.expat: An interface to the Expat non-validating XML parser."><code>xml.parsers.expat</code></a> module will always be available.</p> <p>The documentation for the <a class="reference internal" href="xml.dom#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code>xml.dom</code></a> and <a class="reference internal" href="xml.sax#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code>xml.sax</code></a> packages are the definition of the Python bindings for the DOM and SAX interfaces.</p> <p>The XML handling submodules are:</p> <ul class="simple"> <li> +<a class="reference internal" href="xml.etree.elementtree#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code>xml.etree.ElementTree</code></a>: the ElementTree API, a simple and lightweight XML processor</li> </ul> <ul class="simple"> <li> +<a class="reference internal" href="xml.dom#module-xml.dom" title="xml.dom: Document Object Model API for Python."><code>xml.dom</code></a>: the DOM API definition</li> <li> +<a class="reference internal" href="xml.dom.minidom#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code>xml.dom.minidom</code></a>: a minimal DOM implementation</li> <li> +<a class="reference internal" href="xml.dom.pulldom#module-xml.dom.pulldom" title="xml.dom.pulldom: Support for building partial DOM trees from SAX events."><code>xml.dom.pulldom</code></a>: support for building partial DOM trees</li> </ul> <ul class="simple"> <li> +<a class="reference internal" href="xml.sax#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code>xml.sax</code></a>: SAX2 base classes and convenience functions</li> <li> +<a class="reference internal" href="pyexpat#module-xml.parsers.expat" title="xml.parsers.expat: An interface to the Expat non-validating XML parser."><code>xml.parsers.expat</code></a>: the Expat parser binding</li> </ul> <section id="xml-vulnerabilities"> <span id="id1"></span><h2>XML vulnerabilities</h2> <p>The XML processing modules are not secure against maliciously constructed data. An attacker can abuse XML features to carry out denial of service attacks, access local files, generate network connections to other machines, or circumvent firewalls.</p> <p>The following table gives an overview of the known attacks and whether the various modules are vulnerable to them.</p> <table class="docutils align-default"> <thead> <tr> +<th class="head"><p>kind</p></th> <th class="head"><p>sax</p></th> <th class="head"><p>etree</p></th> <th class="head"><p>minidom</p></th> <th class="head"><p>pulldom</p></th> <th class="head"><p>xmlrpc</p></th> </tr> </thead> <tr> +<td><p>billion laughs</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> </tr> <tr> +<td><p>quadratic blowup</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> <td><p><strong>Vulnerable</strong> (1)</p></td> </tr> <tr> +<td><p>external entity expansion</p></td> <td><p>Safe (5)</p></td> <td><p>Safe (2)</p></td> <td><p>Safe (3)</p></td> <td><p>Safe (5)</p></td> <td><p>Safe (4)</p></td> </tr> <tr> +<td><p><a class="reference external" href="https://en.wikipedia.org/wiki/Document_type_definition">DTD</a> retrieval</p></td> <td><p>Safe (5)</p></td> <td><p>Safe</p></td> <td><p>Safe</p></td> <td><p>Safe (5)</p></td> <td><p>Safe</p></td> </tr> <tr> +<td><p>decompression bomb</p></td> <td><p>Safe</p></td> <td><p>Safe</p></td> <td><p>Safe</p></td> <td><p>Safe</p></td> <td><p><strong>Vulnerable</strong></p></td> </tr> </table> <ol class="arabic simple"> <li>Expat 2.4.1 and newer is not vulnerable to the “billion laughs” and “quadratic blowup” vulnerabilities. Items still listed as vulnerable due to potential reliance on system-provided libraries. Check <code>pyexpat.EXPAT_VERSION</code>.</li> <li> +<a class="reference internal" href="xml.etree.elementtree#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code>xml.etree.ElementTree</code></a> doesn’t expand external entities and raises a <a class="reference internal" href="xml.etree.elementtree#xml.etree.ElementTree.ParseError" title="xml.etree.ElementTree.ParseError"><code>ParseError</code></a> when an entity occurs.</li> <li> +<a class="reference internal" href="xml.dom.minidom#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code>xml.dom.minidom</code></a> doesn’t expand external entities and simply returns the unexpanded entity verbatim.</li> <li> +<a class="reference internal" href="xmlrpc.client#module-xmlrpc.client" title="xmlrpc.client: XML-RPC client access."><code>xmlrpc.client</code></a> doesn’t expand external entities and omits them.</li> <li>Since Python 3.7.1, external general entities are no longer processed by default.</li> </ol> <dl class="simple"> <dt>billion laughs / exponential entity expansion</dt> +<dd> +<p>The <a class="reference external" href="https://en.wikipedia.org/wiki/Billion_laughs">Billion Laughs</a> attack – also known as exponential entity expansion – uses multiple levels of nested entities. Each entity refers to another entity several times, and the final entity definition contains a small string. The exponential expansion results in several gigabytes of text and consumes lots of memory and CPU time.</p> </dd> <dt>quadratic blowup entity expansion</dt> +<dd> +<p>A quadratic blowup attack is similar to a <a class="reference external" href="https://en.wikipedia.org/wiki/Billion_laughs">Billion Laughs</a> attack; it abuses entity expansion, too. Instead of nested entities it repeats one large entity with a couple of thousand chars over and over again. The attack isn’t as efficient as the exponential case but it avoids triggering parser countermeasures that forbid deeply nested entities.</p> </dd> <dt>external entity expansion</dt> +<dd> +<p>Entity declarations can contain more than just text for replacement. They can also point to external resources or local files. The XML parser accesses the resource and embeds the content into the XML document.</p> </dd> <dt> +<a class="reference external" href="https://en.wikipedia.org/wiki/Document_type_definition">DTD</a> retrieval</dt> +<dd> +<p>Some XML libraries like Python’s <a class="reference internal" href="xml.dom.pulldom#module-xml.dom.pulldom" title="xml.dom.pulldom: Support for building partial DOM trees from SAX events."><code>xml.dom.pulldom</code></a> retrieve document type definitions from remote or local locations. The feature has similar implications as the external entity expansion issue.</p> </dd> <dt>decompression bomb</dt> +<dd> +<p>Decompression bombs (aka <a class="reference external" href="https://en.wikipedia.org/wiki/Zip_bomb">ZIP bomb</a>) apply to all XML libraries that can parse compressed XML streams such as gzipped HTTP streams or LZMA-compressed files. For an attacker it can reduce the amount of transmitted data by three magnitudes or more.</p> </dd> </dl> <p>The documentation for <a class="reference external" href="https://pypi.org/project/defusedxml/">defusedxml</a> on PyPI has further information about all known attack vectors with examples and references.</p> </section> <section id="the-defusedxml-package"> <span id="defusedxml-package"></span><h2>The <code>defusedxml</code> Package</h2> <p><a class="reference external" href="https://pypi.org/project/defusedxml/">defusedxml</a> is a pure Python package with modified subclasses of all stdlib XML parsers that prevent any potentially malicious operation. Use of this package is recommended for any server code that parses untrusted XML data. The package also ships with example exploits and extended documentation on more XML exploits such as XPath injection.</p> </section> <div class="_attribution"> + <p class="_attribution-p"> + © 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br> + <a href="https://docs.python.org/3.12/library/xml.html" class="_attribution-link">https://docs.python.org/3.12/library/xml.html</a> + </p> +</div> |
