-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The defense's state was on the prototype the defense was built to outwit\n\nvm2's bridge is `lib/bridge.js`, and the whole bridge is wrapped in a `createBridge` factory. `createBridge` is instantiated twice when a VM starts: once in the host realm, once in the sandbox realm. The two instances share source code; their closure-local `[]` literals, `{}` literals, and `Map`/`Set` allocations bind to the realm that instantiated them.\n\nWhen sandbox code invokes a host function, the call dispatches into the proxy `apply` trap of the host-function wrapper. That wrapper was registered with sandbox-side handlers, so the trap body runs in the **sandbox** instance of the bridge closure. Inside that body, the `[]` literal in `neutralizeArraySpeciesBatch` allocates a **sandbox-realm Array**. Its prototype chain is sandbox `Array.prototype`. The sandbox can install setters on it.\n\nThe unfixed function:\n\n```javascript\nfunction neutralizeArraySpeciesBatch(context, args) {\n const saved = [];\n const c = neutralizeArraySpeciesOn(context);\n if (c) saved[saved.length] = c;\n if (args) {\n const len = args.length | 0;\n for (let i = 0; i < len; i++) {\n const s = neutralizeArraySpeciesOn(args[i]);\n if (s) saved[saved.length] = s;\n }\n }\n return saved;\n}\n```\n\n`saved[saved.length] = c` is an ordinary index assignment to a property that does not exist as an own slot. ECMAScript's `OrdinarySet` walks the prototype chain, finds `Array.prototype[0]` if a setter has been installed there, and invokes the setter with `value = c` and `this = saved`.\n\n`c` is the record produced by `neutralizeArraySpeciesOn`:\n\n```javascript\n{ __proto__: null, arr, originalDesc, marker: SPECIES_NEUTRALIZED }\n```\n\n`arr` is the host-realm proxy of the argument array. It is the exact value the bridge spends 306 lines hiding from V8's C++ species lookup. The defense walks every host array entering the bridge, captures a host-realm proxy reference, and writes that reference into a container whose write operator the sandbox can intercept.\n\n## The full exploit is one setter\n\nThe canonical PoC, reduced from vm2's own advisory test fixture at `test/ghsa/GHSA-9qj6-qjgg-37qq/repro.js`:\n\n```javascript\nconst { VM } = require('vm2');\nnew VM().run(`\n const a = [];\n Object.defineProperty(Array.prototype, 0, {\n set(value) {\n a.f = Buffer.prototype.inspect;\n value.arr.f.constructor.constructor('return process')()\n .mainModule.require('child_process').execSync('touch pwned');\n }\n });\n new Buffer(a);\n`);\n```\n\nWalked in order:\n\n1. Sandbox allocates `a`, an empty sandbox-realm array.\n2. Sandbox installs a setter on `Array.prototype[0]`. The setter body runs whenever any sandbox-realm Array is index-assigned at slot 0 without an own slot.\n3. Sandbox calls `new Buffer(a)`. The call dispatches into the bridge's host-Buffer proxy. The proxy's `construct` trap runs in the sandbox-realm closure.\n4. The trap converts arguments via `otherFromThisArguments(args)`, then calls `savedSpecies = neutralizeArraySpeciesBatch(null, args)`.\n5. `neutralizeArraySpeciesBatch` allocates `saved = []` (sandbox-realm), computes `s = neutralizeArraySpeciesOn(args[0])`, and gets back `{ __proto__: null, arr: , originalDesc, marker }`.\n6. `saved[saved.length] = s` walks the prototype chain. `Array.prototype[0]` has a setter. The setter fires with `value = s`.\n7. Inside the setter, sandbox code plants `a.f = Buffer.prototype.inspect`, reads `value.arr.f` through the host-realm proxy (returning a host-realm `Function` instance), then climbs `value.arr.f.constructor.constructor(\"return process\")()` to host `process`, then `process.mainModule.require('child_process').execSync('touch pwned')` for arbitrary command execution.\n\nThe setter ran inside a function the bridge wrote, with state the bridge produced, while the bridge was halfway through installing the defense against the underlying primitive. The bookkeeping was the exfiltration channel.\n\n## The discipline already existed. The new function did not use it.\n\nThe fix commit's bridge.js change is forty lines. It replaces the two `saved[saved.length] = ...` writes with `thisReflectDefineProperty(saved, savedLen, { __proto__: null, value, writable: true, enumerable: true, configurable: true })`. `Reflect.defineProperty` installs an own data property without consulting the prototype chain. The setter on `Array.prototype[0]` does not fire.\n\n`thisReflectDefineProperty` is not new code. It is captured in the bridge module's top-level closure at module load, before any sandbox code runs, the same way `thisArrayCtor` was captured for the prior fix. The bridge uses it at line 2403, in the function that converts host-realm argument arrays into sandbox-realm ones:\n\n```javascript\nfunction thisFromOtherArguments(args) {\n const arr = [];\n for (let i = 0; i < args.length; i++) {\n const value = thisFromOther(args[i]);\n thisReflectDefineProperty(arr, i, {\n __proto__: null,\n value: value,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n return arr;\n}\n```\n\nAllocates a sandbox-realm Array. Appends elements without walking the prototype chain. The reason is documented in the patch commit message for CVE-2026-44008:\n\n> The bridge's existing pattern in `thisFromOtherArguments` already uses `thisReflectDefineProperty` to install argument indices precisely because index assignment via `[i] =` triggers prototype-chain setters. `neutralizeArraySpeciesBatch` did not follow that pattern; the regression was introduced when the species defense (GHSA-grj5-jjm8-h35p) replaced its earlier no-restore variant with a `saved`-list design.\n\nThe discipline lived in the same file. The new function did not inherit it. The reviewer who landed 306 lines to lie to V8's C++ `ArraySpeciesCreate` did not read the function near the one they were patching.\n\n## The threat model grew by one invariant\n\nThe same fix commit modifies `docs/ATTACKS.md`. It adds Defense Invariant #11: bridge-internal containers must not invoke sandbox code. Lists, maps, and saved-state records allocated for the bridge's exclusive use are reached from sandbox-realm closures whose intrinsics (`Array.prototype`, `Object.prototype`, `Map.prototype`) are attacker-reachable. Reads and writes on those containers must use prototype-bypassing primitives like `Reflect.defineProperty` and `Reflect.apply` over cached `WeakMap.prototype.{get,set}`, never operators (`obj[i] =`, `map.set`, `for...in`) that fall through to the sandbox prototype chain.\n\nvm2 had ten prior Defense Invariants. The eleventh exists because the patch from seven days earlier violated it.\n\nThe same commit adds Attack Category 28, \"Bridge Internal-State Leak via Sandbox-Realm Array Setter,\" whose *Why It Works* section identifies the structural property: `createBridge` runs twice, once per realm; `[]` literals in the sandbox-side instantiation are sandbox-realm; the sandbox controls the prototype chain. The category exists in the file because the species defense added new bridge-internal containers, and the containers were not audited against an invariant that had not yet been written down.\n\n## Each new defense in vm2 is itself surface area\n\n[CVE-2026-24118's writeup](/posts/vm2-cve-2026-24118-resetpromisespecies-has-a-sibling) named the defense vocabulary. `lib/setup-sandbox.js` and `lib/bridge.js` together hold `resetPromiseSpecies`, `neutralizeArraySpeciesBatch`, the `WebAssembly.JSTag` deletion, the `%AsyncGeneratorPrototype%` wrap, and `handleException`'s SuppressedError recursion. Each entry exists because V8 implements a language feature whose C++ surface reads through to a raw object the Proxy bridge cannot trap. The vocabulary grows whenever V8 ships another such feature.\n\nCVE-2026-44008 names a different layer. The vocabulary is not just the inventory of V8 surfaces vm2 cannot trap; it is now also the inventory of bridge-internal containers each defense allocates, the realm those containers belong to, and which operators on those containers walk into sandbox-controlled prototypes. Defense Invariant #11 is the codification of an audit pass the previous defenses did not need because their fixes did not allocate per-call state. The species defense did. The same primitive (sandbox `Array.prototype` is attacker-controlled) reached the new state through the same operator (`[i] =` walks the chain) the codebase had already neutralized everywhere else.\n\nThis is the [unpatchable primitive](/patterns/unpatchable-primitive) compounding. The CVE-2026-24118 patch was reactive to a V8-internal-bypass class. The CVE-2026-44008 patch is reactive to the CVE-2026-24118 patch. vm2 is a [design-debt driver](/patterns/design-debt-driver) at the substrate level, because Proxy traps cannot intercept V8's C++ reads and each species-using built-in needs its own per-call sanitization, and at the defense layer, because each new defense allocates new containers, and the containers inherit sandbox prototypes the maintainer has to remember to bypass.\n\nThe substrate produces the CVE that requires the defense. The defense produces the CVE that requires the invariant. The invariant produces the audit pass the next defense will be reviewed against, until the audit pass misses a new container the V8 design forces vm2 to introduce next.\n\n## The same function, two readings\n\nThe April 24 commit message framed `neutralizeArraySpeciesBatch` as analogous to `resetPromiseSpecies`, a sibling defense for the same V8-internal-bypass class. The May 1 commit message framed the same function as a regression, an instance of the bridge's established `[i] =` anti-pattern that the species fix had inadvertently reintroduced. Both messages were written by the same maintainer, one week apart, about the same function. The function did not change between the two readings. The maintainer's view of what the function was did.\n\nPoC: vm2's own test fixture at [`test/ghsa/GHSA-9qj6-qjgg-37qq/repro.js`](https://github.com/patriksimek/vm2/blob/master/test/ghsa/GHSA-9qj6-qjgg-37qq/repro.js). Patch: [`ca195f0`](https://github.com/patriksimek/vm2/commit/ca195f0178989d6f59eafb7af965806f829e20f7) in vm2 v3.11.2.","closing_line":"The defense was 306 lines. The leak in the defense was an unqualified index assignment.","hook_md":"vm2 closed CVE-2026-24118 on April 24, 2026 with one commit that added 306 lines to `lib/bridge.js`. The new function was `neutralizeArraySpeciesBatch`. Its job was to walk every host array entering the bridge before every sandbox-to-host call, install `constructor = undefined` as an own data property so V8's C++ `ArraySpeciesCreate` reads a benign default, and restore the original descriptor after the call returned.\n\nThe function holds per-call state in a fresh `[]`. The `[]` is sandbox-realm.\n\nCVE-2026-44008 is dated seven days later. The fix is one commit. It does not change what `neutralizeArraySpeciesBatch` does. It changes how the function appends to its own bookkeeping array.","post_id":353,"slug":"vm2-cve-2026-44008-defense-invariant-11","title":"CVE-2026-44008: vm2 Wrote Defense Invariant #11 Seven Days After the Patch That Violated It","type":"initial","unreadable_sentence":"vm2 wrote Defense Invariant #11 seven days after shipping the patch that violated it."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaj13NAAKCRDeZjl4jgkQ JgY8AQCOyKCq0I10CN9puGa8HhUfKQ+7vPjoRsu10IFkoMp69gD/TIiQy3HYXdUA Gd5eNRoDXoYPEzett3Yms9F1lxqGEQs= =4scn -----END PGP SIGNATURE-----