@nyariv/sandboxjs(npm) — vulnerable:<= 0.8.33→ patched in0.8.34
CWE-94 — Improper Control of Generation of Code ('Code Injection')
Affected Packages
Vulnerability Analysis
The vulnerability lies in the SandboxJS execution engine, specifically in the handler for function calls made from within the sandboxed environment. The root cause was a failure to sanitize the return values of these function calls. When sandboxed code executed a native JavaScript function (e.g., Object.values(this)), the raw return value was passed back into the sandbox. The vulnerability could be triggered by calling a function that returns an array containing a reference to the host's Function constructor. With access to the Function constructor, an attacker could create and execute arbitrary code, escaping the sandbox and leading to Remote Code Execution (RCE). The patch addresses this by introducing a sanitizeArray function, which is now invoked on the return value of every function call. This new function recursively inspects arrays and replaces any references to sensitive objects like the Function constructor with their sandboxed, safe counterparts, effectively preventing the leak.
Identified Vulnerable Functions
addOps(LispType.Call handler)This anonymous handler function for LispType.Call is responsible for executing function calls originating from the sandboxed code. Prior to the patch, it would return the results of these function calls without sanitization. This allowed built-in functions like Object.values(this) to return an array containing a reference to the powerful Function constructor, which could then be used to escape the sandbox and achieve remote code execution. The patch fixes this by calling the new sanitizeArray function on the return values to replace sensitive objects like the Function constructor with their safe, sandboxed equivalents.