Skip to content

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

Merged
Yhg1s merged 1 commit into
python:3.12from
StanFromIreland:backport-19bc391-3.12
Aug 4, 2026
Merged

Yhg1s merged 1 commit into
python:3.12from
StanFromIreland:backport-19bc391-3.12

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

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)

… 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)
(cherry picked from commit 19bc391)

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

@picnixz picnixz left a comment

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.

LGTM. But I can't merge it anyway.

@picnixz

picnixz commented Jul 4, 2026

Copy link
Copy Markdown
Member

Why was it a manual backport btw?

@StanFromIreland

Copy link
Copy Markdown
Member Author

I don't remember any more, it has been a while. Possibly the generated clinic or test decorators.

@Yhg1s
Yhg1s merged commit db195e3 into python:3.12 Aug 4, 2026
25 checks passed
@StanFromIreland
StanFromIreland deleted the backport-19bc391-3.12 branch August 7, 2026 14:01
@StanFromIreland StanFromIreland added the needs backport to 3.11 only security fixes label Aug 7, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

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

cherry_picker db195e38a499c837b3ea2cf0aa1c9383e76ddc80 3.11
@bedevere-app

bedevere-app Bot commented Aug 7, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Aug 7, 2026
@bedevere-app

bedevere-app Bot commented Aug 9, 2026

Copy link
Copy Markdown

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants