Skip to content

python: fix unbounded recursion DoS in FieldMask path handling#26509

Closed
CHIRANJEET1729DAS wants to merge 1 commit intoprotocolbuffers:mainfrom
CHIRANJEET1729DAS:fix/field-mask-unbounded-recursion-dos
Closed

python: fix unbounded recursion DoS in FieldMask path handling#26509
CHIRANJEET1729DAS wants to merge 1 commit intoprotocolbuffers:mainfrom
CHIRANJEET1729DAS:fix/field-mask-unbounded-recursion-dos

Conversation

@CHIRANJEET1729DAS
Copy link
Copy Markdown

A FieldMask path string with thousands of dot-separated segments bypasses wire-level parser depth limits (they treat it as a flat string) and causes unbounded Python call-stack recursion in _FieldMaskTree, crashing the process with RecursionError.

Two complementary defences:

  1. AddPath() now rejects paths exceeding _MAX_FIELD_MASK_DEPTH (64) segments with a ValueError before they enter the tree.

  2. _AddFieldPaths(), AddLeafNodes(), and _MergeMessage() are rewritten iteratively using explicit stacks, eliminating all unbounded Python call-stack growth as defence-in-depth.

Security impact: any server using Union(), Intersect(), or CanonicalFormFromMask() on attacker-controlled FieldMask input was vulnerable to remote DoS via a ~2KB payload.

Fixes: #26489

A FieldMask path string with thousands of dot-separated segments
bypasses wire-level parser depth limits (they treat it as a flat string)
and causes unbounded Python call-stack recursion in _FieldMaskTree,
crashing the process with RecursionError.

Two complementary defences:

1. AddPath() now rejects paths exceeding _MAX_FIELD_MASK_DEPTH (64)
   segments with a ValueError before they enter the tree.

2. _AddFieldPaths(), AddLeafNodes(), and _MergeMessage() are rewritten
   iteratively using explicit stacks, eliminating all unbounded Python
   call-stack growth as defence-in-depth.

Security impact: any server using Union(), Intersect(), or
CanonicalFormFromMask() on attacker-controlled FieldMask input was
vulnerable to remote DoS via a ~2KB payload.

Fixes: https://github.com/protocolbuffers/protobuf/issues/<ISSUE_NUMBER>
@CHIRANJEET1729DAS CHIRANJEET1729DAS requested a review from a team as a code owner March 22, 2026 02:50
@CHIRANJEET1729DAS CHIRANJEET1729DAS requested review from haberman and removed request for a team March 22, 2026 02:50
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@esrauchg
Copy link
Copy Markdown
Contributor

I replied on #26489 for the shape of fix that I think we could accept, but we can't take a look at your PR without the CLA first.

Thanks!

@esrauchg esrauchg self-requested a review March 23, 2026 18:24
@esrauchg
Copy link
Copy Markdown
Contributor

Thank you for raising this issue; resolved in 7adc4b6 so closing this PR

Thanks!

@esrauchg esrauchg closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants