Discovered and reported by Goldberg Security Research. Responsibly disclosed to the maintainer; patched in 3.12.1.

The short version

If an embedder hands the vm2 sandbox a host-realm Promise — the return value of any exposed async API, which is an extremely common embedding pattern — sandbox code can escape to the host and run arbitrary commands. The rejection sanitizer that is supposed to prevent this is completely bypassed. The fix is one version bump. The impact is full host RCE from inside a sandbox that was designed to prevent exactly that.

Root cause

Two things combine to break the sandbox:

1. Species neutralisation only covers the sandbox Promise

After the earlier GHSA-27g9-p43v-cw3v fix, vm2 overrides .then, .catch and .finally on the sandbox Promise.prototype to call resetPromiseSpecies() before delegating to the native implementation. That blocks Symbol.species hijacks — but only for promises whose prototype chain goes through the sandbox intrinsic.

A genuine host-realm Promise crossing the bridge has the host Promise.prototype. Its .then resolves to the real host method. resetPromiseSpecies() is never called. The species channel is wide open.

2. Missing onRejected bypasses the callback sanitizer

The bridge's rejection sanitizer (hostPromiseSanitizeReject / makeSanitizedPromiseCallback) only wraps a .then/.catch slot when that slot holds a function. Call p.then() with no onRejected and V8 substitutes its internal Thrower reaction per spec:

// PerformPromiseThen (ECMA-262)
// "If IsCallable(onRejected) is false, set onRejected to Thrower."

Thrower re-throws the raw host rejection value directly into resultCapability.[[Reject]]. vm2's bridge never sees this substitution — there is no sandbox-realm slot to wrap. The sanitizer is not bypassed by a clever trick; it simply has no input to operate on.

The escape

Combining both gaps: sandbox code writes p.constructor = { [Symbol.species]: Evil } on the host Promise (ordinary property write on a non-frozen host object — permitted by design). V8 calls new Evil(executor) to build the reaction capability, executing inside the sandbox, where the attacker captures the raw resolve/reject closures from the executor.

Then p.then() with no onRejected. V8's Thrower re-throws the raw host rejection value straight into the captured reject closure. The delivered value is a fully functional bridge proxy of the host object — isProxy === true, .mainModule.require('child_process').execSync() works. Full host RCE.

const p = hostApiCall(); // host-realm Promise, rejected with a host object

p.constructor = { [Symbol.species]: function (executor) {
    executor(function () {}, function (hostValue) {
        // hostValue is RAW — never sanitized
        // hostValue.mainModule.require('child_process').execSync('id')
    });
}};

p.then(); // no onRejected → V8 Thrower → raw value to captured closure

No proxy-argument-wrapping, no handleException, no hostPromiseSanitizeReject chokepoint is on this path at all. The sanitizer is not defeated — it is never reached.

Proof

Our PoC confirms the escape meets three proof criteria:

  • isProxy === true — the received value is a genuine bridge proxy of a host object, not a sandbox-realm value.
  • hostValue.env.HOST_ONLY_SECRET reads a host-only environment variable the sandbox has no legitimate way to see (the default sandbox process stub has an empty env: {}).
  • hostValue.mainModule.require('child_process').execSync('echo PWNED') actually runs host shell commands.

The escape is unconditional given any exposed host-realm Promise. What the Promise resolves or rejects with determines the severity of the pivot, but the sanitizer bypass itself does not depend on the rejection value.

Why this matters

vm2 is used to sandbox untrusted code in Node.js applications. The entire point of the library is to prevent the sandbox from reaching the host. A critical escape means any application relying on vm2 ≤ 3.12.0 to isolate untrusted input — template engines, plugin systems, code-execution APIs — is running that untrusted code with full host privileges.

The bug is also a good case study in defense-in-depth failure. vm2 had multiple layers of Promise sanitisation, each added in response to a previous escape. This bypass does not break any of them — it finds a path that none of them cover. The species neutralisation covers the wrong prototype. The callback sanitizer only fires when there is a callback. V8's spec-compliant Thrower substitution is the bridge between the two gaps.

Remediation

  • Upgrade to vm2 ≥ 3.12.1.
  • Consider migrating to isolated-vm or a separate-process sandbox. vm2 has had a long history of escapes; the fundamental challenge of securing a same-process JS sandbox against a determined attacker is well-documented.

Related

References