Skip to content

Commit fa8f464

Browse files
[3.14] gh-139313: Improve docs on XML security (GH-139460) (GH-141065)
Clarify that: - it takes parsing for an attack - that some doors are closed by default - only Expat version 2.7.2 has all the fixes - use of the bundle depends on configuration (cherry picked from commit baa9f33) Co-authored-by: Sebastian Pipping <[email protected]>
1 parent 19ba593 commit fa8f464

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

Doc/library/pyexpat.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,15 @@ otherwise stated.
558558

559559
.. method:: xmlparser.ExternalEntityRefHandler(context, base, systemId, publicId)
560560

561+
.. warning::
562+
563+
Implementing a handler that accesses local files and/or the network
564+
may create a vulnerability to
565+
`external entity attacks <https://en.wikipedia.org/wiki/XML_external_entity_attack>`_
566+
if :class:`xmlparser` is used with user-provided XML content.
567+
Please reflect on your `threat model <https://en.wikipedia.org/wiki/Threat_model>`_
568+
before implementing this handler.
569+
561570
Called for references to external entities. *base* is the current base, as set
562571
by a previous call to :meth:`SetBase`. The public and system identifiers,
563572
*systemId* and *publicId*, are strings if given; if the public identifier is not

Doc/library/xml.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,22 @@ XML security
5353

5454
An attacker can abuse XML features to carry out denial of service attacks,
5555
access local files, generate network connections to other machines, or
56-
circumvent firewalls.
57-
58-
Expat versions lower than 2.6.0 may be vulnerable to "billion laughs",
59-
"quadratic blowup" and "large tokens". Python may be vulnerable if it uses such
60-
older versions of Expat as a system-provided library.
56+
circumvent firewalls when attacker-controlled XML is being parsed,
57+
in Python or elsewhere.
58+
59+
The built-in XML parsers of Python rely on the library `libexpat`_, commonly
60+
called Expat, for parsing XML.
61+
62+
By default, Expat itself does not access local files or create network
63+
connections.
64+
65+
Expat versions lower than 2.7.2 may be vulnerable to the "billion laughs",
66+
"quadratic blowup" and "large tokens" vulnerabilities, or to disproportional
67+
use of dynamic memory.
68+
Python bundles a copy of Expat, and whether Python uses the bundled or a
69+
system-wide Expat, depends on how the Python interpreter
70+
:option:`has been configured <--with-system-expat>` in your environment.
71+
Python may be vulnerable if it uses such older versions of Expat.
6172
Check :const:`!pyexpat.EXPAT_VERSION`.
6273

6374
:mod:`xmlrpc` is **vulnerable** to the "decompression bomb" attack.
@@ -90,5 +101,6 @@ large tokens
90101
be used to cause denial of service in the application parsing XML.
91102
The issue is known as :cve:`2023-52425`.
92103

104+
.. _libexpat: https://github.com/libexpat/libexpat
93105
.. _Billion Laughs: https://en.wikipedia.org/wiki/Billion_laughs
94106
.. _ZIP bomb: https://en.wikipedia.org/wiki/Zip_bomb

0 commit comments

Comments
 (0)