Skip to content

Fix Any recursion depth bypass in Python json_format.ParseDict#25239

Closed
aviralgarg05 wants to merge 1 commit intoprotocolbuffers:mainfrom
aviralgarg05:fix-any-recursion-depth-bypass
Closed

Fix Any recursion depth bypass in Python json_format.ParseDict#25239
aviralgarg05 wants to merge 1 commit intoprotocolbuffers:mainfrom
aviralgarg05:fix-any-recursion-depth-bypass

Conversation

@aviralgarg05
Copy link
Contributor

This fixes a security vulnerability where nested google.protobuf.Any messages could bypass the max_recursion_depth limit, potentially leading to denial of service via stack overflow.

The root cause was that _ConvertAnyMessage() was calling itself recursively via methodcaller() for nested well-known types, bypassing the recursion depth tracking in ConvertMessage().

The fix routes well-known type parsing through ConvertMessage() to ensure proper recursion depth accounting for all message types including nested Any.

Fixes #25070

@aviralgarg05 aviralgarg05 requested a review from a team as a code owner January 9, 2026 15:34
@aviralgarg05 aviralgarg05 requested review from anandolee and removed request for a team January 9, 2026 15:34
@anandolee anandolee self-assigned this Jan 12, 2026
@anandolee anandolee added python 🅰️ safe for tests Mark a commit as safe to run presubmits over labels Jan 12, 2026
@github-actions github-actions bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Jan 12, 2026
Copy link

@ankitsinha-cmyk ankitsinha-cmyk left a comment

Choose a reason for hiding this comment

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

Consider:

  1. Add a comment clarifying how you count depth and whether max_recursion_depth is inclusive/exclusive.

  2. Adding a test that explicitly asserts that depth==max_recursion_depth-1 succeeds and depth==max_recursion_depth fails, so the boundary behavior is documented.

@benglewis
Copy link

I understand this this is failing CI/CD and all... but we are stuck with our packages failing on vulnerabilities with this fix. What is the ETA for getting this merged?

Copy link

@ankitsinha-cmyk ankitsinha-cmyk left a comment

Choose a reason for hiding this comment

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

@aviralgarg05 thanks for incorporating the changes. Looks fine to me now.

lebaudantoine added a commit to suitenumerique/meet that referenced this pull request Jan 25, 2026
A new vulnerability (CVE-2026-0994) was reported and is not yet fixed. It affects
protobuf libraries used by the livekit-api Python package.

A fix is in progress upstream, but the related PR has not yet been merged or
released. Since a release is required tonight, the Trivy scan step is
temporarily disabled to allow the build to proceed. This should be re-enabled
once a patched version is available.

protocolbuffers/protobuf#25239
lebaudantoine added a commit to suitenumerique/meet that referenced this pull request Jan 25, 2026
A new vulnerability (CVE-2026-0994) was reported and is not yet fixed.
It affects protobuf libraries used by the livekit-api Python package.

A fix is in progress upstream, but the related PR has not yet been merged or
released. Since a release is required tonight, the Trivy scan step is
temporarily disabled to allow the build to proceed. This should be re-enabled
once a patched version is available.

protocolbuffers/protobuf#25239
lebaudantoine added a commit to suitenumerique/meet that referenced this pull request Jan 25, 2026
A new vulnerability (CVE-2026-0994) was reported and is not yet fixed.
It affects protobuf libraries used by the livekit-api Python package.

A fix is in progress upstream, but the related PR has not yet been merged or
released. Since a release is required tonight, the Trivy scan step is
temporarily disabled to allow the build to proceed. This should be re-enabled
once a patched version is available.

protocolbuffers/protobuf#25239
lebaudantoine added a commit to suitenumerique/meet that referenced this pull request Jan 25, 2026
A new vulnerability (CVE-2026-0994) was reported and is not yet fixed.
It affects protobuf libraries used by the livekit-api Python package.

A fix is in progress upstream, but the related PR has not yet been merged or
released. Since a release is required tonight, the Trivy scan step is
temporarily disabled to allow the build to proceed. This should be re-enabled
once a patched version is available.

