diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 0000000..1d31cae --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2024-05-18 - [Sandbox Environment Leakage] +**Vulnerability:** The sandbox was leaking the host's environment variables (process.env) into the sandboxed child processes. +**Learning:** Node's `child_process.spawn()` and `spawnSync()` default to inheriting `process.env` when the `env` option is `undefined`. This bypasses sandbox isolation if the environment object is not explicitly provided. +**Prevention:** Always explicitly set `env: options.env ?? {}` in child process options when executing untrusted code to enforce a clean environment. diff --git a/packages/core/src/sandbox.ts b/packages/core/src/sandbox.ts index 1daaa7b..58bc9b3 100644 --- a/packages/core/src/sandbox.ts +++ b/packages/core/src/sandbox.ts @@ -42,7 +42,7 @@ export function runSandboxedNodeScript( try { const result = spawnSync(process.execPath, [scriptPath], { cwd: options.cwd, - env: options.env, + env: options.env ?? {}, encoding: "utf8", timeout: options.timeoutMs ?? DEFAULT_CPU_TIMEOUT_MS, killSignal: "SIGKILL", @@ -85,7 +85,7 @@ export function runSandboxedNodeScriptAsync( const child = spawn(process.execPath, [scriptPath], { cwd: options.cwd, - env: options.env, + env: options.env ?? {}, stdio: ["ignore", "pipe", "pipe"], });