Security: use execFileSync instead of execSync with shell strings (#20655)
Replace execSync (which spawns a shell) with execFileSync (which invokes the binary directly with an argv array). This eliminates command injection risk from interpolated arguments. Co-authored-by: sirishacyd <sirishacyd@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -148,10 +148,10 @@ async function resolveNodePath(): Promise<string> {
|
||||
}
|
||||
|
||||
async function resolveBinaryPath(binary: string): Promise<string> {
|
||||
const { execSync } = await import("node:child_process");
|
||||
const { execFileSync } = await import("node:child_process");
|
||||
const cmd = process.platform === "win32" ? "where" : "which";
|
||||
try {
|
||||
const output = execSync(`${cmd} ${binary}`, { encoding: "utf8" }).trim();
|
||||
const output = execFileSync(cmd, [binary], { encoding: "utf8" }).trim();
|
||||
const resolved = output.split(/\r?\n/)[0]?.trim();
|
||||
if (!resolved) {
|
||||
throw new Error("empty");
|
||||
|
||||
Reference in New Issue
Block a user