Summary
MySQL2: Unbounded zlib inflate in compressed MySQL protocol handler allows decompression-bomb DoS
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
- Application connects with
mysql2/mysql2/promiseusingcompress: true(a documented option for reducing bandwidth, commonly used for cloud/WAN DB connections). - The connection target is attacker-controlled or attacker-compromised, or an attacker MITMs a non-TLS connection.
- 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.
zlib.inflate()starts allocating memory for the full decompressed output with no ceiling.- 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.
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 {
...
}
}
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.
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.
GHSA-RGWJ-5XJ2-C3M3 has a CVSS score of 5.9 (Medium). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (3.23.1); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
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) err → connection._handleNetworkError(err) path, so no new error-handling logic is required.
Frequently Asked Questions
- What is GHSA-RGWJ-5XJ2-C3M3? GHSA-RGWJ-5XJ2-C3M3 is a medium-severity security vulnerability in mysql2 (npm), affecting versions <= 3.23.0. It is fixed in 3.23.1.
- How severe is GHSA-RGWJ-5XJ2-C3M3? GHSA-RGWJ-5XJ2-C3M3 has a CVSS score of 5.9 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of mysql2 are affected by GHSA-RGWJ-5XJ2-C3M3? mysql2 (npm) versions <= 3.23.0 is affected.
- Is there a fix for GHSA-RGWJ-5XJ2-C3M3? Yes. GHSA-RGWJ-5XJ2-C3M3 is fixed in 3.23.1. Upgrade to this version or later.
- Is GHSA-RGWJ-5XJ2-C3M3 exploitable, and should I be worried? Whether GHSA-RGWJ-5XJ2-C3M3 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether GHSA-RGWJ-5XJ2-C3M3 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix GHSA-RGWJ-5XJ2-C3M3? Upgrade
mysql2to 3.23.1 or later.