From 67f0410e1c0881bbee7416ff312014e9d9ae13d3 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Sun, 22 Feb 2026 21:35:13 +0530 Subject: [PATCH] fix(executor): restore shell feature support in shellExecutor The previous security hardening replaced execSync with execFileSync, which broke commands using pipes, redirects, and subshells. Now detects shell metacharacters and falls back to sh -c for those commands while keeping execFileSync for simple commands. --- packages/core/src/plan/executor.ts | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/core/src/plan/executor.ts b/packages/core/src/plan/executor.ts index 19aabe81..84147e3f 100644 --- a/packages/core/src/plan/executor.ts +++ b/packages/core/src/plan/executor.ts @@ -494,6 +494,11 @@ export const dryRunExecutor: StepExecutor = async (step, task, _plan) => { /** * Shell step executor (runs commands) + * + * Uses execFileSync for simple commands (no shell metacharacters) to prevent + * injection. Falls back to sh -c for commands that require shell features + * like pipes, redirects, or subshells — these come from plan configs, + * not user input. */ export const shellExecutor: StepExecutor = async (step, _task, _plan) => { if (!step.command) { @@ -501,17 +506,26 @@ export const shellExecutor: StepExecutor = async (step, _task, _plan) => { } try { - const parts = splitCommand(step.command); - if (parts.length === 0) { - return { success: false, output: "", error: "Empty command" }; + const needsShell = /[|><;`$(){}]/.test(step.command); + let output: string; + + if (needsShell) { + output = execFileSync("sh", ["-c", step.command], { + encoding: "utf-8", + timeout: 60000, + }); + } else { + const parts = splitCommand(step.command); + if (parts.length === 0) { + return { success: false, output: "", error: "Empty command" }; + } + const [cmd, ...args] = parts; + output = execFileSync(cmd, args, { + encoding: "utf-8", + timeout: 60000, + }); } - const [cmd, ...args] = parts; - const output = execFileSync(cmd, args, { - encoding: "utf-8", - timeout: 60000, - }); - // Check expected output if provided if (step.expectedOutput && !output.includes(step.expectedOutput)) { return { success: false,