/

CVE-2026-23830

Severity:

CRITICAL RISK

(10.0)

Sandbox Escape / Code Injection in SandboxJS

CVE-2026-23830

Analyzed

Vulnerability type

Category:

Sandbox Escape / Code Injection

CWE:

CWE-94, CWE-693, CWE-913

Impact:

Remote Code Execution via Sandbox Bypass

Severity:

CRITICAL RISK

(10.0)

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

SandboxJS prior to version 0.8.26 contains a sandbox escape where async, generator, and async-generator function constructors are not properly isolated from untrusted code.

Attackers running code inside the sandbox can obtain the native AsyncFunction constructor via .constructor and create new functions that execute in the host global scope, leading to full sandbox bypass and remote code execution.

Affected context

This vulnerability affects applications that:

  • Embed SandboxJS to execute untrusted or partially trusted JavaScript
  • Rely on SandboxJS's SandboxFunction to isolate arbitrary code
  • Allow creation and use of async functions, generator functions, or async generator functions inside the sandbox

The issue manifests where sandboxed code can access function constructors indirectly through .constructor properties, allowing it to cross the sandbox boundary.

Exploit preconditions

  • Attack surface: Any API surface that passes attacker-controlled or untrusted JavaScript into SandboxJS for evaluation or execution.
  • Required access: Ability to inject or influence JavaScript code that runs inside the SandboxJS environment (e.g., user-provided scripts, plugins, templates, or configuration).
  • Trigger point: Sandboxed code creates or uses async / generator functions and then accesses their .constructor property, obtaining the native host constructor.
  • Why exploitation is possible: The sandbox only replaces the global Function constructor with SandboxFunction but fails to remap AsyncFunction, GeneratorFunction, and AsyncGeneratorFunction. Through property access resolution in executor.ts, the real host constructor is exposed, and any function constructed with it executes in the unsandboxed global scope.

Why this happens

The underlying problem is incomplete isolation of function constructors, mapping to CWE-94: Improper Control of Generation of Code ('Code Injection') and CWE-693: Protection Mechanism Failure.

SandboxJS attempts to secure dynamic code execution by substituting the global Function with SandboxFunction via a lookup map. However, it overlooks related constructors (AsyncFunction, GeneratorFunction, AsyncGeneratorFunction) that are not globals but are accessible via .constructor on function instances. The executor's property access logic dutifully returns these native constructors because they are absent from the safe-replacement map, breaking the sandbox model.

This design flaw means that user-controlled code can still generate new functions using genuine engine constructors that run in the real global context, bypassing all sandbox controls and enabling arbitrary code execution on the host.

Potential impact

  • Execution of arbitrary JavaScript in the host environment outside the sandbox.
  • Complete bypass of security and resource restrictions enforced by SandboxJS.
  • Access to sensitive data, process environment variables, and in-process secrets.
  • Invocation of host APIs, including filesystem, network, and database layers exposed by the embedding application.
  • Pivoting to broader system compromise depending on host privileges and integrations.
  • Abuse of the application as a platform for further attacks (e.g., SSRF, data exfiltration).

General mitigation guidance

Effective mitigation focuses on hardening the sandbox boundary and reducing reliance on in-process sandboxes for strict isolation:

  • Comprehensive constructor isolation: Ensure that all function-like constructors (Function, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction, and any engine-specific variants) are wrapped or replaced with sandbox-aware versions. Apply this consistently in every property resolution path, not only for global properties.
  • Strict property access mediation: Centralize and harden property access logic so that traversing object graphs (e.g., .constructor, __proto__, constructor.prototype) cannot leak host-native constructors or powerful built-ins back into sandboxed code.
  • Minimize exposed host capabilities: Treat anything reachable from sandboxed objects as part of the attack surface. Avoid exposing unnecessary objects, methods, or references that might lead back to the host environment.
  • Privilege and trust reduction: Do not assume that the sandbox is perfect. Run the embedding process or sandbox executor with the least privileges possible (restricted filesystem access, minimal network, and scoped environment variables).
  • Defense-in-depth isolation: For highly untrusted code, prefer process-level or VM/container isolation over purely in-process JavaScript sandboxes. Use OS-level boundaries and inter-process communication to contain code execution.
  • Secure-by-default configuration: Ship the sandbox with the safest defaults—restricted globals, hardened constructors, and documented limitations—so that developers must opt into additional capabilities rather than starting from an overly permissive baseline.

How teams detect issues like this

Detection strategies can focus on both code-level patterns and runtime behavior:

  • Static analysis and code scanning:
  • Search for sandbox implementations that override Function but do not handle AsyncFunction, GeneratorFunction, and AsyncGeneratorFunction.
  • Flag property access mediators (executor, proxies, traps) that directly return host constructors without validation against a whitelist.
  • Detect code that allows untrusted scripts to access .constructor, __proto__, or prototype on function objects without constraint.
  • Code review heuristics:
  • During security review, treat any JavaScript sandbox as a critical component and verify the treatment of all function constructors and reflective capabilities.
  • Review any logic that maps or proxies native objects into the sandbox; ensure the mapping is complete and includes non-global but discoverable constructors.
  • Runtime monitoring:
  • Log and monitor usage of dynamic function generation (e.g., Function, async function constructors) and unexpected calls originating from sandboxed execution paths.
  • Use application-level auditing to spot sandboxed scripts that appear to open network connections, access files, or read sensitive configuration unexpectedly.
  • Automated testing:
  • Incorporate security regression tests that attempt .constructor-based escapes and other prototype chain traversal techniques against the sandbox.
  • Leverage fuzzing or property-based tests to explore unusual property access chains from within the sandbox.

Sources

SourceLink
github.comgithub.com/nyariv/SandboxJS/commit/345aee6566e47979dee5c337b925b141e7f78ccd
github.comgithub.com/nyariv/SandboxJS/security/advisories/GHSA-wxhw-j4hc-fmq6

Frequently asked

questions

Yes. If a web service, API, or application accepts user-supplied JavaScript (or logic that is compiled to JavaScript) and runs it inside SandboxJS, an attacker can exploit this issue remotely by providing crafted code that escapes the sandbox.

The attacker must be able to influence or supply code that executes within the SandboxJS environment. This might be through features like custom scripting, user-defined rules, plugin systems, or any configuration that is evaluated with the sandbox.

Ensure that all function-related constructors (Function, AsyncFunction, GeneratorFunction, AsyncGeneratorFunction) and similar powerful built-ins are consistently wrapped, replaced, or blocked within the sandbox's mapping and property access logic. Additionally, structure the sandbox so that no reflective paths (like .constructor or prototype traversal) can reintroduce native constructors from the host context.

Treat sandboxing as a high-risk, specialized feature: adopt defense-in-depth isolation (e.g., separate processes or containers), design sandbox APIs with minimal exposed surface, enforce comprehensive mediation of constructors and reflection, and include targeted security testing (including constructor-based escape attempts) in your development and CI pipelines for any new sandbox-related changes.

Find out what's already
exploitable in your codebase.