You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assumed repo path is /Users/zwique/Downloads/SandboxJS-0.8.34 (no /Users/zwique/Downloads/SandboxJS found). A global tick state (currentTicks.current) is shared between sandboxes. Timer string handlers are compiled at execution time using that global tick state rather than the scheduling sandbox's tick object. In multi-tenant / concurrent sandbox scenarios, another sandbox can overwrite currentTicks.current between scheduling and execution, causing the timer callback to run under a different sandbox's tick budget and bypass the original sandbox's execution quota/watchdog.
sandboxedSetTimeout compiles string handlers at execution time, not at scheduling time, which lets currentTicks.current be the wrong sandbox's ticks when compilation occurs.
Why This Is Vulnerable
currentTicks.current is global mutable state shared across all sandbox instances.
Timer string handlers are compiled at the moment the timer fires and read currentTicks.current at that time. If another sandbox runs between scheduling and execution, it can replace currentTicks.current. The scheduled timer's code will be compiled/executed with the other sandbox's tick budget. This allows the original sandbox's execution quota to be bypassed.
Proof of Concept
Run with Node.js; adjust path if needed.
// PoC (run with node); adjust path if neededimportSandboxfrom'/Users/zwique/Downloads/SandboxJS-0.8.34/node_modules/@nyariv/sandboxjs/build/Sandbox.js';constglobals={ ...Sandbox.SAFE_GLOBALS, setTimeout, clearTimeout };constprototypeWhitelist=Sandbox.SAFE_PROTOTYPES;constsandboxA=newSandbox({
globals,
prototypeWhitelist,executionQuota: 50n,haltOnSandboxError: true,});lethaltedA=false;sandboxA.subscribeHalt(()=>{haltedA=true;});constsandboxB=newSandbox({ globals, prototypeWhitelist });// Sandbox A schedules a heavy string handlersandboxA.compile('setTimeout("let x=0; for (let i=0;i<200;i++){ x += i } globalThis.doneA = true;", 0);')().run();// Run sandbox B before A's timer firessandboxB.compile('1+1')().run();setTimeout(()=>{console.log({ haltedA,doneA: sandboxA.context.sandboxGlobal.doneA});},50);
Who is impacted: Applications that run multiple SandboxJS instances concurrently in the same process — multi-tenant interpreters, plugin engines, server-side scripting hosts, online code runners.
Practical impact: Attackers controlling sandboxed code can bypass configured execution quotas/watchdog and perform CPU-intensive loops or long-running computation, enabling resource exhaustion/DoS or denial of service against the host process or other tenants.
Does not (as tested) lead to: Host object exposure or direct sandbox escape (no process / require leakage observed from this primitive alone). Escalation to RCE was attempted and not observed.
The product contains a concurrent code sequence that requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence operating concurrently.
Learn more on MITRE.
Summary
Assumed repo path is
/Users/zwique/Downloads/SandboxJS-0.8.34(no/Users/zwique/Downloads/SandboxJSfound). A global tick state (currentTicks.current) is shared between sandboxes. Timer string handlers are compiled at execution time using that global tick state rather than the scheduling sandbox's tick object. In multi-tenant / concurrent sandbox scenarios, another sandbox can overwritecurrentTicks.currentbetween scheduling and execution, causing the timer callback to run under a different sandbox's tick budget and bypass the original sandbox's execution quota/watchdog.Impact: execution quota bypass → CPU/resource abuse
Details
SandboxJS-0.8.34at/Users/zwique/Downloads/SandboxJS-0.8.34Vulnerable code paths
/src/eval.ts—sandboxFunctionbindsticksusingticks || currentTicks.current:Relevant lines: 44, 53, 164, 167.
/src/evaluator.ts//src/executor.ts— global ticks:and
Relevant lines: ~1700, 1712.
sandboxedSetTimeoutcompiles string handlers at execution time, not at scheduling time, which letscurrentTicks.currentbe the wrong sandbox's ticks when compilation occurs.Why This Is Vulnerable
currentTicks.currentis global mutable state shared across all sandbox instances.currentTicks.currentat that time. If another sandbox runs between scheduling and execution, it can replacecurrentTicks.current. The scheduled timer's code will be compiled/executed with the other sandbox's tick budget. This allows the original sandbox's execution quota to be bypassed.Proof of Concept
Reproduction Steps
Place the PoC in
hi.jsand run:Observe output similar to:
This indicates the heavy loop completed and the quota was bypassed.
Remove the
sandboxB.compile('1+1')().run();line and rerun. Output should now be:This indicates quota enforcement is working correctly.
Impact
process/requireleakage observed from this primitive alone). Escalation to RCE was attempted and not observed.