Summary
A critical sandbox-escape vulnerability in vm2 can allow untrusted sandbox code to obtain a functional proxy to objects from the host Node.js process. When a bridged host Promise rejects with an Error containing a host-object property and its rejection handler is registered through certain call or apply indirection, the value sanitization step can be bypassed, potentially enabling remote code execution with host-process privileges.
Affected context
The vulnerability occurs in vm2 deployments that expose host-realm asynchronous functions or Promise objects to sandboxed code. Risk is present when a host Promise rejects with an Error whose own properties include non-primitive references to host objects, and the rejection handler is registered through an indirect call or apply path that defeats the bridge's identity check.
Exploit preconditions
- Attack surface: vm2's Promise bridge and sandbox-to-host asynchronous interaction
- Required access: Ability to execute untrusted JavaScript within the vm2 sandbox
- Trigger point: Handling a rejected host Promise through an indirect
Function.prototype.callorapplyregistration path - Required host state: The rejected Error must expose an own property referencing a host object
- Why exploitation is possible: The bridge may forward the raw host Error without rebuilding or sanitizing its host-object properties
Why this happens
The underlying bug is an incomplete sandbox boundary check in the Promise rejection bridge. The bridge determines whether sanitization is necessary by identity-checking only the direct call target; indirection through Function.prototype.call or apply changes the observed target and prevents the sanitizer from running.
This maps to CWE-94: Improper Control of Generation of Code, because sandboxed input can gain access to host capabilities that can be used to generate or execute commands. More broadly, the flaw reflects an incorrect trust-boundary assumption in proxy and object sanitization logic.
Potential impact
- Sandbox code may obtain a functional proxy to a host object
- Attackers could execute arbitrary commands in the host Node.js process
- Host credentials, files, environment variables, or services may be accessed
- The application and other workloads sharing the host process could be compromised
- Data confidentiality, integrity, and availability may be affected
General mitigation guidance
Mitigation generally focuses on maintaining a complete and conservative host-to-sandbox boundary.
Common defensive patterns include:
- Treating all host-realm Promise results, rejection values, and Error properties as untrusted
- Sanitizing or reconstructing rejected values before they cross into sandbox code
- Resolving indirect invocation paths consistently, including
call,apply, binding, and reflective invocation - Exposing only narrowly scoped, least-privilege host functions to untrusted code
- Avoiding host-object references in errors or other values returned across the boundary
- Separating sandbox workloads from sensitive host processes and capabilities where possible
- Applying dependency governance that requires security review of sandbox and isolation libraries
How teams detect issues like this
Detection can combine dependency review with source-level and runtime analysis:
- Use static analysis to identify bridge code that relies on direct function identity checks for security decisions
- Review Promise proxy handlers for incomplete treatment of
call,apply, binding, and reflective invocation - Search for host-realm asynchronous APIs exposed directly to untrusted execution contexts
- Test rejected host Promises whose Error objects contain non-primitive host references
- Add policy checks preventing sensitive host objects from being returned through sandbox interfaces
- Monitor sandbox processes for unexpected child-process creation, filesystem access, or use of host module-loading capabilities
- Automated security testing and dependency scanners can help identify known isolation-library weaknesses

