/

CVE-2026-26954

Severity:

CRITICAL RISK

(10.0)

Code Injection / Sandbox Escape in SandboxJS

CVE-2026-26954

Analyzed

Vulnerability type

Category:

Code Injection / Sandbox Escape

CWE:

CWE-94

Impact:

Arbitrary Code Execution / Sandbox Escape

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, a JavaScript sandboxing library, allowed untrusted code to obtain arrays containing Function and then reconstruct callable function objects from them.

When this occurs, an attacker can escape the sandbox and execute arbitrary JavaScript code in the host context, fully bypassing intended isolation.

Affected context

This vulnerability affects applications that embed SandboxJS to execute potentially untrusted or user-supplied JavaScript in an isolated environment.

It becomes relevant when:

  • SandboxJS versions prior to 0.8.34 are used, and
  • The sandboxed code has access to constructs that leak Function via arrays, and
  • The sandboxed environment exposes utilities such as Object.fromEntries or similar helpers.

In such setups, the sandbox boundary can be bypassed, allowing sandboxed code to interact with the host environment in ways the application did not intend.

Exploit preconditions

  • Attack surface: JavaScript execution environment where SandboxJS runs untrusted or semi-trusted code.
  • Required access: Ability to supply or influence code executed inside the SandboxJS instance (e.g., user scripts, plugins, or configuration-based scripts).
  • Trigger point: Code paths that expose or return arrays containing Function, combined with access to Object.fromEntries or equivalent mechanisms that can rebuild objects with function-valued properties.
  • Why exploitation is possible: The sandbox design assumes that certain built-ins and objects are safe to expose, but the presence of Function in an array, coupled with object construction helpers, enables reconstruction of executable function objects. This breaks the isolation and maps to arbitrary code injection (CWE-94).

Why this happens

The underlying issue is an incomplete isolation model in the sandbox implementation.

SandboxJS attempts to restrict access to powerful primitives such as the Function constructor, which can compile and execute arbitrary code.

However, the library permits scenarios where arrays containing Function become reachable from inside the sandbox.

When combined with utilities like Object.fromEntries, sandboxed code can create objects with function-valued properties, effectively reintroducing a callable Function into the restricted environment.

This is a manifestation of CWE-94: Improper Control of Generation of Code, where the sandbox fails to fully control access to code generation primitives, allowing untrusted input to reach components that can dynamically create and execute code.

Potential impact

  • Execution of arbitrary JavaScript code with the privileges of the host environment, bypassing sandbox restrictions.
  • Access to data and APIs that should have remained isolated from untrusted scripts.
  • Manipulation of application state, including sensitive in-memory objects and configuration.
  • Potential theft of authentication tokens or session information exposed to the host environment.
  • Pivoting into broader system compromise if the sandboxed environment had access to powerful host APIs, file I/O, or network capabilities.

General mitigation guidance

Effective mitigation focuses on strengthening the isolation boundaries and eliminating unsafe exposure of code-generation primitives:

  • Review all sandboxed environments to ensure that constructors such as Function, eval, and similar code-generation APIs are inaccessible from sandboxed code, including via indirect references (arrays, prototypes, or helper APIs).
  • Avoid exposing general-purpose object construction helpers (e.g., Object.fromEntries, Object.assign, spread operators applied to host objects) to untrusted scripts when they can be combined with powerful primitives.
  • Enforce a strict object capability model inside the sandbox: only pass in the minimal set of functions and objects required for the sandboxed code to operate.
  • Employ defense-in-depth by running the hosting process with least privilege and separating high-risk script execution from sensitive data and operations.
  • Consider layering security controls (e.g., process-level isolation, VM-based sandboxes, or hardened interpreters) so that a logical sandbox escape does not automatically imply full system compromise.

How teams detect issues like this

Detection generally involves a combination of code inspection and automated analysis:

  • Static analysis and code review:
  • Look for any paths where Function, eval, or dynamic code construction (e.g., new Function, setTimeout with string arguments) can be reached from sandboxed code.
  • Examine bridges between host and sandbox for accidental exposure of host objects, arrays, or utilities that may contain or rebuild Function.
  • Verify that helper APIs like Object.fromEntries, Object.assign, or custom factory functions do not accept untrusted keys or values that can produce function-valued properties.
  • Automated scanning:
  • Use SAST or custom linters to flag usage of dynamic code-generation APIs in the context of sandbox implementations.
  • Add CI checks that detect the presence of high-risk primitives inside the set of objects and globals exposed to sandboxed code.
  • Runtime monitoring and tests:
  • Implement security-focused test cases that attempt to obtain Function or equivalent capabilities from the sandbox.
  • Monitor logs for unexpected errors or stack traces indicating that sandboxed code interacted with host-only APIs.

Sources

SourceLink
github.comgithub.com/nyariv/SandboxJS/security/advisories/GHSA-6r9f-759j-hjgv

Frequently asked

questions

It can be, if remote users are able to submit or control scripts that are executed inside SandboxJS. In such deployments, an attacker can exploit the sandbox escape over the network by sending crafted code.

The attacker needs the ability to run or influence code inside the SandboxJS instance. This could occur through user-defined scripts, templating features, plugin systems, or any feature that interprets user-supplied JavaScript within the sandbox.

The safest pattern is to ensure untrusted code cannot reach code-generation primitives. Audit the sandbox configuration and bridging logic to remove all direct and indirect exposure to Function, eval, and similar constructors, and limit the set of exposed host objects and helpers to a minimal, well-reviewed subset.

Treat sandboxing as a defense-in-depth mechanism rather than a single point of security. Use strict capability-based APIs, conduct regular security reviews of the sandbox boundary, employ automated checks for dynamic code execution features, and consider combining logical sandboxes with OS-level or process-level isolation so that a sandbox escape has limited impact.

Find out what's already
exploitable in your codebase.