Skip to content

fix(agents): block message sends through exec - #76423

Closed
rubencu wants to merge 2 commits into
openclaw:mainfrom
rubencu:codex/auto-reply-cli-send
Closed

rubencu wants to merge 2 commits into
openclaw:mainfrom
rubencu:codex/auto-reply-cli-send

Conversation

@rubencu

@rubencu rubencu commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Agent exec could run openclaw message ... delivery commands and send a real provider message outside the tracked reply/message-tool path; the observed duplicate was WhatsApp, but the bug was generic to message delivery commands.
  • Why it matters: Auto-reply sessions can otherwise produce one normal agent reply plus a second untracked chat/status message.
  • What changed: exec now rejects OpenClaw message delivery commands across direct CLI, package-runner, shell-wrapper, heredoc/here-string, and shell-script forms, while preserving non-delivery commands like help, dry-run, read, search, and thread list.
  • What did NOT change (scope boundary): This does not change the message tool, normal chat replies, channel transports, or message CLI behavior outside exec.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: exec classified interactive approval/channel-login commands as unsafe, but did not classify OpenClaw message CLI delivery as unsafe even though it can deliver provider messages outside the current reply path.
  • Missing detection / guardrail: The guard did not inspect delivery commands hidden behind package runners, shell wrappers, shell stdin, or shell script files.
  • Contributing context (if known): The reported WhatsApp duplicate came from an agent sending through the CLI and then reporting that it had sent the answer.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/bash-tools.exec.script-preflight.test.ts
  • Scenario the test should lock in: exec rejects message delivery commands across direct, wrapped, package-runner, heredoc/here-string, shell script, sourced script, chained script, outside-workdir readable script, and full gateway exec modes.
  • Why this is the smallest reliable guardrail: The bug is in the exec command/preflight boundary, so focused parser/preflight tests cover the delivery bypass without needing live channel sends.
  • Existing test that already covers this (if any): Existing login/approval exec guard tests covered adjacent unsafe command blocking, not message delivery.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

exec now refuses OpenClaw message delivery commands. Agents should reply normally in the current conversation or use the message tool for explicit cross-channel sends.

Diagram (if applicable)

Before:
agent exec -> openclaw message send -> provider delivery outside tracked reply path -> duplicate/status reply risk

After:
agent exec -> OpenClaw message delivery guard -> rejected with guidance to reply normally or use message tool

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) Yes
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: The exec surface is narrowed for OpenClaw message delivery commands so provider sends stay on tracked reply/message-tool paths.

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 22+ repo runtime
  • Model/provider: N/A
  • Integration/channel (if any): WhatsApp symptom, generic message CLI surface
  • Relevant config (redacted): N/A

Steps

  1. Ask an agent with exec to send a response via openclaw message send.
  2. Hide the same send behind a package runner, shell wrapper, heredoc/here-string, or shell script.
  3. Run the focused exec preflight tests.

Expected

  • exec rejects real message delivery commands and instructs the agent to reply normally or use the message tool.
  • Help, dry-run, read, search, and list forms remain allowed.

Actual

  • Before this change, those commands could reach provider delivery from exec.
  • After this change, the focused tests reject the delivery forms and preserve non-delivery forms.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Validation:

  • pnpm exec oxfmt --check --threads=1 src/agents/bash-tools.exec.ts src/agents/bash-tools.exec.script-preflight.test.ts docs/tools/exec.md CHANGELOG.md
  • git diff --check
  • pnpm test src/agents/bash-tools.exec.script-preflight.test.ts
  • pnpm tsgo:core
  • pnpm changed:lanes --json
  • codex review --base origin/main clean
  • Broad validation: GitHub PR CI.

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Direct CLI sends, package-runner forms, shell wrappers, shell stdin heredocs/here-strings, shell script files, sourced scripts, chained scripts, outside-workdir readable scripts, full gateway exec mode, and dry-run/help/read/search non-delivery cases through targeted tests.
  • Edge cases checked: env -S, sudo, npm/pnpm/yarn/bun/npx/pnpx/corepack, line continuations, command/process substitutions, grouping, root options, and readable external shell scripts.
  • What you did not verify: User manual verification: owner performs final manual verification outside this agent run.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A.

Risks and Mitigations

  • Risk: The parser may miss an obscure shell form.
    • Mitigation: Coverage includes direct CLI, package runners, shell wrappers, command substitution, process substitution, heredocs, here-strings, sourced scripts, direct/chained scripts, and local Codex review iterations against bypass cases.

Real behavior proof

  • Behavior or issue addressed: Agent exec now refuses OpenClaw message delivery commands, including direct CLI, package-runner, shell-wrapper, generated shell, heredoc, here-string, and script-file variants.
  • Real environment tested: macOS local OpenClaw source worktree, Node 22, pnpm, after rebasing the PR branch onto current origin/main.
  • Exact steps or command run after this patch: Ran pnpm test src/agents/bash-tools.exec.script-preflight.test.ts src/agents/bash-tools.exec.path.test.ts src/agents/bash-tools.exec-host-gateway.test.ts in the local OpenClaw checkout.
  • Evidence after fix: Terminal output from the local source checkout: Test Files 3 passed; 131 passed, 4 skipped, total 135 tests in the exec preflight/path/gateway group.
  • Observed result after fix: The exec preflight rejects OpenClaw message delivery attempts across the covered direct, wrapped, generated, and file-backed command forms while preserving non-delivery command paths.
  • What was not tested: No additional gaps.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR adds exec preflight parsing, tests, docs, and a changelog entry to reject OpenClaw message delivery commands from agent exec while preserving non-delivery message commands.

