MongoBleed is a recently disclosed pre-authentication memory disclosure vulnerability in MongoDB Server, formally tracked as CVE-2025-14847. The flaw resides in the zlib-based network message compression logic, where incorrect handling of client-supplied length metadata can cause the server to return uninitialized heap memory to remote attackers without requiring authentication. This class of defect has been widely compared to the infamous Heartbleed memory leak in OpenSSL- therefore the name "MongoBleed" - because both arise from a mistrust of length/size metadata that leads to silent memory exposure.
Background: MongoDB Wire Protocol and Compression:
Modern MongoDB servers communicate with clients using the OP_MSG wire protocol. To reduce bandwidth and latency, MongoDB supports optional message compression using algorithms such as zlib, snappy, zstd.
MongoDB network flow (simplified):
The bug occurs before authentication, specifically inside message decompression & buffer handling.
The Core Bug: Length Trust Violation:
The vulnerability stems from improper length validation within the MongoDB OP_COMPRESSED handler. When a client sends a compressed message, the server trusts the user-provided uncompressed_size value and uses it to allocate a memory buffer on the heap.
The exploit occurs when an attacker specifies an uncompressed_size that is intentionally much larger than the actual decompressed data. While the decompression process fills the start of the buffer, the remaining "slack space" is left untouched and uninitialized. Because this memory is not zeroed out, it still contains "stale" data from previous heap allocations such as session tokens, credentials, or TLS keys. When the server reflects the full buffer back to the client, it inadvertently leaks this sensitive internal memory.
Step-by-Step Memory Timeline
Step 1: Malicious packet arrives
Attacker sends
Compressed Payload:
- Declared uncompressed size: 64 KB
- Real decompressed size: 120 bytes
Step 2: Server allocates heap memory
char* buf = malloc(65536); // based on uncompressed_size
// ** malloc does NOT zero memory
Heap may contain
[ valid data | leftover heap | sensitive fragments ]
Step 3: Decompression happens
actual_len = inflate(zlib_stream, buf);
Result:
buf[0..119] → valid decompressed data
buf[120..65535] → untouched memory
Step 4: Fatal mistake wrong length used (This is the bug)
Instead of sending:
send(socket, buf, actual_len);
The server sends:
send(socket, buf, declared_uncompressed_size);
The attacker receives raw heap memory returned by the system, which may include data from other users’ queries, credentials still resident in memory, internal data structures, and occasionally readable secrets that were never intended to be exposed.
Understanding BSON in the Context
When a compressed OP_MSG is received, MongoDB first parses the compression header, then invokes the zlib inflate algorithm to expand the payload into a heap buffer sized according to the client-supplied uncompressed length. The BSON parser is subsequently invoked on this buffer and relies on BSON’s self-describing structure to traverse the data. If zlib inflation produces fewer bytes than the declared size, the remaining portion of the buffer contains uninitialized heap memory. Because the parser and subsequent response handling operate on the full allocated buffer rather than the actual number of bytes produced by zlib, adjacent heap data from prior requests may be inadvertently exposed.
Why This Is Pre-Authentication
This vulnerability manifests before authentication because MongoDB must process and decompress incoming network messages prior to understanding their semantic intent. Compression handling occurs ahead of message parsing, meaning the server is required to decompress the payload in order to determine what command the client is attempting to execute, including authentication commands themselves. As a result, the decompression logic is invoked without any prior trust boundary enforcement. Compounding this issue, authentication credentials and related security material may already be present in heap memory from previous connections or internal operations, making them susceptible to exposure when uninitialized heap buffers are inadvertently returned to the client.
Why the Server Does Not Crash
MongoBleed does not cause the server to crash because it is not a memory corruption vulnerability, but rather a buffer over-read. Unlike buffer overflows, use-after-free conditions, or double-free bugs, which typically result in process termination or exploitable control-flow corruption, this flaw merely causes the server to read and transmit memory that it should not. Since the accessed memory is still valid heap space and no illegal writes occur, MongoDB continues operating normally. This silent failure mode allows the server to leak sensitive data without triggering crashes, alerts, or obvious instability, significantly complicating detection and incident response.
Affected Versions
| Version | Affected Range | Fixed Version |
|---|---|---|
| 8.2.x | 8.2.0–8.2.2 | 8.2.3 |
| 8.0.x | 8.0.0–8.0.16 | 8.0.17 |
| 7.0.x | 7.0.0–7.0.27 | 7.0.28 |
| 6.0.x | 6.0.0–6.0.26 | 6.0.27 |
| 5.0.x | 5.0.0–5.0.31 | 5.0.32 |
Recommended Actions for Security Teams
- Upgrade immediately to a patched MongoDB version: 8.2.3, 8.0.17, 7.0.28, 6.0.27, 5.0.32, or 4.4.30
- If patching is not possible, disable zlib compression and use
snappy,zstd, or disable compression entirely - Restrict network exposure by removing MongoDB from the public internet and enforcing firewall or private network access
- Monitor MongoDB logs for anomalous pre-authentication behavior or suspicious connection patterns

Top comments (0)