protocolbuffers/protobuf#25239
aponcedeleonch added a commit to StacklokLabs/mcp-optimizer that referenced this pull request Jan 26, 2026
This will enable running the CI and its checks. There is a fix
upstream waiting to be merged and released: protocolbuffers/protobuf#25239
aponcedeleonch added a commit to StacklokLabs/mcp-optimizer that referenced this pull request Jan 26, 2026
This will enable running the CI and its checks. There is a fix
upstream waiting to be merged and released: protocolbuffers/protobuf#25239
aponcedeleonch added a commit to StacklokLabs/mcp-optimizer that referenced this pull request Jan 26, 2026
This will enable running the CI and its checks. There is a fix
upstream waiting to be merged and released: protocolbuffers/protobuf#25239
copybara-service bot pushed a commit that referenced this pull request Jan 29, 2026
In the case of quotes and backslashes (which are the most common things that need escaping) we can avoid going into Utf8 bytes for most cases this way, while also only doing 1 pass over the string when it doesn't need escaping at all.

COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
FUTURE_COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 862311595
copybara-service bot pushed a commit that referenced this pull request Jan 29, 2026
COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
FUTURE_COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 861246215
@copybara-service copybara-service bot mentioned this pull request Jan 29, 2026
copybara-service bot pushed a commit that referenced this pull request Jan 29, 2026
COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
FUTURE_COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 862635690
@copybara-service copybara-service bot mentioned this pull request Jan 29, 2026
copybara-service bot pushed a commit that referenced this pull request Jan 29, 2026
COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
FUTURE_COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 861910783
@copybara-service copybara-service bot mentioned this pull request Jan 29, 2026
zhangskz pushed a commit that referenced this pull request Jan 29, 2026
This fixes a security vulnerability where nested google.protobuf.Any messages could bypass the max_recursion_depth limit, potentially leading to denial of service via stack overflow.

The root cause was that _ConvertAnyMessage() was calling itself recursively via methodcaller() for nested well-known types, bypassing the recursion depth tracking in ConvertMessage().

The fix routes well-known type parsing through ConvertMessage() to ensure proper recursion depth accounting for all message types including nested Any.

Fixes #25070

Closes #25239

COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 862740421
zhangskz pushed a commit that referenced this pull request Jan 29, 2026
This fixes a security vulnerability where nested google.protobuf.Any messages could bypass the max_recursion_depth limit, potentially leading to denial of service via stack overflow.

The root cause was that _ConvertAnyMessage() was calling itself recursively via methodcaller() for nested well-known types, bypassing the recursion depth tracking in ConvertMessage().

The fix routes well-known type parsing through ConvertMessage() to ensure proper recursion depth accounting for all message types including nested Any.

Fixes #25070

Closes #25239

COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 862740421
zhangskz added a commit that referenced this pull request Jan 29, 2026
… (#25586)

This fixes a security vulnerability where nested google.protobuf.Any messages could bypass the max_recursion_depth limit, potentially leading to denial of service via stack overflow.

The root cause was that _ConvertAnyMessage() was calling itself recursively via methodcaller() for nested well-known types, bypassing the recursion depth tracking in ConvertMessage().

The fix routes well-known type parsing through ConvertMessage() to ensure proper recursion depth accounting for all message types including nested Any.

Fixes #25070

Closes #25239

COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 862740421

Co-authored-by: Aviral Garg <gargaviral99@gmail.com>
zhangskz added a commit that referenced this pull request Jan 29, 2026
… (#25587)

This fixes a security vulnerability where nested google.protobuf.Any messages could bypass the max_recursion_depth limit, potentially leading to denial of service via stack overflow.

The root cause was that _ConvertAnyMessage() was calling itself recursively via methodcaller() for nested well-known types, bypassing the recursion depth tracking in ConvertMessage().

The fix routes well-known type parsing through ConvertMessage() to ensure proper recursion depth accounting for all message types including nested Any.

Fixes #25070

Closes #25239

COPYBARA_INTEGRATE_REVIEW=#25239 from aviralgarg05:fix-any-recursion-depth-bypass 3cbbcbe
PiperOrigin-RevId: 862740421

Co-authored-by: Aviral Garg <gargaviral99@gmail.com>
@crmpicco
Copy link

Thanks @paulhodson , that is a useful tip for future

@obs-gh-nikhildua
Copy link

obs-gh-nikhildua commented Feb 4, 2026

@aviralgarg05 @ankitsinha-cmyk @anandolee Is there any plans to bring this to version 4.25.x? We run a cloud function which depends on this version and updating will cause backwards incompatibility with other library versions as well for our customers. Thanks!

@sfc-gh-ndua
Copy link

@aviralgarg05 @ankitsinha-cmyk @anandolee Is there any plans to bring this to version 4.25.x? We run a cloud function which depends on this version and updating will cause backwards incompatibility with other library versions as well for our customers. Thanks!

Any update on above? Thanks!

@esrauchg
Copy link
Contributor

We don't plan to backport to 4.25 as Py 4.x has has been end of lifed for a year (after a year of high prio fixes only). See the chart here:
https://protobuf.dev/support/version-support/#:~:text=TBD-,Release%20support%20chart,-Protobuf%20Python

The 25.x line is still specially maintenance support just for Java (so the same issue happening in Java would get a backport by contrast).

Note that we're even in the final quarter of official high prio backports only for Py 5.x, so 4.x is getting quite behind the version treadmill here.

Note that the breaking changes across this version boundaries are intentionally minor/obscure including that old gencode is still compatible, as described here:
https://protobuf.dev/support/cross-version-runtime-guarantee/#:~:text=minor%2C%20or%20micro).-,Python%2Dspecific%20Guarantees,-Since%20the%203.20.0

So we expect it should be rare that anyone should not be able to upgrade past these major version numbers without changing their application code at all.

@sfc-gh-ndua
Copy link

sfc-gh-ndua commented Feb 24, 2026

We don't plan to backport to 4.25 as Py 4.x has has been end of lifed for a year (after a year of high prio fixes only). See the chart here: https://protobuf.dev/support/version-support/#:~:text=TBD-,Release%20support%20chart,-Protobuf%20Python

The 25.x line is still specially maintenance support just for Java (so the same issue happening in Java would get a backport by contrast).

Note that we're even in the final quarter of official high prio backports only for Py 5.x, so 4.x is getting quite behind the version treadmill here.

Note that the breaking changes across this version boundaries are intentionally minor/obscure including that old gencode is still compatible, as described here: https://protobuf.dev/support/cross-version-runtime-guarantee/#:~:text=minor%2C%20or%20micro).-,Python%2Dspecific%20Guarantees,-Since%20the%203.20.0

So we expect it should be rare that anyone should not be able to upgrade past these major version numbers without changing their application code at all.

Thanks! We have other dependencies that will break such as google-cloud-sdk libs (https://github.com/observeinc/google-cloud-functions/blob/main/requirements.txt#L48)

venv) ➜ google-cloud-functions git:(main) ✗ python -m pip install -U "protobuf==6.33.5" Collecting protobuf==6.33.5 Using cached protobuf-6.33.5-cp39-abi3-macosx_10_9_universal2.whl.metadata (593 bytes) Downloading protobuf-6.33.5-cp39-abi3-macosx_10_9_universal2.whl (427 kB) Installing collected packages: protobuf Attempting uninstall: protobuf Found existing installation: protobuf 4.25.8 Uninstalling protobuf-4.25.8: Successfully uninstalled protobuf-4.25.8 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. google-cloud-org-policy 1.8.3 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-access-context-manager 0.1.16 requires protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-os-config 1.15.3 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-tasks 2.14.2 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-appengine-logging 1.4.3 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. grpc-google-iam-v1 0.12.6 requires protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-pubsub 2.18.4 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-asset 3.25.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. googleapis-common-protos 1.61.0 requires protobuf!=3.20.0,!=3.20.1,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0.dev0,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. google-cloud-compute 1.14.1 requires protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5, but you have protobuf 6.33.5 which is incompatible. proto-plus 1.22.3 requires protobuf<5.0.0dev

@psibre
Copy link

psibre commented Feb 25, 2026

@sfc-gh-ndua I don't want to tell you how to manage your dependencies, but all of the Google Cloud packages you have are apparently pinned to versions from around 2023. But they're all actively maintained and have had many releases since then, which are presumably compatible with protobuf v5+. So you could just upgrade them...?

@esrauchg
Copy link
Contributor

esrauchg commented Feb 25, 2026

Speaking authoritatively for Protobuf project: it does looking to me that cloud-sdk libs are stuck behind here (at least for their default set version, unclear about true-compatibility) and they is one of our biggest Google library usages. We'll follow up on that internally to see why its still stuck.

Broadly we also know being 3 years behind on some deps is also relatively normal for lots of projects; we are just trying to thread the needle on being able to make changes that keep Protobuf healthy while still avoiding breaking people; there's unfortunately a direct tension where total stability (which we did for a while) makes things stagnant on all axes which ends up slowly building up over time to harm.

We do try very hard to keep the breaking changes obscure to avoid people's difficulties upgrading. We had made some missteps with our last Java breaking change, which is partially why it has an extended support window, so we also know that even smaller seeming breaks can cause big problems for some customers.

We are likely to do a 25 release for an unrelated Java issue; depending on the state of Cloud SDK and difficulty in releasing the backport we may consider backporting this thing to Py 4.x as well even though its officially end of life (but no promises here).

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any JSON recursion depth bypass in Python json_format.ParseDict