Skip to content

Commit 0c17473

Browse files
authored
gh-90949: Recommend hasattr with Expat security methods (#139800)
1 parent 13e9c2d commit 0c17473

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

Doc/library/pyexpat.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ XMLParser Objects
223223
Calling ``SetReparseDeferralEnabled(True)`` allows re-enabling reparse
224224
deferral.
225225

226-
Note that :meth:`SetReparseDeferralEnabled` has been backported to some
227-
prior releases of CPython as a security fix. Check for availability of
228-
:meth:`SetReparseDeferralEnabled` using :func:`hasattr` if used in code
229-
running across a variety of Python versions.
226+
:meth:`!SetReparseDeferralEnabled`
227+
has been backported to some prior releases of CPython as a security fix.
228+
Check for availability using :func:`hasattr` if used in code running
229+
across a variety of Python versions.
230230

231231
.. versionadded:: 3.13
232232

@@ -257,6 +257,11 @@ against some common XML vulnerabilities.
257257
The corresponding :attr:`~ExpatError.lineno` and :attr:`~ExpatError.offset`
258258
should not be used as they may have no special meaning.
259259

260+
:meth:`!SetBillionLaughsAttackProtectionActivationThreshold`
261+
has been backported to some prior releases of CPython as a security fix.
262+
Check for availability using :func:`hasattr` if used in code running
263+
across a variety of Python versions.
264+
260265
.. note::
261266

262267
Activation thresholds below 4 MiB are known to break support for DITA 1.3
@@ -288,6 +293,11 @@ against some common XML vulnerabilities.
288293
The corresponding :attr:`~ExpatError.lineno` and :attr:`~ExpatError.offset`
289294
should not be used as they may have no special meaning.
290295

296+
:meth:`!SetBillionLaughsAttackProtectionMaximumAmplification`
297+
has been backported to some prior releases of CPython as a security fix.
298+
Check for availability using :func:`hasattr` if used in code running
299+
across a variety of Python versions.
300+
291301
.. note::
292302

293303
The maximum amplification factor is only considered if the threshold
@@ -309,6 +319,11 @@ against some common XML vulnerabilities.
309319
The corresponding :attr:`~ExpatError.lineno` and :attr:`~ExpatError.offset`
310320
should not be used as they may have no special meaning.
311321

322+
:meth:`!SetAllocTrackerActivationThreshold`
323+
has been backported to some prior releases of CPython as a security fix.
324+
Check for availability using :func:`hasattr` if used in code running
325+
across a variety of Python versions.
326+
312327
.. versionadded:: next
313328

314329
.. method:: xmlparser.SetAllocTrackerMaximumAmplification(max_factor, /)
@@ -334,6 +349,11 @@ against some common XML vulnerabilities.
334349
The corresponding :attr:`~ExpatError.lineno` and :attr:`~ExpatError.offset`
335350
should not be used as they may have no special meaning.
336351

352+
:meth:`!SetAllocTrackerMaximumAmplification`
353+
has been backported to some prior releases of CPython as a security fix.
354+
Check for availability using :func:`hasattr` if used in code running
355+
across a variety of Python versions.
356+
337357
.. note::
338358

339359
The maximum amplification factor is only considered if the threshold

Doc/library/xml.etree.elementtree.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,10 +1398,10 @@ XMLParser Objects
13981398
Disabling reparse deferral has security consequences; please see
13991399
:meth:`xml.parsers.expat.xmlparser.SetReparseDeferralEnabled` for details.
14001400

1401-
Note that :meth:`flush` has been backported to some prior releases of
1402-
CPython as a security fix. Check for availability of :meth:`flush`
1403-
using :func:`hasattr` if used in code running across a variety of Python
1404-
versions.
1401+
:meth:`!flush`
1402+
has been backported to some prior releases of CPython as a security fix.
1403+
Check for availability using :func:`hasattr` if used in code running
1404+
across a variety of Python versions.
14051405

14061406
.. versionadded:: 3.13
14071407

@@ -1476,10 +1476,10 @@ XMLPullParser Objects
14761476
Disabling reparse deferral has security consequences; please see
14771477
:meth:`xml.parsers.expat.xmlparser.SetReparseDeferralEnabled` for details.
14781478

1479-
Note that :meth:`flush` has been backported to some prior releases of
1480-
CPython as a security fix. Check for availability of :meth:`flush`
1481-
using :func:`hasattr` if used in code running across a variety of Python
1482-
versions.
1479+
:meth:`!flush`
1480+
has been backported to some prior releases of CPython as a security fix.
1481+
Check for availability using :func:`hasattr` if used in code running
1482+
across a variety of Python versions.
14831483

14841484
.. versionadded:: 3.13
14851485

0 commit comments

Comments
 (0)