Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-10-30 - Command Injection in Syntax Checker
**Vulnerability:** Use of string-based \`execSync\` for node syntax checking (\`execSync(\\\`node --check "\${tempFile}"\\\`)\`) allows for potential command injection if \`tempFile\` path can be manipulated.
**Learning:** Even internal tool execution or paths that seem controlled should use array-based argument passing (e.g., \`spawnSync\`) and \`process.execPath\` to absolutely prevent injection vulnerabilities in execution engines.
**Prevention:** Always prefer \`spawnSync\` over \`execSync\`, use \`process.execPath\` for invoking node, and pass arguments as an array rather than constructing a command string.
10 changes: 8 additions & 2 deletions packages/core/src/reconcile.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -139,7 +139,13 @@ export function reconcile(options: ReconcileOptions): ReconcileResult {
fs.writeFileSync(tempFile, extractedCode, "utf8");

try {
execSync(`node --check "${tempFile}"`, { stdio: "pipe" });
const result = spawnSync(process.execPath, ["--check", tempFile], { stdio: "pipe" });
if (result.error) throw result.error;
if (result.status !== 0) {
const err = new Error("Syntax check failed") as Error & { stderr: Buffer };
err.stderr = result.stderr;
throw err;
}
log.audit("Syntax check passed");
} catch (err) {
const stderr =
Expand Down
Loading