/

CVE-2026-22709

Severity:

CRITICAL RISK

(9.8)

Code Injection / Sandbox Escape in vm2 for Node.js

CVE-2026-22709

Analyzed

Vulnerability type

Category:

Code Injection / Sandbox Escape

CWE:

CWE-94, CWE-693, CWE-913

Impact:

Remote Code Execution / Sandbox Breakout

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

vm2's Promise callback sanitization can be bypassed by abusing async function return values, which are implemented as global Promise objects whose callbacks are not correctly sanitized.

Under these conditions, an attacker running code inside a vm2 sandbox may escape isolation and execute arbitrary code in the host Node.js environment.

Affected context

This vulnerability affects applications that rely on vm2 as a security boundary to sandbox untrusted or semi-trusted JavaScript.

Specifically, it arises when:

  • vm2 is used in versions prior to 3.10.2
  • Untrusted code can define or invoke async functions inside the sandbox
  • The application assumes vm2 reliably prevents access to the host Node.js environment

In these setups, differences between local Promise and global Promise handling create an unintended escape hatch.

Exploit preconditions

  • Attack surface: Code paths that execute untrusted or user-supplied JavaScript inside a vm2 sandbox.
  • Required access: Ability to supply or influence JavaScript executed within vm2 (e.g., plugins, scripts, user-defined rules, online code runners).
  • Trigger point: Execution of async functions whose return values are globalPromise objects, enabling use of unsanitized then/catch callbacks.
  • Why exploitation is possible: vm2 sanitizes callbacks on localPromise.prototype.then, but not on globalPromise.prototype.then; async functions return global Promise instances, so attacker-controlled callbacks can interact with host objects and escape the sandbox.

Why this happens

The core issue is an incomplete enforcement of the sandbox boundary for asynchronous promise handling.

vm2 wraps and sanitizes certain Promise APIs (such as localPromise.prototype.then) to ensure callbacks execute in a restricted context, but leaves the corresponding globalPromise callbacks unsanitized.

Because async functions in JavaScript always return a Promise implemented as a globalPromise, attacker-controlled async code can attach then or catch callbacks that are not passed through vm2's security wrappers.

This design gap maps to:

  • CWE-94: Improper Control of Generation of Code, since untrusted code gains a pathway to execute arbitrary operations in the host environment.
  • It also relates to broken enforcement of a defined security boundary, where not all asynchronous primitives are treated consistently.

Potential impact

  • Execution of arbitrary JavaScript code in the host Node.js process outside the intended sandbox.
  • Complete compromise of the sandboxing guarantees provided by vm2.
  • Access to sensitive host resources (filesystem, network, environment variables, credentials) depending on host application permissions.
  • Ability to manipulate application logic, exfiltrate data, or pivot to other systems from the compromised host.
  • Potential use of the host process as a stepping stone for broader infrastructure attacks.

General mitigation guidance

Effective mitigation focuses on strengthening the sandbox boundary and reducing trust in sandboxed code:

  • Ensure all asynchronous primitives (Promises, async/await, microtasks) are consistently wrapped so that callbacks are always executed in a constrained context.
  • Treat sandboxed JavaScript as untrusted even when vm2 or similar tools are in use; apply additional isolation layers such as OS-level process separation, containers, or restricted system users.
  • Design sandbox policies following a strict allowlist model, exposing only minimal, well-reviewed APIs to sandboxed code and avoiding direct access to powerful host objects.
  • Adopt a defense-in-depth approach: even if the sandbox fails, limit the privileges of the hosting process (e.g., restricted filesystem access, minimal environment variables, limited network connectivity).
  • Regularly review sandbox configuration and usage patterns for assumptions that untrusted code is "fully contained" and adjust architecture to avoid relying on a single mechanism for isolation.

How teams detect issues like this

To identify and monitor for similar weaknesses:

  • Perform code reviews focusing on sandbox implementation details, ensuring that both synchronous and asynchronous execution paths are wrapped and sanitized consistently.
  • Use static analysis or custom linters to flag direct use of global Promise objects or unwrapped async behavior in sandboxed environments.
  • Introduce security-focused tests that intentionally attempt sandbox escape via async/await, Promises, and other advanced language features to validate isolation guarantees.
  • Apply dynamic monitoring and logging around sandbox boundaries to detect anomalous behavior, such as unexpected access to host APIs or modules from ostensibly sandboxed code.
  • Include automated security checks in CI/CD pipelines that validate the integrity of sandbox libraries and highlight changes affecting security-related code paths.

Sources

SourceLink
github.comgithub.com/patriksimek/vm2/commit/4b009c2d4b1131c01810c1205e641d614c322a29
github.comgithub.com/patriksimek/vm2/releases/tag/v3.10.2
github.comgithub.com/patriksimek/vm2/security/advisories/GHSA-99p7-6v5w-7xg8

Frequently asked

questions

It can be, if a remote user can supply or control JavaScript that your application runs inside vm2. For example, online code execution services, plugin systems, or user-configurable scripting engines may expose a remote attack surface.

The attacker must be able to execute or influence code within the vm2 sandbox (e.g., by submitting scripts, templates, or rules). No direct shell or file system access is required if the application already executes attacker-controlled code inside vm2.

Ensure that all Promise-related callbacks (including those from async functions) are subject to the same sanitization and wrapping as other sandboxed operations, and avoid relying solely on language-level mechanisms for security boundaries. Combine robust sandbox library configurations with OS-level isolation where feasible.

Treat sandboxes as one layer in a broader security strategy: design for least privilege, expose minimal APIs to sandboxed code, consistently review and test sandbox isolation for new language features, and use additional isolation techniques such as separate processes, containers, or VMs to reduce the impact of sandbox escapes.

Find out what's already
exploitable in your codebase.