Visit the Wiz Whimzical Shop at AWS re:Invent
Vulnerability DatabaseGHSA-hvx6-xjcv-pww2

GHSA-hvx6-xjcv-pww2: 
Python vulnerability analysis and mitigation

Impact

pika decodes AMQP field tables and arrays recursively, with no depth limit (pika/data.py, decode_table and decode_value). A field table nested a few hundred levels deep makes the decoder raise RecursionError. The error is not caught where frames are decoded, so the adapter reports a lost stream and the connection closes. Two tables the client decodes are controlled by the other side:

  • server_properties in Connection.Start, decoded before authentication. A malicious or compromised broker can send it; so can an active intermediary on a connection without TLS. Verified TLS prevents the intermediary route.
  • headers in message properties, decoded on Basic.Deliver, Basic.GetOk and Basic.Return. Anyone with permission to publish a message that reaches a consumer's queue can send it, and RabbitMQ relays it. On the publisher route the message is a poison message. With manual acknowledgements it is redelivered on every reconnect and closes the consumer's connection each time, so the queue's consumers cannot make progress until the message is removed, for example by purging the queue or dead-lettering it. There is no evidence of code execution or of access to data outside the connection.

Measurements

  • At Python's default recursion limit of 1000, about 500 nested tables (about 3.5 KB), 665 alternating table and array levels, or about 1000 nested arrays raise RecursionError, on Python 3.7 and 3.14. This is well under the frame size limit.
  • Against RabbitMQ 4.4.0, a message with headers nested 600 deep is accepted, confirmed and delivered. The consuming connection then closes with StreamLostError: ("Stream connection lost: RecursionError('maximum recursion depth exceeded')",). With pika.Connection and manual acknowledgements, three consecutive connections each closed this way and the message stayed in the queue.
  • The reporter reproduced the broker route with a greeting of 1,800 alternating container levels against BlockingConnection on 1.4.4.

Affected versions

Every release before 1.5.1. The recursive decoder dates from 2011.

Fix

1.5.1 rejects received tables and arrays nested more than 32 deep with InvalidFrameError instead of recursing, the limit the RabbitMQ Java client uses.

  • A delivery whose headers exceed the limit is logged and, unless its consumer uses automatic acknowledgement, rejected without requeueing, so it goes to the queue's dead-letter exchange if one is configured. The consumer's connection stays open, which ends the redelivery loop.
  • Any other frame that exceeds the limit, such as a broker's Connection.Start or a Basic.GetOk or Basic.Return, ends the connection as any malformed frame does: StreamLostError, with the InvalidFrameError as its cause.

Workarounds

For versions before 1.5.1, the redelivery loop can be broken on the broker side:

  • Consume from a quorum queue. RabbitMQ 4.x applies a default delivery limit of 20 to quorum queues, after which the message is dropped or dead-lettered. Measured against RabbitMQ 4.4.0: the consumer failed 21 times, then consumed the next message.
  • Configure a dead-letter exchange on the queue so a message dropped at the delivery limit is kept rather than lost.
  • Use a prefetch count of 1. With a larger prefetch, other messages delivered in the same batch are returned to the queue each time the connection closes, and count toward their own delivery limit.

<details> <summary>Patch proposed by the reporter</summary> The reporter tested this against 06b5a039, with a regression test:

diff --git a/pika/data.py b/pika/data.py
index 121db9d98bf357072ccfbbbe2b74b68aeb0ecbdb..c31690ab2912c381c537c0f87fd9123ae8f5a3e9 100644
--- a/pika/data.py
+++ b/pika/data.py
@@ -259,7 +259,7 @@ def encode_value(pieces: list[bytes], value: Any) -> int:
 
 
 def decode_table(encoded: bytes,
-                 offset: int) -> tuple[dict[str | bytes, Any], int]:
+                 offset: int, depth: int = 0) -> tuple[dict[str | bytes, Any], int]:
     """
     Decode the AMQP table passed in from the encoded value returning the decoded result and the
     number of bytes read plus the offset.
@@ -267,18 +267,20 @@ def decode_table(encoded: bytes,
     :param encoded: The binary encoded data to decode
     :param offset: The starting byte offset
     """
