Files
openclaw/src/infra/node-shell.ts
Peter Steinberger 6e81c548fc fix: bind macOS node allowlist commands safely (#104337)
* fix: bind macOS node allowlist commands safely

* chore: leave node fix notes in PR
2026-07-11 02:27:59 -07:00

19 lines
924 B
TypeScript

// Builds platform shell argv for Node-driven command execution.
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
// Node shell command construction keeps platform shell flags centralized for
// system.run and related command execution paths.
/** Build argv for running a command through the platform default shell. */
export function buildNodeShellCommand(command: string, platform?: string | null) {
const normalized = normalizeLowercaseStringOrEmpty((platform ?? "").trim());
if (normalized.startsWith("win")) {
return ["cmd.exe", "/d", "/s", "/c", command];
}
if (normalized === "darwin" || normalized.startsWith("macos")) {
// The Mac node binds static allowlisted commands through non-login sh.
// A login shell can execute unapproved startup files before the payload.
return ["/bin/sh", "-c", command];
}
return ["/bin/sh", "-lc", command];
}