GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-90949: add Expat API to prevent XML deadly allocations by picnixz · Pull Request #139234 · python/cpython

Conversation

@picnixz

@picnixz picnixz commented Sep 22, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@hartwork I observed that the maximum allocation factor is only checked if we exceed the activation threshold. The online docs for Expat didn't explicitly mention it so I mentioned it in our docs.

I eventually decided to redo the float-check in case of an error so that we can give a better message to the user (as it relates to security practices, I think it's good to explain why the API call failed as much as we can).

  • Issue: Expose Expat XML attack protection APIs #90949

📚 Documentation preview 📚: https://cpython-previews--139234.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hartwork reacted with heart emoji
All reactions
  • ❤️ 1 reaction
picnixz added 4 commits September 22, 2025 14:51
@picnixz
Expose XML Expat 2.7.2 mitigation APIs
c1c23fb
@picnixz
add tests
12bef9c
@picnixz
docs
1d7e599
@picnixz
NEWS
3dcd9bd
@picnixz
picnixz requested a review from AA-Turner as a code owner September 22, 2025 12:53
@picnixz picnixz added the topic-XML label Sep 22, 2025
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 22, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Sep 22, 2025
Expose Expat XML attack protection APIs #90949
Closed
picnixz added 4 commits September 22, 2025 17:04
@picnixz
Merge branch 'main' into feat/xml/mitigation-api-90949
192fe08
@picnixz
fix docs
0ecbd55
@picnixz
fix tests
07445ad
@picnixz
regen SBOM
9c7371f
@picnixz
picnixz force-pushed the feat/xml/mitigation-api-90949 branch from 3fa5b10 to 9c7371f Compare September 22, 2025 15:23
@picnixz
picnixz requested a review from sethmlarson as a code owner September 22, 2025 15:23
@picnixz

picnixz commented Sep 22, 2025

Copy link
Copy Markdown
Member Author

I plan to also expose the billion laugh mitigation API, but in a separate PR.

hartwork reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz added 3 commits September 22, 2025 18:43
@picnixz
remove unused include
1085584
@picnixz
fix possible error handling
c10fe91
@picnixz
undef macro after usage
18d175f
picnixz
picnixz commented Sep 22, 2025
View reviewed changes
Comment thread Lib/test/test_pyexpat.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
Update Lib/test/test_pyexpat.py
911b2b7
@hartwork

hartwork commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

@picnixz thanks for taking on this project — very much appreciated! 🙏

@hartwork I observed that the maximum allocation factor is only checked if we exceed the activation threshold. The online docs for Expat didn't explicitly mention it so I mentioned it in our docs.

@picnixz there is mention of the activation threshold in the final note of https://libexpat.github.io/doc/api/latest/#XML_SetAllocTrackerMaximumAmplification but I'm happy if the topic gets more attention in CPython docs.

I already started review and spotted a few things. I will likely submit a first round of review some time later today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Sep 22, 2025

Copy link
Copy Markdown
Member Author

there is mention of the activation threshold in the final note of

I assume you are actually talking about this:

So if you do reduce the maximum allowed amplification, please make sure that the activation threshold is still big enough to not end up with undesired false positives (i.e. benign files being rejected).

I actually understood it only as "if you use a smaller factor then in practice, you might want to change the activation threshold" but I didn't understand it as "the amplification factor is only used if we exceed the threshold in the first place". I assumed from the note on XML_SetAllocTrackerActivationThreshold that the two values were totally independent and could have two different protections:

Note: For types of allocations that intentionally bypass tracking and limiting, please see XML_SetAllocTrackerMaximumAmplification above.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Sep 22, 2025

Copy link
Copy Markdown
Member Author

I already started review and spotted a few things. I will likely submit a first round of review some time later today.

Thank you! I'll hold the work on the billion laugh API as it'll be easier to add the API once this one is merged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz
update comments
d636685
@picnixz
picnixz force-pushed the feat/xml/mitigation-api-90949 branch from 4ba478d to d636685 Compare September 22, 2025 17:12
hartwork
hartwork reviewed Sep 22, 2025
View reviewed changes

@hartwork hartwork left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz here's everything I found so far. Happy to learn what I missed in these findings 🍻

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/pyexpat.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pyexpat.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pyexpat.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_pyexpat.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_pyexpat.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/pyexpat.c
}
#endif

#if XML_COMBINED_VERSION >= 20702

@hartwork hartwork Sep 22, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that Expat >=2.7.2 is needed to offer this functionality, but maybe the the Python API should be available in any case and raise exceptions that the compile time Expat was not recent enough to support this feature. Is that what's happening? I remember we had this very question when introducing SetReparseDeferralEnabled.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Sep 22, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument Clinic will handle this automatically by "not" having the function (an AttributeError will be raised). For SetReparseDeferralEnabled, it appears that the API call will be a no-op otherwise.

Maybe it's better to raise NotImplementedError instead of the default AttributeError, as we usually do in ssl when the libssl backend is not the latest.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hartwork hartwork Sep 22, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz I'd like to vote for NotImplementedError or no-op rather than AttributeError for now. I'll need to sleep over this and potentially dig up past communication on the reparse deferall thing. There was past rationale on this somewhere.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Sep 22, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a NotImplementedError over a no-op, as otherwise people might assume that they are protected against some attacks while they are not.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hartwork hartwork Sep 22, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz I should note that protection is active by default (or it would not have fixed the vulnerability). So a no-op in the tuning function would leave them protected under default settings, not unprotected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Sep 23, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the #error approach. It simplifies the checks. I think I'll do a separate PR for that one.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hartwork hartwork Sep 23, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz please feel free to CC me for review there 👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Sep 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if I include expat_config.h before, those symbols will anyway be defined (unless someone changes expat_config.h). But I don't think I need to assume that expat_config.h should be changed. Until now, it was not even used... (it wasn't included). I prefer not to overcomplicate the file (but at least now I know that it should be fine)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@hartwork hartwork Sep 23, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@picnixz file expat_config.h is auto-generated by the Expat build system (if systemwide Expat is used) and hardcoded by CPython when the bundle is used. So in the former case, XML_DTD and XML_GE could be defined or not: it's under the sysadmin's control.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@picnixz picnixz Sep 24, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks for the explanation. I thought it was a python-only file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hartwork reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Modules/pyexpat.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_pyexpat.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_pyexpat.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/pyexpat.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@hartwork

hartwork commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

I assume you are actually talking about this:

So if you do reduce the maximum allowed amplification, please make sure that the activation threshold is still big enough to not end up with undesired false positives (i.e. benign files being rejected).

@picnixz I confirm, yes, exactly 👍

I actually understood it only as "if you use a smaller factor then in practice, you might want to change the activation threshold" but I didn't understand it as "the amplification factor is only used if we exceed the threshold in the first place". I assumed from the note on XML_SetAllocTrackerActivationThreshold that the two values were totally independent and could have two different protections:

I see. I think that means that upstream docs should be adjusted some way to make it easier to read that (or them) as interconnected. How about I try a related pull request upstream and you take the review seat there?

I'll hold the work on the billion laugh API as it'll be easier to add the API once this one is merged.

