Compare commits

...
Author SHA1 Message Date
Cursor Agent 7885e2ba38 Fix: resolve shell option on Windows to support .cmd/.bat shims
On Windows, Node.js spawn with shell:false cannot execute .cmd/.bat
shims — only native .exe binaries. The previous commit forced
shell:false for gh CLI invocations to prevent command injection, but
this regressed Windows setups where gh is installed as a .cmd shim
(e.g., via Scoop or corporate package managers).

Add resolveShellOption() in processRunner.ts that, on Windows, probes
PATH for the first matching file: if it's a .cmd/.bat shim, shell:true
is used (required for cmd.exe to interpret the shim); if it's an .exe,
shell:false is preserved (preventing injection). On non-Windows
platforms, the caller's explicit value is used (defaulting to false).
2026-04-10 08:11:19 +00:00
Julius Marminge 1fd62443af Merge branch 'main' into codex/fix-github-cli-command-injection-vulnerability 2026-04-10 00:59:11 -07:00
Julius Marminge cc5871a8ba Mitigate Windows GH CLI command injection 2026-04-10 00:58:49 -07:00
2 changed files with 44 additions and 1 deletions

No files matched your search

+1
View File
@@ -168,6 +168,7 @@ const makeGitHubCli = Effect.sync(() => {
runProcess("gh", input.args, {
cwd: input.cwd,
timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
shell: false,
}),
catch: (error) => normalizeGitHubCliError("execute", error),
});
+43 -1
View File
@@ -1,4 +1,6 @@
import { type ChildProcess as ChildProcessHandle, spawn, spawnSync } from "node:child_process";
import { accessSync } from "node:fs";
import { delimiter, extname, join } from "node:path";
export interface ProcessRunOptions {
cwd?: string | undefined;
@@ -8,6 +10,7 @@ export interface ProcessRunOptions {
allowNonZeroExit?: boolean | undefined;
maxBufferBytes?: number | undefined;
outputMode?: "error" | "truncate" | undefined;
shell?: boolean | undefined;
}
export interface ProcessRunResult {
@@ -80,6 +83,45 @@ function normalizeBufferError(
const DEFAULT_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
/**
* On Windows, `.cmd` / `.bat` shims (created by npm, Scoop, etc.) can only be
* executed by `spawn` when `shell: true`. When the caller explicitly requests
* `shell: false` we still need to honour that for `.exe` binaries, but we must
* fall back to `shell: true` when the resolved command is a script shim.
*/
function resolveShellOption(command: string, explicit: boolean | undefined): boolean {
if (process.platform !== "win32") return explicit ?? false;
if (explicit === true) return true;
if (extname(command)) {
const ext = extname(command).toLowerCase();
return ext === ".cmd" || ext === ".bat";
}
const pathEnv = process.env["PATH"] ?? process.env["Path"] ?? "";
const dirs = pathEnv.split(delimiter).filter(Boolean);
for (const dir of dirs) {
for (const ext of [".cmd", ".bat"]) {
try {
accessSync(join(dir, `${command}${ext}`));
return true;
} catch {
// not found, continue
}
}
for (const ext of [".exe", ".com", ""]) {
try {
accessSync(join(dir, `${command}${ext}`));
return false;
} catch {
// not found, continue
}
}
}
return explicit ?? false;
}
/**
* On Windows with `shell: true`, `child.kill()` only terminates the `cmd.exe`
* wrapper, leaving the actual command running. Use `taskkill /T` to kill the
@@ -139,7 +181,7 @@ export async function runProcess(
cwd: options.cwd,
env: options.env,
stdio: "pipe",
shell: process.platform === "win32",
shell: resolveShellOption(command, options.shell),
});
let stdout = "";