From e36ea531d389c0bde79a09d0e6eaebceeba4a380 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 16:03:47 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A1=EF=B8=8F=20Sentinel:=20[CRITICAL]?= =?UTF-8?q?=20Fix=20command=20injection=20in=20reconcile=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaces `execSync` with `spawnSync` array argument list and `process.execPath` in `packages/core/src/reconcile.ts` to prevent command injection from user-controlled paths. - Records critical learning in `.jules/sentinel.md` regarding `execSync` dangers. Co-authored-by: connerkup <72580335+connerkup@users.noreply.github.com> --- .jules/sentinel.md | 4 ++++ packages/core/src/reconcile.ts | 16 +++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 .jules/sentinel.md diff --git a/.jules/sentinel.md b/.jules/sentinel.md new file mode 100644 index 0000000..ed0e8c6 --- /dev/null +++ b/.jules/sentinel.md @@ -0,0 +1,4 @@ +## 2025-02-09 - Avoid execSync for paths controlled by workspace inputs +**Vulnerability:** Command injection vulnerability via `execSync` when executing dynamically generated workspace files. The `tempFile` was generated dynamically in `.shieldedshell/state/temp_check.js` which depended on `options.workspace`, allowing command injection. +**Learning:** `execSync` runs in a shell by default or executes a string as a command, opening the possibility for command injection even for paths that look safe but are controlled by external inputs or environment locations. +**Prevention:** Use `spawnSync` from `node:child_process` with an array-based argument list and `process.execPath` to launch node, removing the shell execution risk. diff --git a/packages/core/src/reconcile.ts b/packages/core/src/reconcile.ts index b0285bc..1c00261 100644 --- a/packages/core/src/reconcile.ts +++ b/packages/core/src/reconcile.ts @@ -1,4 +1,4 @@ -import { execSync } from "node:child_process"; +import { spawnSync } from "node:child_process"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; @@ -138,20 +138,14 @@ export function reconcile(options: ReconcileOptions): ReconcileResult { fs.mkdirSync(path.dirname(tempFile), { recursive: true }); fs.writeFileSync(tempFile, extractedCode, "utf8"); - try { - execSync(`node --check "${tempFile}"`, { stdio: "pipe" }); - log.audit("Syntax check passed"); - } catch (err) { - const stderr = - err && typeof err === "object" && "stderr" in err - ? String((err as { stderr?: Buffer }).stderr ?? "") - : err instanceof Error - ? err.message - : String(err); + const check = spawnSync(process.execPath, ["--check", tempFile], { stdio: "pipe", encoding: "utf8" }); + if (check.status !== 0) { + const stderr = check.stderr || (check.error ? check.error.message : "Unknown syntax error"); consolidateSharedContext(sharedContext, `Syntax Error:\n${stderr}`); if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile); return { success: false, reason: "Syntax check failed" }; } + log.audit("Syntax check passed"); if (options.benchmark) { const staticResult = runBenchmarkStaticVerification(options.workspace, options.benchmark);