Understood, good plan 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hartwork hartwork mentioned this pull request Sep 22, 2025
xmlwf: Resolve use of functions XML_GetErrorLineNumber and XML_GetErrorColumnNumber libexpat/libexpat#1053
Merged
picnixz added 2 commits September 22, 2025 20:37
@picnixz
use better test names
b951065
@picnixz
simplify roles usage
e11bf14
picnixz added a commit to picnixz/cpython that referenced this pull request Sep 28, 2025
@picnixz
pythongh-90949: amend pythonGH-139234 in prevision of future mitigati…
b52fc88
…on API (python#139366)

Fix some typos left in f04bea4,
and simplify some internal functions to ease maintenance of future
mitigation APIs.
@hartwork

hartwork commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

@picnixz I went to past related pull requests…

  • gh-115398: Expose Expat >=2.6.0 reparse deferral API (CVE-2023-52425) #115623

  • gh-115398: Suggest use of hasattr with checking for 3.13 Expat API availability #116278

  • gh-115399: Document CVE-2023-52425 under "XML vulnerabilities" #115400

…to look for open questions or things that may be missing still here. (That exposed the missing version checks in the new tests as already commented above.) And it gave me these three open questions:

  • Do the sax and etree parsers using Expat need new knobs for this and if so, does it need to be in here? The related classes are:

    • xml.etree.ElementTree.XMLParser
    • xml.etree.ElementTree.XMLPullParser
    • xml.sax.expatreader.ExpatParser
  • Is extending the docs for CVE-2025-59375 needed and if so, does it have to be in here?

    • Should the docs suggest getattr hasattr for the new method added and should it be done in here?

What do you think?

@picnixz any ideas about what to do about xml.sax and xml.etree?

Regarding hasattr, I can look into a pull request like #116278 if you want (or be in the review seat)?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Sep 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

any ideas about what to do about xml.sax and xml.etree?

I think we could just add a method for tuning the protections? maybe a single method for all protections? or a configuration object for that? I don't really know which one would be the best here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Sep 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Note: I think having the user calling parser.<method-with-a-really-long-name> wouldn't really be "pretty". I'm sad that we can't have some parameter called tune_lolz_protection() (the most pythonic I can think of is set_thresholds(expansion=..., memory=...) so that users don't need to remember very long method names.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hartwork hartwork mentioned this pull request Sep 28, 2025
[3.14] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234) #139359
Merged
@hartwork

hartwork commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

@picnixz it's a pity that etree and sax are not reusing pyexpat internally (as can be seen in Modules/_elementtree.c). Or else we could just ask for the underlying parser, give the user access, and we'd already be done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Sep 28, 2025

Copy link
Copy Markdown
Member Author

it's a pity that etree and sax are not reusing pyexpat internally

But they do I think? at least there is some ExpatReader in the sax module and I think there is some import pyexpat in etree. Or did I misunderstand?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hartwork

hartwork commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

@picnixz maybe we need to look at sax and etree separately. Other than sax, etree has a C and a pure-Python version of the same module that — I think — need to satisfy the same interface. The C version of etree does not seem to use xmlparseobject of pyexpat internally (despite the #include "pyexpat.h"). I'm only vaguely familiar with this territory. Past related pull request #115623 showcases addition of the same feature to both the C and the pure-Python version.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Sep 28, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Indeed, for etree, we have a pure Python implementation and a C implementation. The C implementation directly uses pyexpat, but the pure Python one doesn't. Implementing the logic for the pure Python interface seems an overkill. It would essentially ask to mimic the allocation limitations and we would then need to compute ourselves the size of objects being allocated, which is not realistic for the pure Python implementation.

I would instead suggest that we don't do anything for this one, and that by default, it's left untouched (namely make those methods a no-op). For the C implementation, we would add new methods at the level of _elementree.XMLParser. Note that we use libexpat by using the C API that is exposed by the pyexpat (C) module.

For SAX, it's also a pure Python implementation (no C), so I suggest leaving the API empty as well. The pure Python implementation however seems to only use pyexpat (see https://github.com/python/cpython/blob/main/Lib/xml/sax/expatreader.py#L284-L295) so we could directly use the underlying C API as well (I don't think it was needed to re-implement the logic in pure Python since, AFAICT, the parser was always C-based for SAX).

I think checking for the existence of the underlying C API through hasattr would be the best.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hartwork pushed a commit to hartwork/cpython that referenced this pull request Oct 2, 2025
@picnixz @hartwork
[3.12] pythongh-90949: add Expat API to prevent XML deadly allocations (
aeefb63
CVE-2025-59375) (pythonGH-139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.
(cherry picked from commit f04bea4)

Co-authored-by: Bénédikt Tran <[email protected]>
hartwork pushed a commit to hartwork/cpython that referenced this pull request Oct 2, 2025
@picnixz @hartwork
pythongh-90949: amend pythonGH-139234 in prevision of future mitigati…
a5d026a
…on API (python#139366)

Fix some typos left in f04bea4,
and simplify some internal functions to ease maintenance of future
mitigation APIs.

(cherry picked from commit 68a1778)
@bedevere-app

bedevere-app Bot commented Oct 2, 2025

Copy link
Copy Markdown

GH-139527 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Oct 2, 2025
hartwork pushed a commit to hartwork/cpython that referenced this pull request Oct 2, 2025
@picnixz @hartwork
pythongh-90949: add Expat API to prevent XML deadly allocations (CVE-…
a295473
…2025-59375) (python#139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.

(cherry picked from commit f04bea4)
hartwork pushed a commit to hartwork/cpython that referenced this pull request Oct 2, 2025
@picnixz @hartwork
pythongh-90949: amend pythonGH-139234 in prevision of future mitigati…
5680561
…on API (python#139366)

Fix some typos left in f04bea4,
and simplify some internal functions to ease maintenance of future
mitigation APIs.

(cherry picked from commit 68a1778)
@bedevere-app

bedevere-app Bot commented Oct 2, 2025

Copy link
Copy Markdown

GH-139529 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Oct 2, 2025
hartwork pushed a commit to hartwork/cpython that referenced this pull request Oct 3, 2025
@picnixz @hartwork
pythongh-90949: add Expat API to prevent XML deadly allocations (CVE-…
de690f1
…2025-59375) (python#139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.

(cherry picked from commit f04bea4)
hartwork pushed a commit to hartwork/cpython that referenced this pull request Oct 3, 2025
@picnixz @hartwork
pythongh-90949: amend pythonGH-139234 in prevision of future mitigati…
6ae7665
…on API (python#139366)

Fix some typos left in f04bea4,
and simplify some internal functions to ease maintenance of future
mitigation APIs.

(cherry picked from commit 68a1778)
@bedevere-app

bedevere-app Bot commented Oct 3, 2025

Copy link
Copy Markdown

GH-139532 is a backport of this pull request to the 3.10 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.10 label Oct 3, 2025
picnixz pushed a commit that referenced this pull request Oct 4, 2025
@hartwork
gh-90949: Fix an "unused function" compiler warning introduced in GH-…
fc48a3c
…139234 (#139558)

Fix a compiler warning `-Wunused-function` after f04bea4.

The `set_invalid_arg` function in `Modules/pyexpat.c` may be unused if the underlying Expat
version is less than 2.4.0.
danigm pushed a commit to openSUSE-Python/cpython that referenced this pull request Oct 7, 2025
@hartwork @danigm
pythongh-90949: Fix an "unused function" compiler warning introduced in
1aead6b
pythonGH-139234 (python#139558)

Fix a compiler warning `-Wunused-function` after f04bea4.

The `set_invalid_arg` function in `Modules/pyexpat.c` may be unused if the underlying Expat
version is less than 2.4.0.
@hartwork hartwork mentioned this pull request Oct 9, 2025
gh-90949: Recommend hasattr with Expat security methods #139800
Merged
picnixz added a commit that referenced this pull request Nov 2, 2025
@picnixz
[3.14] gh-90949: add Expat API to prevent XML deadly allocations (CVE…
bf2865f
…-2025-59375) (GH-139234) (#139359)

* [3.14] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.

(cherry picked from commit f04bea4)
(cherry picked from commit 68a1778)
picnixz pushed a commit that referenced this pull request Nov 2, 2025
@hartwork
[3.13] gh-90949: add Expat API to prevent XML deadly allocations (CVE…
bc36bd1
…-2025-59375) (GH-139234) (#139367)

* gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (#139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.

(cherry picked from commit f04bea4)
(cherry picked from commit 68a1778)
pablogsal pushed a commit that referenced this pull request Nov 25, 2025
@hartwork @picnixz
[3.10] gh-90949: add Expat API to prevent XML deadly allocations (CVE…
1173f80
…-2025-59375) (GH-139234) (#139532)

Co-authored-by: Bénédikt Tran <[email protected]>
pablogsal pushed a commit that referenced this pull request Nov 25, 2025
@hartwork @picnixz
[3.11] gh-90949: add Expat API to prevent XML deadly allocations (CVE…
9bbb68a
…-2025-59375) (GH-139234) (#139529)

Co-authored-by: Bénédikt Tran <[email protected]>
@dg-pb dg-pb mentioned this pull request Nov 27, 2025
Add c-analyzer fails for pyexpat.c #142025
Closed
Yhg1s pushed a commit that referenced this pull request Dec 17, 2025
@hartwork @picnixz
[3.12] gh-90949: add Expat API to prevent XML deadly allocations (CVE…
0e4cd89
…-2025-59375) (GH-139234) (#139527)

* [3.12] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234)

Expose the XML Expat 2.7.2 mitigation APIs to disallow use of
disproportional amounts of dynamic memory from within an Expat
parser (see CVE-2025-59375 for instance).

The exposed APIs are available on Expat parsers, that is,
parsers created by `xml.parsers.expat.ParserCreate()`, as:

- `parser.SetAllocTrackerActivationThreshold(threshold)`, and
- `parser.SetAllocTrackerMaximumAmplification(max_factor)`.

(cherry picked from commit f04bea4)
(cherry picked from commit 68a1778)
Co-authored-by: Bénédikt Tran <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AA-Turner AA-Turner AA-Turner left review comments
+1 more reviewer
@hartwork hartwork hartwork approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@picnixz picnixz

Labels

topic-XML

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@picnixz @hartwork @AA-Turner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.