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
Functionconstructor 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
callerproperty 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.Callruntime callback - Invoke this callback with crafted
contextandobjarguments - Recover blocked host statics and the real
Functionconstructor - Use
Functionto 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.Callanalogs) 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.

