New Sandbox Escape Affecting Popular Node.js Sandbox Library Vm2
A sandbox escape in the vm2 library allows untrusted JavaScript to bypass promise sanitisation and execute arbitrary code in the host Node.js process. An attacker could run any command the Node process can, such as spawning child processes.
semgrep.dev
Published on semgrep.dev
Popular Node.js sandboxing library vm2 has just announced a critical vulnerability in their library which allows attackers to bypass their promise sanitization and execute arbitrary code, escaping the sandbox. This is a critical vulnerability with a 9.8 CVSS score, any application leveraging vm2 to run untrusted…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a fail-open case in the promise catch-block configuration meant that a global promise exception handler was not wrapped by the sanitiser, so an unscoped promise.catch could hoist into global scope and expose the real Error constructor.
Impact
An attacker could do anything the Node process can, including reading memory values and running arbitrary code or spawning child processes.
What the attacker needed
Application runs untrusted code in vm2; vm2 version 3.10.1 or earlier
The fix
The library was fixed in version 3.10.2; the text also recommends using isolated-vm or containerised isolation instead of vm2 for untrusted code.
How it was found
- Run untrusted JavaScript inside a vm2 sandbox.
- Create an error and set its name to a Symbol.
- Define an async function that returns the error's stack.
- Call the function to get a promise and attach an unscoped catch handler.
- Inside the handler, reach the real Error and Function constructors and execute a command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
vm2 is a tool that lets a Node.js program run someone else's JavaScript code in a restricted 'sandbox'. A flaw in how it handled promises (JavaScript's way of managing asynchronous results) let that code break out of the sandbox and run commands on the server, as if the attacker had direct access.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.