Executive brief
SandboxJS is a JavaScript sandbox library that restricts untrusted code execution by intercepting object construction and function calls. A vulnerability in versions 0.8.35 and below allows sandboxed code to leak internal interpreter objects and access the host's global scope, potentially enabling modification of sandbox scope variables. While code evaluation remains isolated, this breaks the security boundary that prevents sandboxed code from accessing protected objects like the real Function constructor and eval.
Technical details
The vulnerability is a scope modification flaw in the new operator handler (src/executor.ts lines 1275–1280) that fails to sanitize constructor arguments and return values. The handler passes raw Prop objects (internal wrappers containing references to scope.allVars) directly to constructors without calling valueOrProp(), and returns constructed objects without sanitization via getGlobalProp() or sanitizeArray(). When sandboxed code executes `new Constructor(someVariable)`, a malicious constructor can access the Prop's `context` field, obtaining a direct reference to scope.allVars (which contains the real host globalThis, Function, eval, and other globals). The attack requires only that the host application runs sandboxed code and reads its return value, with no authentication or user interaction needed. A fix is available in version 0.8.36 that adds proper argument and return value sanitization matching the Call handler's implementation.
Affected products
- nyariv SandboxJS 0.8.35 and below
Timeline
- 2026-04-03: disclosed
- 2026-04-03: patched: Version 0.8.36 patches the vulnerability