FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-90949: expose Expat API to tune exponential expansion protections by picnixz · Pull Request #139368 · python/cpython · GitHub

/ cpython Public

gh-90949: expose Expat API to tune exponential expansion protections - #139368

Merged
picnixz merged 7 commits into
python:mainfrom
picnixz:feat/xml/1e9-lolz-api-90949
Sep 28, 2025
Merged

gh-90949: expose Expat API to tune exponential expansion protections#139368
picnixz merged 7 commits into
python:mainfrom
picnixz:feat/xml/1e9-lolz-api-90949

Conversation

picnixz commented Sep 26, 2025
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

hartwork left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@picnixz already in pretty good shape 👍

picnixz left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've updated the PR from the web UI but I'll do the rest tomorrow.

Comment thread Doc/library/pyexpat.rst
Comment thread Doc/library/pyexpat.rst Outdated
Comment thread Doc/library/pyexpat.rst Outdated
picnixz requested review from gpshead and hartwork September 27, 2025 08:19
picnixz changed the title gh-90949: expose Expat mitigation API to prevent exponential expansions gh-90949: expose Expat API to prevent exponential expansions Sep 27, 2025

hartwork left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@picnixz I like this new version! 👍

One question: There were changes in here to the previous related news file. This is what it reads on main today:

# cat Misc/NEWS.d/next/Library/2025-09-22-14-40-11.gh-issue-90949.UM35nb.rst
Add :meth:`~xml.parsers.expat.xmlparser.SetAllocTrackerActivationThreshold`
and :meth:`~xml.parsers.expat.xmlparser.SetAllocTrackerMaximumAmplification`
to :ref:`xmlparser <xmlparser-objects>` objects to prevent use of
disproportional amounts of dynamic memory from within an Expat parser.
Patch by Bénédikt Tran.

From what we discussed here, this should probably says things about tuning also?
Should you or me create a follow-up pull request to adjust that after this?

picnixz commented Sep 27, 2025

Copy link
Copy Markdown
Member Author

I'll amend the NEWS as part of this PR.

picnixz enabled auto-merge (squash) September 28, 2025 07:58
picnixz changed the title gh-90949: expose Expat API to prevent exponential expansions gh-90949: expose Expat API to tune exponential expansion protections Sep 28, 2025
picnixz merged commit 6661123 into python:main Sep 28, 2025
45 checks passed
picnixz deleted the feat/xml/1e9-lolz-api-90949 branch September 28, 2025 08:37

picnixz commented Sep 28, 2025

Copy link
Copy Markdown
Member Author

Since this is built on top of many other PRs, I'll just wait for the others to be backported first.

StanFromIreland added the needs backport to 3.14 bugs and security fixes label May 24, 2026

Copy link
Copy Markdown

Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

Copy link
Copy Markdown

Sorry, @picnixz, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 666112376d574c7802646ee1df6244062671cd61 3.10

Copy link
Copy Markdown

Sorry, @picnixz, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 666112376d574c7802646ee1df6244062671cd61 3.11

Copy link
Copy Markdown

Sorry, @picnixz, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 666112376d574c7802646ee1df6244062671cd61 3.12

Copy link
Copy Markdown

Sorry, @picnixz, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 666112376d574c7802646ee1df6244062671cd61 3.13

Copy link
Copy Markdown

Sorry, @picnixz, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 666112376d574c7802646ee1df6244062671cd61 3.14

picnixz commented May 24, 2026

Copy link
Copy Markdown
Member Author

@StanFromIreland I see that the backports here totally failed and then it passed under my radar. Could you backport this PR (and any other PRs that need to be backported with it, including docs changes) to 3.14 so that you're no more blocked? I'm sorry to dump my work on you but I won't be available otherwise for that today :(

Copy link
Copy Markdown
Member

It's fine, I've put it on my list, I'll get to it soon-ish.

Comment thread Doc/whatsnew/3.15.rst
disproportional amounts of dynamic memory usage from within an Expat parser.
(Contributed by Bénédikt Tran in :gh:`90949`.)

* Add :meth:`~xml.parsers.expat.xmlparser.SetBillionLaughsAttackProtectionActivationThreshold`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not quite sure how to go about backporting this, I think we'll need to remove it from here?

picnixz May 25, 2026
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yeah, you can drop this part in older branches but we still want the versionadded:: next in the docs directly. What's New can be omitted. You can add the explicit Python version when it was added though (3.14.x) and not just 3.14 (don't know if :: next handles it...)

StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request May 26, 2026
… protections (pythonGH-139368)

Expose the XML Expat 2.7.2 APIs to tune protections against
"billion laughs" [1] attacks.

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

- `parser.SetBillionLaughsAttackProtectionActivationThreshold(threshold)`, and
- `parser.SetBillionLaughsAttackProtectionMaximumAmplification(max_factor)`.

This completes the work in f04bea4,
and improves the existing related documentation.

[1]: https://en.wikipedia.org/wiki/Billion_laughs_attack
(cherry picked from commit 6661123)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

bedevere-app Bot commented May 26, 2026

Copy link
Copy Markdown

GH-150496 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 26, 2026
StanFromIreland added a commit that referenced this pull request Jun 9, 2026
…ctions (GH-139368) (#150496)

Expose the XML Expat 2.7.2 APIs to tune protections against
"billion laughs" [1] attacks.

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

- `parser.SetBillionLaughsAttackProtectionActivationThreshold(threshold)`, and
- `parser.SetBillionLaughsAttackProtectionMaximumAmplification(max_factor)`.

This completes the work in f04bea4,
and improves the existing related documentation.

[1]: https://en.wikipedia.org/wiki/Billion_laughs_attack
(cherry picked from commit 6661123)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
StanFromIreland removed the needs backport to 3.13 bugs and security fixes label Jun 9, 2026

bedevere-app Bot commented Jun 9, 2026

Copy link
Copy Markdown

GH-151151 is a backport of this pull request to the 3.13 branch.

StanFromIreland added a commit that referenced this pull request Jun 9, 2026
…ctions (GH-139368)

Expose the XML Expat 2.7.2 APIs to tune protections against
"billion laughs" [1] attacks.

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

- `parser.SetBillionLaughsAttackProtectionActivationThreshold(threshold)`, and
- `parser.SetBillionLaughsAttackProtectionMaximumAmplification(max_factor)`.

This completes the work in f04bea4,
and improves the existing related documentation.

[1]: https://en.wikipedia.org/wiki/Billion_laughs_attack
(cherry picked from commit 6661123)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

bedevere-app Bot commented Jun 12, 2026

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.12 only security fixes label Jun 12, 2026
Yhg1s pushed a commit that referenced this pull request Aug 4, 2026
…ctions (GH-139368) (#151401)

Expose the XML Expat 2.7.2 APIs to tune protections against
"billion laughs" [1] attacks.

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

- `parser.SetBillionLaughsAttackProtectionActivationThreshold(threshold)`, and
- `parser.SetBillionLaughsAttackProtectionMaximumAmplification(max_factor)`.

This completes the work in f04bea4,
and improves the existing related documentation.

[1]: https://en.wikipedia.org/wiki/Billion_laughs_attack
(cherry picked from commit 6661123)
(cherry picked from commit 19bc391)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
StanFromIreland removed needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Aug 9, 2026
pablogsal pushed a commit that referenced this pull request Aug 9, 2026
…ctions (GH-139368) (GH-151401) (#155346)

* [3.11] gh-90949: expose Expat API to tune exponential expansion protections (GH-139368) (GH-151401)

Expose the XML Expat 2.7.2 APIs to tune protections against
"billion laughs" [1] attacks.

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

- `parser.SetBillionLaughsAttackProtectionActivationThreshold(threshold)`, and
- `parser.SetBillionLaughsAttackProtectionMaximumAmplification(max_factor)`.

This completes the work in f04bea4,
and improves the existing related documentation.

[1]: https://en.wikipedia.org/wiki/Billion_laughs_attack
(cherry picked from commit 6661123)
(cherry picked from commit 19bc391)
(cherry picked from commit db195e3)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix capi member access

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
pablogsal pushed a commit that referenced this pull request Aug 10, 2026
…ctions (GH-139368) (#151401) (#155414)

Expose the XML Expat 2.7.2 APIs to tune protections against
"billion laughs" [1] attacks.

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

- `parser.SetBillionLaughsAttackProtectionActivationThreshold(threshold)`, and
- `parser.SetBillionLaughsAttackProtectionMaximumAmplification(max_factor)`.

This completes the work in f04bea4,
and improves the existing related documentation.

[1]: https://en.wikipedia.org/wiki/Billion_laughs_attack
(cherry picked from commit 6661123)
(cherry picked from commit 19bc391)


(cherry picked from commit db195e3)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL