/

CVE-2026-25520

Severity:

CRITICAL RISK

(10.0)

Sandbox Escape / Code Injection in SandboxJS

CVE-2026-25520

Analyzed

Vulnerability type

Category:

Sandbox Escape / Code Injection

CWE:

CWE-74

Impact:

Arbitrary Code Execution Outside the Sandbox

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.29 contains a sandbox escape issue where return values of functions are not safely wrapped, allowing access to the host environment's Function constructor.

By chaining built‑in methods like Object.values, Object.entries, and Array.prototype.at, an attacker can obtain the host Function constructor and execute arbitrary code outside of the intended JavaScript sandbox boundaries.

Affected context

This vulnerability affects applications that embed untrusted or partially trusted JavaScript using SandboxJS versions prior to 0.8.29.

It becomes relevant when:

  • The sandbox is relied upon as a strong isolation boundary between untrusted code and the host environment.
  • Untrusted code can call functions that internally access host objects, with their return values exposed directly to sandboxed code.
  • The application assumes that built-in language features (like Object.* and Array.*) cannot be used to escape the sandbox.

In such setups, the sandbox may provide only the illusion of isolation while still leaking powerful references into the guest code.

Exploit preconditions

  • Attack surface: JavaScript execution environment where untrusted or semi-trusted scripts are run under SandboxJS.
  • Required access: Ability to execute or influence code that runs inside the SandboxJS instance (e.g., user-supplied scripts, plugins, templates, or extensibility hooks).
  • Trigger point: Invocation of functions that return objects containing references to host-level constructors or methods, which are then processed via Object.values / Object.entries and Array.prototype.at.
  • Why exploitation is possible: SandboxJS does not fully wrap or neutralize function return values, allowing internal references (including the host's Function constructor) to leak into the sandboxed context. Once obtained, Function can be used to construct and run arbitrary code in the host context, bypassing sandbox restrictions.

Why this happens

The core issue is incomplete mediation of object graphs crossing the sandbox boundary.

SandboxJS attempts to restrict what sandboxed code can access, but it does not consistently wrap or proxy the return values of functions that originate from the host environment.

As a result, sandboxed code can use built-in enumeration helpers (Object.values, Object.entries) and positional access (Array.prototype.at) to traverse returned objects and eventually reach the native Function constructor.

This pattern maps to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, in the sense that untrusted code can inject or construct executable code in a downstream execution engine (the host JavaScript environment) because critical elements (like Function and its arguments) are not adequately controlled at the trust boundary.

Potential impact

  • Execution of arbitrary JavaScript code in the host environment, bypassing sandbox restrictions.
  • Access to sensitive in-memory data, including secrets, tokens, or user information available to the host process.
  • Modification of application state, including tampering with security checks, business logic, or user data.
  • Lateral movement within the hosting environment, such as invoking host APIs, performing network requests, or interacting with the filesystem (where available).
  • Complete compromise of the security guarantees expected from using SandboxJS as an isolation mechanism.

General mitigation guidance

Effective mitigation centers on reinforcing the trust boundary between sandboxed and host code, and ensuring no powerful references leak into untrusted contexts.

Pattern-based guidance includes:

  • Comprehensive wrapping/proxying of return values: Ensure that any object, function, or constructor exposed to sandboxed code is passed through a strict proxy or wrapping layer that filters or replaces dangerous properties such as constructor, __proto__, and Function.
  • Deny access to powerful constructors: Prevent sandboxed code from obtaining references to Function, eval, or other dynamic code construction mechanisms. This may require structural filtering of object graphs before they are visible to the sandbox.
  • Minimize host object exposure: Design the sandbox API so that host objects are represented with minimal, purpose-built facades rather than exposing rich native objects or generic containers.
  • Implement allowlists over denylists: Define explicit, minimal sets of safe properties and methods that can be accessed from sandboxed code, rather than trying to blacklist known-dangerous ones.
  • Harden built-in method handling: Audit how language built-ins like Object.values, Object.entries, and array access helpers interact with wrapped objects, and ensure wrappers preserve security invariants even under introspection and enumeration.
  • Defense in depth at the application layer: Treat sandboxed execution as one layer of security; combine it with process isolation, least-privilege runtime permissions, and strict input validation on data returning from sandboxed code.

How teams detect issues like this

Detection focuses on identifying insecure sandbox boundaries and leaked powerful references:

  • Static analysis and linting:
  • Search for uses of SandboxJS or similar libraries where untrusted code is executed, and verify that wrapping and proxying are consistently applied to function return values.
  • Flag instances where host functions or constructors are passed directly into the sandbox without mediation.
  • Code review heuristics:
  • Review sandbox adapter layers for exposure of rich host objects, especially those with access to constructor properties or prototypes.
  • Inspect any bridging code that returns complex objects to the sandbox and ensure that it applies a strict transformation or proxy.
  • Look for assumptions in comments or docs claiming "full isolation" without evidence of systematic wrapping.
  • Runtime monitoring and policies:
  • Instrument sandbox environments to log attempts to access Function, eval, or other dynamic evaluators, and treat such access as an indicator of possible sandbox escape attempts.
  • Use security-focused automated tests or fuzzing that exercise built-in object enumeration and introspection patterns (Object.keys, Object.values, Object.entries, spread syntax) to discover unexpected escape paths.
  • Automated tooling:
  • Integrate security scanners or SAST tools that understand common sandbox patterns and can flag exposed constructors and unwrapped object graphs as potential vulnerabilities.

Sources

SourceLink
github.comgithub.com/nyariv/SandboxJS/commit/67cb186c41c78c51464f70405504e8ef0a6e43c3
github.comgithub.com/nyariv/SandboxJS/security/advisories/GHSA-58jh-xv4v-pcx4

Frequently asked

questions

Yes, if an application allows remote users to supply or influence JavaScript that is executed inside SandboxJS, then a remote attacker can often trigger this issue. The sandbox is not a reliable containment boundary in affected versions.

The attacker needs the ability to execute code within the SandboxJS environment—such as providing scripts, templates, or plugin logic. No direct access to the host environment is required; once the sandbox is reached, the escape can be performed purely through language features.

The safest pattern is to redesign the sandbox boundary so that no raw host objects or constructors are ever exposed to untrusted code. All values crossing into the sandbox should be passed through strict wrappers or facades that remove or neutralize powerful properties and constructors, and the sandbox should enforce a minimal, allowlisted API surface.

Prevention requires treating sandboxing as a rigorous security boundary: thoroughly model the threat, assume attackers can use all language features, and test for escapes using enumeration, prototype access, and dynamic constructor resolution. Combine strict proxying/wrapping, minimal APIs, regular security reviews of sandbox bridges, and automated tests or fuzzers specifically aimed at discovering ways to reach Function, eval, or other dynamic code execution primitives.

Find out what's already
exploitable in your codebase.