Skip to content

Commit 4b1b228

Browse files
committed
addressing codex review
1 parent 4718f44 commit 4b1b228

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/node-host/invoke-system-run-allowlist.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ export function resolveSystemRunExecArgv(params: {
155155
params.shellCommand &&
156156
params.policy.analysisOk &&
157157
params.policy.allowlistSatisfied &&
158-
params.segmentSatisfiedBy.some((entry) => entry === "safeBins" || entry === "inlineChain")
158+
params.segmentSatisfiedBy.some((entry) => entry === "safeBins" || entry === "inlineChain") &&
159+
isPosixShellInlineCommandTransport(params.argv)
159160
) {
160161
const rebuilt = buildSafeBinsShellCommand({
161162
command: params.shellCommand,
@@ -181,6 +182,14 @@ export function resolveSystemRunExecArgv(params: {
181182
return execArgv;
182183
}
183184

185+
function isPosixShellInlineCommandTransport(argv: string[]): boolean {
186+
const transportArgv = resolveShellWrapperTransportArgv(argv);
187+
return Boolean(
188+
transportArgv &&
189+
POSIX_SHELL_WRAPPER_NAMES.has(normalizeExecutableToken(transportArgv[0] ?? "")),
190+
);
191+
}
192+
184193
function findSubsequence(haystack: readonly string[], needle: readonly string[]): number {
185194
if (needle.length === 0 || needle.length > haystack.length) {
186195
return -1;

src/node-host/invoke-system-run.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,31 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
834834
},
835835
);
836836

837+
it.runIf(process.platform !== "win32")(
838+
"does not apply POSIX safe-bin shell rewrites to PowerShell wrappers",
839+
async () => {
840+
const oldPath = process.env.PATH;
841+
process.env.PATH = "/usr/bin:/bin";
842+
try {
843+
const { runCommand, sendInvokeResult } = await runSystemInvoke({
844+
preferMacAppExecHost: false,
845+
security: "allowlist",
846+
ask: "off",
847+
command: ["pwsh", "-Command", "head -c 16"],
848+
});
849+
850+
expect(requireFirstRunCommandArgs(runCommand)).toEqual(["pwsh", "-Command", "head -c 16"]);
851+
expectInvokeOk(sendInvokeResult);
852+
} finally {
853+
if (oldPath === undefined) {
854+
delete process.env.PATH;
855+
} else {
856+
process.env.PATH = oldPath;
857+
}
858+
}
859+
},
860+
);
861+
837862
it("denies abbreviated PowerShell encoded payloads even when the wrapper is allowlisted", async () => {
838863
const binDir = createFixtureDir("openclaw-pwsh-allowlist-");
839864
const executablePath = createTempExecutable({ dir: binDir, name: "pwsh" });

0 commit comments

Comments
 (0)