/

CVE-2026-43898

Severity:

CRITICAL RISK

(10.0)

Code Injection / Sandbox Escape in SandboxJS

CVE-2026-43898

Modified

Vulnerability type

Category:

Code Injection / Sandbox Escape

CWE:

CWE-94

Impact:

Arbitrary Code Execution in Host JavaScript Context

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 Function.caller on sandbox-defined functions, allowing sandboxed code to reach an internal LispType.Call runtime callback and recover blocked host primitives.

By invoking this callback with attacker-controlled context and object values, an attacker can obtain the real host Function constructor and execute arbitrary JavaScript in the host environment, fully escaping the sandbox.

Affected context

This vulnerability can appear in applications that rely on SandboxJS to execute untrusted or semi-trusted JavaScript code under strict isolation.

It is relevant when:

  • SandboxJS is used to restrict access to host globals, constructors, or native capabilities
  • The sandbox exposes functions implemented using host callbacks (e.g., LispType.Call)
  • Host code assumes that sandboxed scripts cannot reach the real Function constructor or other powerful reflection hooks

In such deployments, a sandbox escape can transform a confined scripting feature into full host-code execution within the application process.

Exploit preconditions

  • Attack surface: JavaScript execution paths that evaluate attacker-controlled or user-supplied code inside a SandboxJS instance.
  • Required access: Ability to provide or influence code executed within the sandbox (e.g., embedded script editors, rule engines, plugin systems, custom expressions).
  • Trigger point: Invocation of sandbox-defined functions whose caller property is accessible to sandboxed code.
  • Why exploitation is possible: The sandbox does not sufficiently mask or virtualize Function.caller, allowing code to:
  • Access the internal LispType.Call runtime callback
  • Invoke this callback with crafted context and obj arguments
  • Recover blocked host statics and the real Function constructor
  • Use Function to run arbitrary code in the host environment, bypassing sandbox restrictions.

Why this happens

The underlying issue is an incomplete isolation of reflection and meta-programming capabilities, mapping to CWE-94: Improper Control of Code Generation ('Code Injection').

SandboxJS relies on host-level callbacks and JavaScript functions but does not fully neutralize or encapsulate the Function.caller property on sandbox-defined functions.

Because Function.caller leaks the internal call stack and associated runtime callback (LispType.Call), sandboxed code can interact with low-level host constructs that were assumed to be unreachable.

Once exposed, these constructs can be invoked with attacker-controlled parameters to reconstruct the real host Function constructor, effectively reintroducing unrestricted code generation and breaking the sandbox's security model.

Potential impact

  • Full execution of arbitrary JavaScript in the host runtime, not just inside the logical sandbox.
  • Bypass of all sandbox-level access controls, including blocked statics and restricted APIs.
  • Access to sensitive host environment data, including in-process secrets, tokens, or configuration.
  • Ability to modify application behavior, tamper with security checks, or exfiltrate data.
  • Potential pivot to server-side compromise when SandboxJS is used in backend services.

General mitigation guidance

Mitigation focuses on hardening sandbox boundaries and ensuring that meta-programming entry points cannot leak host capabilities:

  • Restrict or fully virtualize reflection features such as Function.caller, Function.arguments, and similar stack-inspection APIs for sandbox-defined functions.
  • Encapsulate internal runtime callbacks so they are never directly reachable from user-controlled code paths, even via reflective properties.
  • Design sandbox APIs so that all callbacks are invoked through narrow, validated interfaces rather than exposing general-purpose function objects.
  • Apply a least-privilege model to sandboxed code: expose only minimal, well-vetted host capabilities, and avoid passing raw host objects or constructors into the sandbox.
  • Treat any bridging between sandbox and host (e.g., callback bindings, host wrappers) as a security boundary and review them for property leakage, prototype traversal, and reflective access.

Adopting these patterns helps maintain robust separation between untrusted code and the host runtime, even as the sandbox evolves.

How teams detect issues like this

Effective detection combines code-level review with automated checks:

  • Static analysis and linters: Look for sandbox frameworks or custom sandboxes that:
  • Expose host functions or constructors directly into untrusted contexts
  • Access or rely on Function.caller, arguments.callee, or similar reflective features in security-sensitive code
  • Code review signals:
  • Any use of SandboxJS (or similar) where host callbacks are bound into a script environment without strict wrapping.
  • Patterns where the sandbox relies on blacklisting specific globals instead of constructing a whitelisted execution environment.
  • Presence of internal bridge objects (e.g., LispType.Call analogs) that are not clearly isolated from user-facing functions.
  • Policy enforcement:
  • CI checks that flag uses of dangerous reflection APIs near sandbox or "untrusted code execution" modules.
  • Security review gates for any change that modifies sandbox configuration, bridging logic, or host-exposed APIs.
  • Dynamic testing:
  • Fuzzing and property-based tests that attempt to access reflective properties from within the sandbox and verify they do not leak host constructs.

Organizations may optionally use automated security scanners or SAST tools configured with custom rules targeting sandbox and reflection anti-patterns.

Sources

SourceLink
github.comgithub.com/nyariv/SandboxJS/commit/826865251232611ec94078bab5a18ec875dad4a5
github.comgithub.com/nyariv/SandboxJS/security/advisories/GHSA-g8f2-4f4f-5jqw

Frequently asked

questions

It can be, depending on how the application uses SandboxJS. If remote users can submit or edit scripts, expressions, or plugins that run inside the sandbox, then they can potentially exploit this flaw remotely to execute arbitrary host JavaScript.

The attacker needs the ability to run code inside the SandboxJS environment. This often corresponds to user-level access to a scripting feature (e.g., custom rules, formulas, or templates), not necessarily elevated or administrative access.

The safest pattern is to enforce strict separation between sandbox and host by:

  • Removing or virtualizing reflection properties like Function.caller on sandbox-defined functions.
  • Ensuring that internal callbacks and host constructors cannot be recovered from within the sandbox.
  • Treating the sandbox boundary as a strong security boundary and applying defense-in-depth measures such as whitelisting exposed APIs.

Prevention involves designing sandboxing systems with hostile input in mind:

  • Use mature, security-reviewed sandboxing primitives or external isolation (e.g., separate processes/VMs) where possible.
  • Avoid exposing raw host functions or constructors and thoroughly review any bridging layers.
  • Regularly audit sandbox code for reflective leaks, prototype access paths, and other side channels to host capabilities.
  • Integrate automated checks and security reviews into the development lifecycle for any feature that executes user-supplied code.
Find out what's already
exploitable in your codebase.