+    if depth > 32:
+        raise exceptions.InvalidFrameError("Field table nesting depth exceeds 32")
     result = {}
     tablesize = _PACK_UINT.unpack_from(encoded, offset)[0]
     offset += 4
     limit = offset + tablesize
     while offset < limit:
         key, offset = decode_short_string(encoded, offset)
-        value, offset = decode_value(encoded, offset)
+        value, offset = decode_value(encoded, offset, depth)
         result[key] = value
     return result, offset
 
 
-def decode_value(encoded: bytes, offset: int) -> tuple[Any, int]:
+def decode_value(encoded: bytes, offset: int, depth: int = 0) -> tuple[Any, int]:
     """
     Decode the value passed in returning the decoded value and the number of bytes read in addition
     to the starting offset.
@@ -291,6 +293,8 @@ def decode_value(encoded: bytes, offset: int) -> tuple[Any, int]:
     """
     # Dispatch on the raw type-tag byte (avoids a bytes allocation per field);
     # the most common field types are checked first.
+    if depth > 32:
+        raise exceptions.InvalidFrameError("Field value nesting depth exceeds 32")
     value: Any
     kind = encoded[offset]
     offset += 1
@@ -340,16 +344,18 @@ def decode_value(encoded: bytes, offset: int) -> tuple[Any, int]:
 
     # Field Table
     elif kind == _FIELD_TABLE:
-        (value, offset) = decode_table(encoded, offset)
+        (value, offset) = decode_table(encoded, offset, depth + 1)
 
     # Field Array
     elif kind == _FIELD_ARRAY:
+        if depth >= 32:
+            raise exceptions.InvalidFrameError("Field array nesting depth exceeds 32")
         length = _PACK_UINT.unpack_from(encoded, offset)[0]
         offset += 4
         offset_end = offset + length
         value = []
         while offset < offset_end:
-            val, offset = decode_value(encoded, offset)
+            val, offset = decode_value(encoded, offset, depth + 1)
             value.append(val)
 
     elif kind == _FIELD_BYTE_ARRAY:
diff --git a/tests/unit/nesting_tests.py b/tests/unit/nesting_tests.py
new file mode 100644
index 0000000000000000000000000000000000000000..746768855dc53c4205eb4d6fd4595ee7205e6a65
--- /dev/null
+++ b/tests/unit/nesting_tests.py
@@ -0,0 +1,21 @@
+import struct
+
+import pytest
+
+from pika.data import decode_table
+from pika.exceptions import InvalidFrameError
+
+
+def nested_table(depth):
+    value = b't\x01'
+    for index in range(depth):
+        body = value if index % 2 else b'\x01x' + value
+        value = (b'A' if index % 2 else b'F') + struct.pack('>I', len(body)) + body
+    body = b'\x01k' + value
+    return struct.pack('>I', len(body)) + body
+
+
+def test_field_nesting_limit():
+    decode_table(nested_table(8), 0)
+    with pytest.raises(InvalidFrameError, match='nesting depth'):
+        decode_table(nested_table(40), 0)

Happy to test a fix whenever it's useful. Dickson Wu (SEAL & CertiK) </details>


Source: NVD

Related Python vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

GHSA-2vwr-58qv-f67xMEDIUM6.5
  • Python logoPython
  • aiortc
NoYesDec 02, 2026
GHSA-hvx6-xjcv-pww2MEDIUM6.5
  • Python logoPython
  • pika
NoYesDec 02, 2026
CVE-2026-141556MEDIUM4.7
  • Python logoPython
  • lxml-html-clean
NoYesDec 02, 2026
CVE-2026-141555MEDIUM4.7
  • Python logoPython
  • lxml-html-clean
NoYesDec 02, 2026
GHSA-xhqj-2fcc-8vf7LOW3.1
  • Python logoPython
  • ag2
NoYesDec 02, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Additional Wiz resources

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management