/

CVE-2026-25587

Severity:

CRITICAL RISK

(10.0)

Code Injection / Sandbox Escape in SandboxJS SAFE_PROTOTYPES

CVE-2026-25587

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 exposes Map.prototype through its SAFE_PROTOTYPES list, allowing sandboxed code to obtain and overwrite Map.prototype.has.

By modifying this prototype method, an attacker can escape the JavaScript sandbox and execute arbitrary code in the host environment when the sandbox or host logic relies on Map.prototype.has.

Affected context

This vulnerability affects applications that embed SandboxJS to execute untrusted or partially trusted JavaScript code in an isolated environment.

The issue becomes relevant when:

  • SandboxJS versions prior to 0.8.29 are used, and
  • The sandbox exposes Map and its prototype as "safe" via SAFE_PROTOTYPES, and
  • Host or sandbox internals rely on Map.prototype.has during sandboxed execution.

Under these conditions, the untrusted code can influence host-side behavior by tampering with the shared prototype.

Exploit preconditions

  • Attack surface: The JavaScript sandbox that runs attacker-controlled or tenant-controlled code.
  • Required access: Ability to provide or influence code executed inside SandboxJS (e.g., user scripts, plugins, custom expressions).
  • Trigger point: Execution of sandboxed code after Map.prototype has been exposed and the host or sandbox uses Map.prototype.has.
  • Why exploitation is possible: Map.prototype is treated as a safe prototype and shared across sandbox and host, so changes made by sandboxed code to Map.prototype.has affect subsequent calls, enabling execution of arbitrary logic outside intended sandbox boundaries.

Why this happens

The underlying issue is a violation of isolation guarantees due to shared mutable prototypes between sandboxed and host environments.

By placing Map in SAFE_PROTOTYPES and allowing direct access to Map.prototype, SandboxJS effectively grants sandboxed code the ability to mutate a globally shared prototype.

This aligns with CWE-94: Improper Control of Generation of Code, because the sandbox allows untrusted code to modify a function (Map.prototype.has) that is later invoked as part of trusted execution paths.

The core bug class is: treating shared mutable objects (especially prototypes and built-ins) as "safe" in a sandbox, allowing untrusted code to redefine behavior that trusted code will execute with its own privileges.

Potential impact

  • Sandbox escape, allowing untrusted code to run with the privileges of the host application.
  • Execution of arbitrary JavaScript in the host context, bypassing intended isolation controls.
  • Access to sensitive data, APIs, or secrets available to the host environment.
  • Tampering with application logic, including authorization checks that rely on Map usage.
  • Potential pivot to broader system compromise, depending on what the host JavaScript can access (e.g., server-side runtime, file system, network).

General mitigation guidance

Effective mitigation focuses on restoring strong isolation and avoiding shared mutable state between sandboxed and host code.

Recommended design patterns include:

  • Avoid treating built-in prototypes as "safe": do not expose Map.prototype or other mutable shared prototypes directly to untrusted code.
  • Use deep copies or frozen wrappers of objects exposed to untrusted code so that modifications cannot affect the host runtime.
  • Freeze or seal built-in prototypes (Object.freeze(Map.prototype) or equivalent), where compatible, to prevent runtime mutation of core behaviors.
  • Restrict the surface of host APIs and objects made available inside the sandbox; expose carefully designed facades instead of raw language-level constructs.
  • Apply the principle of least privilege in sandbox design: untrusted code should receive only the minimum functions and objects needed to perform its task, with no direct access to global prototypes.

How teams detect issues like this

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

  • Static analysis / code scanning:
  • Search for sandbox implementations that include built-in prototypes in "safe" allowlists (e.g., SAFE_PROTOTYPES).
  • Flag code that passes global prototypes (like Map.prototype, Object.prototype, etc.) into untrusted execution contexts.
  • Identify uses of SandboxJS that do not wrap or freeze exposed built-ins.
  • Code review heuristics:
  • Check any sandbox-related code for shared mutable objects between host and sandbox.
  • Review the list of allowed globals and prototypes in SandboxJS configurations.
  • Confirm that prototype mutation is either blocked or tolerated only in strictly controlled contexts.
  • Runtime monitoring / policy enforcement:
  • Use runtime assertions or policies that detect and block prototype pollution (e.g., attempts to overwrite built-in methods).
  • Employ security-focused linters and automated review tools that understand common sandbox escape patterns.

Sources

SourceLink
github.comgithub.com/nyariv/SandboxJS/commit/67cb186c41c78c51464f70405504e8ef0a6e43c3
github.comgithub.com/nyariv/SandboxJS/security/advisories/GHSA-66h4-qj4x-38xp

Frequently asked

questions

It is highly exploitable in any deployment where untrusted code runs inside SandboxJS and the host or sandbox internals rely on Map.prototype.has or related behavior. In such setups, an attacker can reliably escape the sandbox and execute arbitrary code with host privileges.

The attacker must be able to supply or influence the JavaScript executed inside SandboxJS—such as user-provided scripts, configuration-driven logic, or multi-tenant code execution features. No additional host-level permissions are required beyond sandbox code execution rights.

The safest pattern is to ensure that untrusted code cannot mutate any prototypes or global objects used by the host. In practice, that means not exposing raw built-in prototypes to the sandbox, freezing or wrapping exposed objects, and designing sandbox APIs that provide minimal, hardened interfaces instead of direct access to the host runtime.

Future designs should start from a deny-by-default model: expose as little as possible to untrusted code, avoid sharing mutable state, and treat all prototypes and globals as sensitive. Combine this with code review for sandbox boundaries, automated checks for prototype exposure, and routine security testing specifically focused on sandbox escape attempts.

Find out what's already
exploitable in your codebase.