Reproducibility: yes. Source inspection shows current main lets openclaw message send reach the message CLI delivery path from exec, and PR head still lets a direct ./send.v1 shell script skip shell-file inspection.

Real behavior proof
Needs real behavior proof before merge: The PR body includes copied terminal output from targeted tests, but no after-fix real exec or provider behavior evidence outside tests.

Next step before merge
A narrow parser repair is clear, but this external PR also needs contributor or maintainer real behavior proof and a rebase before it can be merge-ready.

Security
Needs attention: The patch narrows exec overall, but still leaves a concrete message-delivery bypass for dotted direct shell scripts.

Review findings

  • [P2] Inspect dotted direct shell scripts — src/agents/bash-tools.exec.ts:543-546
Review details

Best possible solution:

Keep the exec preflight boundary, inspect direct path-like shell script targets regardless of arbitrary dotted names or by shebang, add focused regression coverage, rebase, and rerun targeted exec checks with real behavior proof.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows current main lets openclaw message send reach the message CLI delivery path from exec, and PR head still lets a direct ./send.v1 shell script skip shell-file inspection.

Is this the best way to solve the issue?

No. The exec preflight boundary is the right approach, but this implementation remains incomplete until dotted path-like direct shell scripts are inspected before execution.

Full review comments:

  • [P2] Inspect dotted direct shell scripts — src/agents/bash-tools.exec.ts:543-546
    The direct-script guard only inspects commands with a known shell suffix or path-like names with no dot. An executable ./send.v1 with a shell shebang skips validateScriptFileForShellBleed, so an openclaw message send inside can still reach exec; treat path-like direct script targets as inspectable regardless of suffix or check the shebang first.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.87

Security concerns:

  • [medium] Dotted shell scripts bypass the message guard — src/agents/bash-tools.exec.ts:543
    Because direct script detection only accepts a shell suffix or path-like names without dots, ./send.v1 with a shell shebang can still run OpenClaw message delivery through exec without file preflight inspection.
    Confidence: 0.87

Acceptance criteria:

  • pnpm exec oxfmt --check --threads=1 src/agents/bash-tools.exec.ts src/agents/bash-tools.exec.script-preflight.test.ts docs/tools/exec.md CHANGELOG.md
  • git diff --check
  • pnpm test src/agents/bash-tools.exec.script-preflight.test.ts src/agents/bash-tools.exec.path.test.ts src/agents/bash-tools.exec-host-gateway.test.ts
  • pnpm tsgo:core

What I checked:

Likely related people:

  • steipete: GitHub commit metadata shows repeated recent work touching src/agents/bash-tools.exec.ts, exec docs/tests, and message CLI helper behavior in the affected area. (role: recent exec and message CLI maintainer; confidence: high; commits: 59fb9e5ca7fe, 738f5f7508ae, 4a846dd129b1; files: src/agents/bash-tools.exec.ts, src/agents/bash-tools.exec.script-preflight.test.ts, src/cli/program/message/helpers.ts)
  • pgondhi987: History ties this boundary to earlier fail-open and TOCTOU hardening in the same script preflight files. (role: exec script-preflight security contributor; confidence: high; commits: b024fae9e5df, 8aceaf5d0f0e; files: src/agents/bash-tools.exec.ts, src/agents/bash-tools.exec.script-preflight.test.ts, src/infra/fs-safe.ts)
  • vincentkoc: Recent history includes exec preflight test maintenance, and this PR's follow-up commit addressed the first direct-script detection gap. (role: recent adjacent exec test maintainer and PR follow-up owner; confidence: medium; commits: d0f090e188df, d46f68489834, 9eb9cbb82e07; files: src/agents/bash-tools.exec.ts, src/agents/bash-tools.exec.script-preflight.test.ts)

Remaining risk / open question:

  • The PR head is merge-conflicted with the base branch, so the final landing diff needs rebase proof.
  • The PR body provides targeted test output, but not after-fix real exec/provider behavior proof outside tests.

Codex review notes: model gpt-5.5, reasoning high; reviewed against d94e7f5114dc.

@rubencu
rubencu force-pushed the codex/auto-reply-cli-send branch from 3ce98f9 to a4c2e09 Compare May 3, 2026 03:48
@rubencu

rubencu commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

this is for maintainers only!

@rubencu

rubencu commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

this is for maintainers only!

@vincentkoc noted. This is what happened - maybe the clawsweeper skill could be more explicit about not re-triggering for non maintainers

Screenshot 2026-05-03 at 6 41 09 AM

@rubencu

rubencu commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing this instead of continuing the current implementation.

The underlying bug is real: agent exec should not be able to produce an extra provider message by running openclaw message send outside the tracked reply/message-tool path. But the current PR shape has drifted into static shell/script analysis. The follow-up review cycle kept finding more shell forms, generated-script cases, env wrappers, and interpreter variants, which is a sign that this approach is becoming an unbounded parser rather than a maintainable boundary fix.

A better follow-up should rethink the boundary around execution context and message delivery itself, with any command parsing kept as narrow defense-in-depth. I do not want to keep expanding this PR reactively and make it harder to review or trust.

@rubencu rubencu closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants