Skip to content
Memory corruption Write-up Advanced

MongoBleed: A Granular Breakdown of MongoDB’s Pre-Auth Memory

MongoDB's zlib decompression trusted a client-supplied uncompressed size, so a crafted compressed message caused the server to return a larger buffer than the real decompressed data. An attacker could repeatedly probe a public-facing instance to leak leftover heap memory that may contain credentials, tokens and keys.

Shreyash Tambe Follow

Published on medium.com

Here’s a reality check: MongoDB is wildly popular as a NoSQL database in cloud environments and microservices. But security?

Shreyash Tambe, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The decompression code blindly trusted the client-supplied uncompressedSize and returned the whole allocated buffer rather than only the bytes actually decompressed.

Impact

An unauthenticated attacker could leak heap memory that may contain credentials, API keys and session tokens, though not every byte is useful and there is no remote code execution.

What the attacker needed

MongoDB reachable from the internet; zlib compression enabled; no authentication needed for the handshake

The fix

MongoDB patched the decompression code and users should upgrade to the fixed versions; disabling zlib compression is a workaround if patching is not possible yet.

How it was found

  1. Connect to the MongoDB server on port 27017, which needs no authentication for the initial handshake.
  2. Negotiate zlib compression with the server before authenticating.
  3. Send a normal command such as ping wrapped in an OP_COMPRESSED message, but set uncompressedSize far larger than the real payload.
  4. Receive the oversized response buffer, which includes leftover heap memory beyond the real decompressed data.
  5. Repeat the probing to collect more leaked memory over time.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

MongoDB is a database that talks to clients over the network. When compression is on, the client tells the server how big the decompressed message will be, and the server believed that number without checking. By claiming a much larger size than the real message, an attacker made the server send back extra memory that still held old data, which can include passwords or keys.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.