Your RSA-2048 keys break in 2030. Find every one of them before attackers do.
📦
📦 npm
Not in CISA KEV
MEDIUM severity

GHSA-rgwj-5xj2-c3m3

MEDIUMFix: sidorares/node-mysql2@7c48343

GHSA-rgwj-5xj2-c3m3 is a medium-severity (CVSS 5.9) vulnerability in mysql2. O3 Security confirms whether GHSA-rgwj-5xj2-c3m3 is actually reachable in your code before you act, and blocks exploitation at runtime until you patch.

MySQL2: Unbounded zlib inflate in compressed MySQL protocol handler allows decompression-bomb DoS

Published
Aug 31, 2026
Updated
Sep 2, 2026
Affected
1 pkg
Patched
1 / 1
Exploits
None indexed
Exploitation data as of Sep 2, 2026 · OSV.dev, FIRST.org (EPSS)

Real-World Exposure

1 pkg affected

How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.

7Kother npm packages depend on this — each one inherits the vulnerability until it's patched upstream
mysql2npm
15.2Mdownloads / week

Description

Vulnerability Details

File: lib/compressed_protocol.js Line: 43 (zlib.inflate(body, (err, data) => { ... }) inside handleCompressedPacket)

Root Cause

When a connection is created with compress: true (and the server advertises CLIENT_COMPRESS), every incoming packet is unwrapped by handleCompressedPacket() in lib/compressed_protocol.js, which calls:

zlib.inflate(body, (err, data) => { ... });

No options object (in particular, no maxOutputLength) is passed. Node's zlib convenience methods default maxOutputLength to buffer.kMaxLength, which on this platform is Number.MAX_SAFE_INTEGER — i.e. effectively unbounded until the process runs out of memory. The 3-byte "length of payload before compression" field in the compressed-packet header is read (packet.readInt24()) but is only used to branch on !== 0; it is never used to cap or validate the actual inflate output size, and the real decompressed size is determined purely by the attacker-supplied deflate stream.

Because DEFLATE can reach compression ratios over 1000:1 for crafted repetitive input, an attacker who controls (or MITMs, on a non-TLS connection) the MySQL server endpoint can send a single small compressed packet that expands to gigabytes in the client's memory — a classic decompression-bomb / "zip bomb" applied to MySQL's client-compression protocol.

Attack Scenario

  1. Application connects with mysql2/mysql2/promise using compress: true (a documented option for reducing bandwidth, commonly used for cloud/WAN DB connections).
  2. The connection target is attacker-controlled or attacker-compromised, or an attacker MITMs a non-TLS connection.
  3. Right after authentication succeeds, the malicious endpoint sends one crafted compressed packet whose deflate stream is small on the wire (hundreds of KB) but decompresses to several GB.
  4. zlib.inflate() starts allocating memory for the full decompressed output with no ceiling.
  5. The Node.js process's RSS grows uncontrolled until OOM-kill or crash — no query needs to be issued by the client; the malicious packet alone is enough.

Impact

Denial of Service of the client application (process crash / OOM) — not the database itself. No authentication bypass or data exposure. Requires compress: true plus a malicious/compromised server or MITM position.

Vulnerable Code

function handleCompressedPacket(packet) {
  const connection = this;
  const deflatedLength = packet.readInt24();
  const body = packet.readBuffer();

  if (deflatedLength !== 0) {
    connection.inflateQueue.push((task) => {
      zlib.inflate(body, (err, data) => {
        if (err) {
          connection._handleNetworkError(err);
          return;
        }
        connection._bumpCompressedSequenceId(packet.numPackets);
        connection._inflatedPacketsParser.execute(data);
        task.done();
      });
    });
  } else {
    ...
  }
}

Recommended Fix

const MAX_INFLATED_PACKET_SIZE = 1 * 1024 * 1024 * 1024; // e.g. 1 GiB, ideally configurable

zlib.inflate(body, { maxOutputLength: MAX_INFLATED_PACKET_SIZE }, (err, data) => {
  if (err) {
    connection._handleNetworkError(err);
    return;
  }
  ...
});

maxOutputLength makes zlib.inflate abort with ERR_BUFFER_TOO_LARGE as soon as the decompressed size would exceed the cap, routing into the exact same (already-existing) errconnection._handleNetworkError(err) path, so no new error-handling logic is required.

Verification

Dynamically confirmed on v3.23.0 (HEAD) using a minimal rogue "MySQL server" built on node-mysql2's own server-mode helpers (mysql.createServer, Packets.Handshake, connection.writeOk()). The rogue server completes a real handshake advertising CLIENT_COMPRESS, then writes one raw compressed frame (509,604 bytes on the wire — a zlib deflate of 500 MB of zero bytes, ratio 1028.8:1) directly to the socket. A normal mysql.createConnection({ ..., compress: true }) victim client — which never issues any query — had its RSS grow from 74.3 MB to 1115.0 MB after receiving that single packet, before erroring out with PROTOCOL_UNEXPECTED_PACKET once the client tried to parse the inflated zero-filled buffer as MySQL packets. The memory allocation happens unconditionally before any content validation.

Affected Packages

1 total 1 fixed
EcosystemPackageVulnerable rangeFix
📦npmmysql2all versions3.23.1

Detection & mitigation playbook

Open-source dependency
  1. Detect

    Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for mysql2. O3's reachability analysis confirms whether the vulnerable code path is actually invoked in your application, so you act on real exposure instead of every transitive match.

  2. Fix

    Update mysql2 to 3.23.1 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-rgwj-5xj2-c3m3 is resolved across your whole dependency graph.

  3. Workarounds

    If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.

  4. How O3 protects you

    O3 pinpoints whether GHSA-rgwj-5xj2-c3m3 is reachable in your code and exactly where to fix it, then blocks exploitation in production at runtime until the patched version is deployed.

Tailored to GHSA-rgwj-5xj2-c3m3. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.

Frequently Asked Questions

## Vulnerability Details **File**: `lib/compressed_protocol.js` **Line**: 43 (`zlib.inflate(body, (err, data) => { ... })` inside `handleCompressedPacket`) ### Root Cause When a connection is created with `compress: true` (and the server advertises `CLIENT_COMPRESS`), every incoming packet is unwrapped by `handleCompressedPacket()` in `lib/compressed_protocol.js`, which calls: ```js zlib.inflate(body, (err, data) => { ... }); ``` No options object (in particular, no `maxOutputLength`) is passed. Node's zlib convenience methods default `maxOutputLength` to `buffer.kMaxLength`, which on this
O3 Security · Impact-Aware SCA

Is GHSA-rgwj-5xj2-c3m3 in your dependencies?

O3 detects GHSA-rgwj-5xj2-c3m3 across npm dependencies and uses function-level reachability to confirm whether the vulnerable code path is actually reachable — not just present. No false positives.

GHSA-rgwj-5xj2-c3m3: mysql2 Authentication… | O3 Security