
Cloud Vulnerability DB
A community-led vulnerabilities database
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.RecursionError, on Python 3.7 and 3.14. This is well under the frame size limit.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.BlockingConnection on 1.4.4.Every release before 1.5.1. The recursive decoder dates from 2011.
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.
Connection.Start or a Basic.GetOk or Basic.Return, ends the connection as any malformed frame does: StreamLostError, with the InvalidFrameError as its cause.For versions before 1.5.1, the redelivery loop can be broken on the broker side:
<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
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."