Skip to content

Commit 4a846dd

Browse files
committed
fix(exec): honor yolo host exec semantics
1 parent 6ce17db commit 4a846dd

5 files changed

Lines changed: 86 additions & 26 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Docs: https://docs.openclaw.ai
1919

2020
### Fixes
2121

22+
- Exec/YOLO: stop rejecting gateway-host exec in `security=full` plus `ask=off` mode via the Python/Node script preflight hardening path, so promptless YOLO exec once again runs direct interpreter stdin and heredoc forms such as `node <<'NODE' ... NODE`.
2223
- fix(qqbot): add SSRF guard to direct-upload URL paths in uploadC2CMedia and uploadGroupMedia [AI-assisted]. (#69595) Thanks @pgondhi987.
2324
- fix(gateway): enforce allowRequestSessionKey gate on template-rendered mapping sessionKeys. (#69381) Thanks @pgondhi987.
2425
- Webchat/images: treat inline image attachments as media for empty-turn gating while still ignoring metadata-only blank turns. (#69474) Thanks @Jaswir.

‎docs/tools/exec-approvals.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Important distinction:
118118

119119
- `tools.exec.host=auto` chooses where exec runs: sandbox when available, otherwise gateway.
120120
- YOLO chooses how host exec is approved: `security=full` plus `ask=off`.
121-
- In YOLO mode, OpenClaw does not add a separate heuristic command-obfuscation approval gate on top of the configured host exec policy.
121+
- In YOLO mode, OpenClaw does not add a separate heuristic command-obfuscation approval gate or script-preflight rejection layer on top of the configured host exec policy.
122122
- `auto` does not make gateway routing a free override from a sandboxed session. A per-call `host=node` request is allowed from `auto`, and `host=gateway` is only allowed from `auto` when no sandbox runtime is active. If you want a stable non-auto default, set `tools.exec.host` or use `/exec host=...` explicitly.
123123

124124
If you want a more conservative setup, tighten either layer back to `allowlist` / `on-miss`

‎docs/tools/exec.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Notes:
6666
- `tools.exec.ask` (default: `off`)
6767
- No-approval host exec is the default for gateway + node. If you want approvals/allowlist behavior, tighten both `tools.exec.*` and the host `~/.openclaw/exec-approvals.json`; see [Exec approvals](/tools/exec-approvals#no-approval-yolo-mode).
6868
- YOLO comes from the host-policy defaults (`security=full`, `ask=off`), not from `host=auto`. If you want to force gateway or node routing, set `tools.exec.host` or use `/exec host=...`.
69-
- In `security=full` plus `ask=off` mode, host exec follows the configured policy directly; there is no extra heuristic command-obfuscation prefilter.
69+
- In `security=full` plus `ask=off` mode, host exec follows the configured policy directly; there is no extra heuristic command-obfuscation prefilter or script-preflight rejection layer.
7070
- `tools.exec.node` (default: unset)
7171
- `tools.exec.strictInlineEval` (default: false): when true, inline interpreter eval forms such as `python -c`, `node -e`, `ruby -e`, `perl -e`, `php -r`, `lua -e`, and `osascript -e` always require explicit approval. `allow-always` can still persist benign interpreter/script invocations, but inline-eval forms still prompt each time.
7272
- `tools.exec.pathPrepend`: list of directories to prepend to `PATH` for exec runs (gateway + sandbox only).

‎src/agents/bash-tools.exec.script-preflight.test.ts‎

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const isWin = process.platform === "win32";
1111
const describeNonWin = isWin ? describe.skip : describe;
1212
const describeWin = isWin ? describe : describe.skip;
1313
const validateExecScriptPreflight = __testing.validateScriptFileForShellBleed;
14+
const createPreflightTool = () =>
15+
createExecTool({ host: "gateway", security: "full", ask: "on-miss" });
1416

1517
afterEach(() => {
1618
__setFsSafeTestHooksForTest();
@@ -66,7 +68,7 @@ describeNonWin("exec script preflight", () => {
6668
"utf-8",
6769
);
6870

69-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
71+
const tool = createPreflightTool();
7072

7173
await expect(
7274
tool.execute("call1", {
@@ -87,7 +89,7 @@ describeNonWin("exec script preflight", () => {
8789
"utf-8",
8890
);
8991

90-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
92+
const tool = createPreflightTool();
9193

9294
await expect(
9395
tool.execute("call1", {
@@ -105,7 +107,7 @@ describeNonWin("exec script preflight", () => {
105107
const jsPath = path.join(tmp, "bad.js");
106108
await fs.writeFile(jsPath, "const value = $DM_JSON;", "utf-8");
107109

108-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
110+
const tool = createPreflightTool();
109111
await expect(
110112
tool.execute("call-quoted", {
111113
command: 'node "bad.js"',
@@ -120,7 +122,7 @@ describeNonWin("exec script preflight", () => {
120122
const jsPath = path.join(tmp, "..bad.js");
121123
await fs.writeFile(jsPath, "const value = $DM_JSON;", "utf-8");
122124

123-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
125+
const tool = createPreflightTool();
124126
await expect(
125127
tool.execute("call-dotdot-prefix-script", {
126128
command: "node ..bad.js",
@@ -137,7 +139,7 @@ describeNonWin("exec script preflight", () => {
137139
await fs.writeFile(targetPath, "const value = $DM_JSON;", "utf-8");
138140
await fs.symlink(targetPath, linkPath);
139141

140-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
142+
const tool = createPreflightTool();
141143
await expect(
142144
tool.execute("call-symlink-entrypoint", {
143145
command: "node link.js",
@@ -153,7 +155,7 @@ describeNonWin("exec script preflight", () => {
153155
await fs.mkdir(literalTildeDir, { recursive: true });
154156
await fs.writeFile(path.join(literalTildeDir, "bad.js"), "const value = $DM_JSON;", "utf-8");
155157

156-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
158+
const tool = createPreflightTool();
157159
await expect(
158160
tool.execute("call-literal-tilde-path", {
159161
command: 'node "~/bad.js"',
@@ -168,7 +170,7 @@ describeNonWin("exec script preflight", () => {
168170
const pyPath = path.join(tmp, "bad.py");
169171
await fs.writeFile(pyPath, "payload = $DM_JSON", "utf-8");
170172

171-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
173+
const tool = createPreflightTool();
172174
await expect(
173175
tool.execute("call-env-python", {
174176
command: "env python bad.py",
@@ -183,7 +185,7 @@ describeNonWin("exec script preflight", () => {
183185
const pyPath = path.join(tmp, "bad.py");
184186
await fs.writeFile(pyPath, "payload = $DM_JSON", "utf-8");
185187

186-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
188+
const tool = createPreflightTool();
187189
await expect(
188190
tool.execute("call-abs-env-python", {
189191
command: "/usr/bin/env python bad.py",
@@ -198,7 +200,7 @@ describeNonWin("exec script preflight", () => {
198200
const jsPath = path.join(tmp, "bad.js");
199201
await fs.writeFile(jsPath, "const value = $DM_JSON;", "utf-8");
200202

201-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
203+
const tool = createPreflightTool();
202204
await expect(
203205
tool.execute("call-env-node", {
204206
command: "env node bad.js",
@@ -213,7 +215,7 @@ describeNonWin("exec script preflight", () => {
213215
await fs.writeFile(path.join(tmp, "bad.py"), "payload = $DM_JSON", "utf-8");
214216
await fs.writeFile(path.join(tmp, "ghost.py"), "print('ok')", "utf-8");
215217

216-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
218+
const tool = createPreflightTool();
217219
await expect(
218220
tool.execute("call-python-first-script", {
219221
command: "python bad.py ghost.py",
@@ -228,7 +230,7 @@ describeNonWin("exec script preflight", () => {
228230
await fs.writeFile(path.join(tmp, "script.py"), "payload = $DM_JSON", "utf-8");
229231
await fs.writeFile(path.join(tmp, "out.py"), "print('ok')", "utf-8");
230232

231-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
233+
const tool = createPreflightTool();
232234
await expect(
233235
tool.execute("call-python-trailing-option-value", {
234236
command: "python script.py --output out.py",
@@ -243,7 +245,7 @@ describeNonWin("exec script preflight", () => {
243245
await fs.writeFile(path.join(tmp, "app.js"), "const value = $DM_JSON;", "utf-8");
244246
await fs.writeFile(path.join(tmp, "config.js"), "console.log('ok')", "utf-8");
245247

246-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
248+
const tool = createPreflightTool();
247249
await expect(
248250
tool.execute("call-node-first-script", {
249251
command: "node app.js config.js",
@@ -258,7 +260,7 @@ describeNonWin("exec script preflight", () => {
258260
await fs.writeFile(path.join(tmp, "bootstrap.js"), "console.log('bootstrap')", "utf-8");
259261
await fs.writeFile(path.join(tmp, "app.js"), "const value = $DM_JSON;", "utf-8");
260262

261-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
263+
const tool = createPreflightTool();
262264
await expect(
263265
tool.execute("call-node-require-script", {
264266
command: "node --require bootstrap.js app.js",
@@ -273,7 +275,7 @@ describeNonWin("exec script preflight", () => {
273275
await fs.writeFile(path.join(tmp, "bad-preload.js"), "const value = $DM_JSON;", "utf-8");
274276
await fs.writeFile(path.join(tmp, "app.js"), "console.log('ok')", "utf-8");
275277

276-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
278+
const tool = createPreflightTool();
277279
await expect(
278280
tool.execute("call-node-preload-before-entry", {
279281
command: "node --require bad-preload.js app.js",
@@ -287,7 +289,7 @@ describeNonWin("exec script preflight", () => {
287289
await withTempDir("openclaw-exec-preflight-", async (tmp) => {
288290
await fs.writeFile(path.join(tmp, "bad.js"), "const value = $DM_JSON;", "utf-8");
289291

290-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
292+
const tool = createPreflightTool();
291293
await expect(
292294
tool.execute("call-node-require-only", {
293295
command: "node --require bad.js",
@@ -301,7 +303,7 @@ describeNonWin("exec script preflight", () => {
301303
await withTempDir("openclaw-exec-preflight-", async (tmp) => {
302304
await fs.writeFile(path.join(tmp, "bad.js"), "const value = $DM_JSON;", "utf-8");
303305

304-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
306+
const tool = createPreflightTool();
305307
await expect(
306308
tool.execute("call-node-import-only", {
307309
command: "node --import bad.js",
@@ -315,7 +317,7 @@ describeNonWin("exec script preflight", () => {
315317
await withTempDir("openclaw-exec-preflight-", async (tmp) => {
316318
await fs.writeFile(path.join(tmp, "bad.js"), "const value = $DM_JSON;", "utf-8");
317319

318-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
320+
const tool = createPreflightTool();
319321
await expect(
320322
tool.execute("call-node-require-with-eval", {
321323
command: 'node --require bad.js -e "console.log(123)"',
@@ -329,7 +331,7 @@ describeNonWin("exec script preflight", () => {
329331
await withTempDir("openclaw-exec-preflight-", async (tmp) => {
330332
await fs.writeFile(path.join(tmp, "bad.js"), "const value = $DM_JSON;", "utf-8");
331333

332-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
334+
const tool = createPreflightTool();
333335
await expect(
334336
tool.execute("call-node-import-with-eval", {
335337
command: 'node --import bad.js -e "console.log(123)"',
@@ -339,6 +341,46 @@ describeNonWin("exec script preflight", () => {
339341
});
340342
});
341343

344+
it("skips script-file preflight in yolo host mode", async () => {
345+
await withTempDir("openclaw-exec-preflight-", async (tmp) => {
346+
const jsPath = path.join(tmp, "bad.js");
347+
await fs.writeFile(jsPath, "const value = $DM_JSON;", "utf-8");
348+
349+
const tool = createExecTool({
350+
host: "gateway",
351+
security: "full",
352+
ask: "off",
353+
allowBackground: false,
354+
});
355+
const result = await tool.execute("call-yolo-bad-js", {
356+
command: "node bad.js",
357+
workdir: tmp,
358+
});
359+
const text = result.content.find((c) => c.type === "text")?.text ?? "";
360+
361+
expect(text).not.toMatch(/exec preflight:/);
362+
expect(result.details).toMatchObject({
363+
status: expect.stringMatching(/completed|failed/),
364+
});
365+
});
366+
});
367+
368+
it("runs heredoc-backed node commands in yolo host mode", async () => {
369+
const tool = createExecTool({
370+
host: "gateway",
371+
security: "full",
372+
ask: "off",
373+
allowBackground: false,
374+
});
375+
const result = await tool.execute("call-yolo-heredoc", {
376+
command: "node <<'NODE'\nprocess.stdout.write('ok')\nNODE",
377+
});
378+
const text = result.content.find((c) => c.type === "text")?.text?.trim();
379+
380+
expect(result.details).toMatchObject({ status: "completed" });
381+
expect(text).toBe("ok");
382+
});
383+
342384
it("skips preflight file reads for script paths outside the workdir", async () => {
343385
await withTempDir("openclaw-exec-preflight-parent-", async (parent) => {
344386
const outsidePath = path.join(parent, "outside.js");
@@ -459,7 +501,7 @@ describeWin("exec script preflight on windows path syntax", () => {
459501
await withTempDir("openclaw-exec-preflight-win-", async (tmp) => {
460502
await fs.writeFile(path.join(tmp, "bad.py"), "payload = $DM_JSON", "utf-8");
461503

462-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
504+
const tool = createPreflightTool();
463505
await expect(
464506
tool.execute("call-win-python-relative", {
465507
command: "python .\\bad.py",
@@ -473,7 +515,7 @@ describeWin("exec script preflight on windows path syntax", () => {
473515
await withTempDir("openclaw-exec-preflight-win-", async (tmp) => {
474516
await fs.writeFile(path.join(tmp, "bad.js"), "const value = $DM_JSON;", "utf-8");
475517

476-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
518+
const tool = createPreflightTool();
477519
await expect(
478520
tool.execute("call-win-node-relative", {
479521
command: "node .\\bad.js",
@@ -489,7 +531,7 @@ describeWin("exec script preflight on windows path syntax", () => {
489531
await fs.writeFile(absPath, "payload = $DM_JSON", "utf-8");
490532
const winAbsPath = absPath.replaceAll("/", "\\");
491533

492-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
534+
const tool = createPreflightTool();
493535
await expect(
494536
tool.execute("call-win-python-absolute", {
495537
command: `python "${winAbsPath}"`,
@@ -504,7 +546,7 @@ describeWin("exec script preflight on windows path syntax", () => {
504546
await fs.mkdir(path.join(tmp, "subdir"), { recursive: true });
505547
await fs.writeFile(path.join(tmp, "subdir", "bad.py"), "payload = $DM_JSON", "utf-8");
506548

507-
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
549+
const tool = createPreflightTool();
508550
await expect(
509551
tool.execute("call-win-python-subdir-relative", {
510552
command: "python subdir\\bad.py",

‎src/agents/bash-tools.exec.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import path from "node:path";
22
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
33
import { analyzeShellCommand } from "../infra/exec-approvals-analysis.js";
4-
import { type ExecHost, loadExecApprovals, maxAsk, minSecurity } from "../infra/exec-approvals.js";
4+
import {
5+
type ExecAsk,
6+
type ExecHost,
7+
type ExecSecurity,
8+
loadExecApprovals,
9+
maxAsk,
10+
minSecurity,
11+
} from "../infra/exec-approvals.js";
512
import { resolveExecSafeBinRuntimePolicy } from "../infra/exec-safe-bin-runtime-policy.js";
613
import { sanitizeHostExecEnvWithDiagnostics } from "../infra/host-env-security.js";
714
import {
@@ -1036,6 +1043,14 @@ async function validateScriptFileForShellBleed(params: {
10361043
}
10371044
}
10381045

1046+
function shouldSkipExecScriptPreflight(params: {
1047+
host: ExecHost;
1048+
security: ExecSecurity;
1049+
ask: ExecAsk;
1050+
}): boolean {
1051+
return params.host === "gateway" && params.security === "full" && params.ask === "off";
1052+
}
1053+
10391054
type ParsedExecApprovalCommand = {
10401055
approvalId: string;
10411056
decision: "allow-once" | "allow-always" | "deny";
@@ -1670,7 +1685,9 @@ export function createExecTool(
16701685

16711686
// Preflight: catch a common model failure mode (shell syntax leaking into Python/JS sources)
16721687
// before we execute and burn tokens in cron loops.
1673-
await validateScriptFileForShellBleed({ command: params.command, workdir });
1688+
if (!shouldSkipExecScriptPreflight({ host, security, ask })) {
1689+
await validateScriptFileForShellBleed({ command: params.command, workdir });
1690+
}
16741691

16751692
const run = await runExecProcess({
16761693
command: params.command,

0 commit comments

Comments
 (0)