Skip to content

fix(node-host): Windows node commands cannot use the allowlist or auto-review because of the cmd.exe wrapper - #166140

Open
Dimitri-lcht wants to merge 6 commits into
openclaw:mainfrom
Dimitri-lcht:windows-direct-argv
Open

Dimitri-lcht wants to merge 6 commits into
openclaw:mainfrom
Dimitri-lcht:windows-direct-argv

Conversation

@Dimitri-lcht

Copy link
Copy Markdown
Contributor

Closes #157930

What Problem This Solves

On a Windows node host, every system.run command is wrapped as cmd.exe /d /s /c <command>. The node intentionally treats that wrapper as an allowlist miss (windowsShellWrapperBlocked), because cmd.exe changes the meaning of quotes and builtins. As a result, no allowlist entry or durable approval can ever apply on a Windows node: every command needs a human approval, even an absolute-path executable that is explicitly allowlisted.

User Impact

An operator can now allowlist an executable on a Windows node (for example C:\Users\me\.local\bin\claude.exe) and the agent can run it with varying arguments without an approval each time. Commands that genuinely need cmd.exe (operators outside quotes, builtins, .cmd/.bat scripts) keep the existing wrapper and the existing behavior.

Why This Change Was Made

#157930 suggests binding and reviewing the inner command of the canonical wrapper. This PR takes the narrower route of not sending the wrapper when it is not needed: when a Windows command has no cmd.exe operator outside quotes, no builtin as its first word, and no .cmd/.bat target, the Gateway sends it to the node as a direct argv. The windowsShellWrapperBlocked rule is untouched, and the node's existing direct-argv path, allowlist and approval binding apply unchanged.

Splitting follows both Windows command-line rules (CommandLineToArgvW and the current C runtime) and only accepts a command when both yield the same argv; otherwise it keeps cmd.exe. Characters such as & | < > ^ ( ) % ! and newlines are literal inside quotes and stay on the direct path; %VAR% is not expanded there, and the approval card shows the exact argv that runs. The Gateway approval precheck evaluates that same argv, so it never authorizes more than the node does.

Evidence

  • Unit tests for the splitter: eligible commands, every cmd.exe metacharacter inside and outside quotes, escaped quotes and backslash runs, doubled quotes, newlines inside quotes, builtins, .cmd/.bat, shell wrappers.
  • Gateway tests for the argv sent to the node on both paths and for equality between the approved text and the executed argv.
  • Real Windows integration test through the node handler: the child receives a & b | c < d > e ^ f (g) 50% %PATH% !x! say "hi" plus a newline exactly; allow-always is offered for an ordinary executable and reused.
  • Real behavior proof: on a Windows 11 node paired with a Linux Gateway, with claude.exe in the node allowlist, the agent ran claude.exe -p "<prompt with ( ) & % ? and accents>" --permission-mode plan with no approval prompt, and Claude Code answered the full prompt. Before this change, the same calls required an approval each time and logged Exec auto-review skipped: dispatch chain cannot be bound; after it, that line no longer appears.
  • Not run locally: the full test suite.

…direct argv

The gateway wrapped every command for a Windows node in
cmd.exe /d /s /c. The node treats that wrapper as an allowlist miss in
allowlist mode, because cmd.exe changes quoting and builtin semantics,
so no allowlist entry applied to any Windows node command and every run
needed a fresh approval.

When a command cannot mean anything different to cmd.exe, the gateway
now sends it as the argv cmd.exe would not have changed. A command
qualifies only if it has no & | < > ^ % ! ( ) or line break anywhere,
quoted text included, no other control character, balanced double
quotes that wrap whole arguments, no backslash before a quote, and a
first word that is neither a cmd.exe internal command, a .cmd or .bat
script, nor a shell wrapper. Every other command keeps the unchanged
cmd.exe envelope and its approval rule.

For a direct argv the gateway sends formatExecCommand(argv) as the raw
command, so the node's prepared plan, the approval card, the approval
binding, and the executed argv all carry the same argv. The node pins
argv[0] to its resolved executable, launches it without a shell, and
evaluates allowlist entries and durable approvals on it, so allow-always
is offered when the node reports a complete reusable pattern.
Prove on a real Windows node host which approvals apply when an agent CLI is called with a prompt that changes on every call: an allow-always decision binds the exact argv and cwd, a path-only allowlist entry runs any prompt without approval on the direct argv path, and a prompt that needs cmd.exe keeps the unchanged envelope, which the node refuses to bind before any approval.
… path

A Windows node command went through cmd.exe, where the node's allowlist
never applies, as soon as it contained & | < > ^ ( ) % ! or a line break
anywhere, quoted text included, or a backslash before a quote. Agent CLI
calls such as claude.exe -p "<prompt>" therefore needed an approval for
most real prompts.

The direct argv splitter now follows the Windows command-line rules
instead of an approximation: 2n backslashes before a quote give n
backslashes and toggle quoting, 2n+1 give n backslashes and a literal
quote, other backslashes are literal, and a doubled quote inside quotes
is a literal quote. CommandLineToArgvW and the current C runtime differ
on that last rule (the runtime stays inside the quotes, CommandLineToArgvW
leaves them), so the command is split with both rules and accepted only
when they produce the same argv; measured on Windows, they agree on every
other case. The child process never reparses this text: the node spawns
the argv array and libuv quotes each element for the C runtime.

Inside quotes every character is literal, line breaks included. Outside
quotes, & | < > ^ ( ) or a line break still keeps the command on the
unchanged cmd.exe envelope, as does an unterminated quote. % and ! are
passed literally on the direct path, since no shell expands them there.
The existing exclusions stay: cmd.exe internal commands, .cmd and .bat
scripts, shell wrappers, and control characters other than tab and line
breaks.

The gateway approval precheck parsed the formatted argv text with the
Windows shell analyzer, which rejects % and line breaks even inside
quotes and sees unquoted operators in arguments without spaces, so it
asked for approval although the node itself would allow the command.
For a direct argv sent to a Windows node, the precheck now evaluates the
prepared argv with the same argv analysis the node uses. The cmd.exe
path and the node's windowsShellWrapperBlocked rule are unchanged.

Node approval tests that describe POSIX nodes now declare a linux
platform instead of the test host's, which only changes their outcome on
Windows test hosts.
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Oct 6, 2026
…t path

evaluateExecAllowlistWithAuthorization no longer exists on main. The
Gateway precheck for a Windows direct argv now calls what the node calls
for a shell-free argv in evaluateSystemRunAllowlist: analyzeArgvCommand
followed by evaluateExecAllowlist, keeping analysisOk and segments from
the analysis. On Windows the removed helper already delegated to
evaluateExecAllowlist, so the evaluation is unchanged.

Test fixtures follow main: saveExecApprovals moved to
exec-approvals-store.test-support, and the node-shell, gateway, and
nodes-utils mocks spread the real module through importOriginal instead
of closed factories, so the stale node-shell entry leaves the mock export
baseline.
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR sends eligible absolute Windows executables directly to node hosts and evaluates their argument arrays for allowlisting and automatic review.

Example: Run allowlisted C:\Windows\System32\hostname.exe on a Windows node.

  • Before: The Gateway adds cmd.exe transport, preventing an automatic allowlist match.
  • After: The Gateway sends the executable directly, allowing existing node policy to authorize it.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The earlier correctness blockers are repaired, but the Windows integration expectations contradict the head and required final-effect evidence remains insufficient.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Windows node operators receive human approval requests even for explicitly allowlisted absolute executables.
Reason: The user problem is concrete, but the recorded area-owner response explicitly reserves the parser and security direction for a maintainer decision.

Merge readiness

⛔ Blocked before merge - 7 items remain

Keep open: current main still has the reported Windows approval limitation, and the four earlier findings are addressed, but two test/documentation defects remain alongside an unresolved owner decision and a reported merge conflict.

Priority: P1
Reviewed head: 251926608b0df479cd67cb7b2fbeac5d5eebcd86
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should the Gateway automatically select direct Windows execution using this new parser, restricted to absolute native images without percent pairs or blank arguments?
  • Recommendation: Approve the restricted direct-execution direction: Accept the narrowed parser contract after its concrete defects and authority evidence are resolved.
  • Why: The recorded area-owner comment requires a product/security design decision; the latest restrictions address earlier defects but do not constitute approval of the parser approach.

Before merge

  • Add real behavior proof - Authority-chain proof required: the Windows 11/Linux Gateway narrative supports an earlier allowlisted native run, but supplies no trace of the revised absolute-path command reaching final launch, quoted-command auto-review, or a bare batch-resolving name and revoked approval being rejected before process I/O. Provide redacted terminal output or logs through the shipped flow, including fresh and v2026.10.8-upgraded setups with existing settings intact; redact IPs, keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Update the Windows fixtures for the percent-expansion fallback (P2) - SPECIAL_ARGUMENT_SOURCE contains 50% %PATH%, so countPercentSigns returns three and resolveWindowsDirectCommandArgv now returns null. On Windows this assertion therefore compares undefined with an argument array before executing the child. The path-only allowlist test also sends this fixture while expecting no approval, although it now takes shell transport. Separate eligible literal-character delivery from an expansion-fallback case and assert the correct transport for each.
  • Document the restricted direct-command eligibility (P2) - This new paragraph still promises direct execution for any non-builtin, non-batch command and says percent expressions inside quotes are passed literally. The head instead requires an absolute .exe/.com target, rejects blank arguments, and falls back to cmd.exe whenever two percent signs occur. For example, bare claude.exe still uses shell transport and C:\tools\tool.exe "%TEMP%\output.txt" retains expansion. Update this paragraph and the corresponding PR claims so operators can configure a working unattended command without relying on behavior the patch no longer provides.
  • Resolve security review attention item - The previous batch-shim bypass is excluded in source, while the new unattended transport boundary remains subject to the recorded owner decision.
  • Resolve merge risk - The Gateway selects direct transport before node-local resolution and process adaptation; final-effect evidence must establish that an admitted command cannot acquire unauthorized shell execution after approval.
  • Complete next step - The contributor should resolve GitHub's reported merge conflict and validate the resulting head.
  • Improve patch quality - Add final-effect proof for permitted native execution, shell-requiring commands, and revocation before process launch.

Findings

  • [P2] Update the Windows fixtures for the percent-expansion fallback — src/agents/bash-tools.exec-host-node.windows-direct.integration.test.ts:187-190
  • [P2] Document the restricted direct-command eligibility — docs/nodes/node-host.md:279

Tests

  • Missing end-to-end proof: Supply recorded Windows Gateway-to-node proof for the revised native path, quoted-command auto-review, forbidden/revoked launch rejection, and fresh versus latest-stable upgrade behavior; base-fail/head-pass regression execution is not shown.
Agent review details

How this fits together

The Gateway translates agent command text into node execution requests; node preparation, approval policy, and process launch bind and execute the resulting argument array.

flowchart TD
A[Agent command text] --> B[Gateway transport selection]
B --> C[Direct Windows argv]
B --> D[cmd shell transport]
C --> E[Node preparation and approval]
D --> E
E --> F[Current authority and executable checks]
F --> G[Process launch]
Loading

Technical review

Best possible solution:

Use an owner-approved direct native-executable path with exact argv binding, preserved shell fallback semantics, and node-owned authorization through final launch.

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

Current-main Windows transport and node policy establish the reported allowlist limitation; no current-main runtime reproduction was executed.

Is this the best way to solve the issue?

Direct argv transport fits the existing node execution contract, but accepting a new command parser remains an explicit owner decision.

Full review comments:

  • [P2] Update the Windows fixtures for the percent-expansion fallback — src/agents/bash-tools.exec-host-node.windows-direct.integration.test.ts:187-190
    SPECIAL_ARGUMENT_SOURCE contains 50% %PATH%, so countPercentSigns returns three and resolveWindowsDirectCommandArgv now returns null. On Windows this assertion therefore compares undefined with an argument array before executing the child. The path-only allowlist test also sends this fixture while expecting no approval, although it now takes shell transport. Separate eligible literal-character delivery from an expansion-fallback case and assert the correct transport for each.
    Confidence: 1
  • [P2] Document the restricted direct-command eligibility — docs/nodes/node-host.md:279
    This new paragraph still promises direct execution for any non-builtin, non-batch command and says percent expressions inside quotes are passed literally. The head instead requires an absolute .exe/.com target, rejects blank arguments, and falls back to cmd.exe whenever two percent signs occur. For example, bare claude.exe still uses shell transport and C:\tools\tool.exe "%TEMP%\output.txt" retains expansion. Update this paragraph and the corresponding PR claims so operators can configure a working unattended command without relying on behavior the patch no longer provides.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fd0403b40c98.

Merge-risk options

Maintainer options:

  1. Establish final transport authorization (recommended)
    The contributor should demonstrate permitted native execution and rejection of shell-requiring or revoked execution before process launch.
  2. Pause this implementation
    Maintainers can retain the report while choosing a different transport-binding design.

Provenance checked

  • Prepared command identity and remote approval prechecks keeps the original intent (b3dc7a4: Bind node automatic review to prepared plans rather than an independently interpreted request.)
  • Gateway environment isolation keeps the original intent (Harden node exec approval precheck env [AI] #81488: Gateway-local PATH must not satisfy an approval precheck for a command executed on another host.)
  • Automatic-review executable binding keeps the original intent (feat(exec): let the auto-reviewer allow, deny, or escalate commands #141987: Automatic approval requires a bound executable dispatch chain and preserves human approval for implicit shell startup.)
  • Windows transport selection changes intended behavior with a stated reason (unknown: Available node-shell history shows longstanding cmd.exe transport; older blob retrieval prevented establishing its original rationale. Current policy explicitly preserves shell approval because cmd changes quoting and builtin semantics.)

Testing

Proof path: in-process harness.

Security

Needs attention: The previous batch-shim bypass is excluded in source, while the new unattended transport boundary remains subject to the recorded owner decision.

Evidence

What I checked:

PR surface

Source +253, Tests +632, Docs +1, Other -1. Total +885 across 11 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 285 32 +253
Tests 5 642 10 +632
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 11 928 43 +885

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #157930
Summary: This PR targets the canonical Windows transport-wrapper approval limitation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported Windows node workflow cannot use its configured unattended approval policy, and current main retains the responsible transport.
  • merge-risk: 🚨 compatibility: Existing command text automatically changes transport and quoting interpretation for eligible native executables.
  • merge-risk: 🚨 security-boundary: The new transport selection enables unattended execution across the Gateway-to-node approval boundary and needs final-effect authorization evidence.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-06T14:39:11.403Z sha ce19116 :: needs real behavior proof before merge. :: [P1] [P1] Replace the nonexistent allowlist evaluator import | [P2] [P2] Bind direct auto-review using canonical argv text | [P1] [P1] Preserve commands that require environment expansion | [P1] [P1] Classify batch scripts after node-local executable resolution | [P2] [P2] Preserve empty arguments through allowlisted process launch
  • reviewed 2026-10-06T14:56:40.342Z sha c4709ee :: needs real behavior proof before merge. :: [P1] [P1] Classify batch scripts after node-local executable resolution | [P1] [P1] Preserve commands that require environment expansion | [P2] [P2] Bind direct auto-review using canonical argv text | [P2] [P2] Preserve empty arguments through allowlisted process launch

Reviewed October 28, 2026, 12:07 PM ET / 16:07 UTC (Revision 3).

…mages

Addresses three ClawSweeper findings on this PR: batch resolution after
node-local executable resolution, environment expansion, and blank
arguments.

The node resolves a bare name through PATH and PATHEXT, so `mytool` can
land on `mytool.cmd`. The classifier inspected only the submitted token,
so an allowlisted batch shim was admitted as a direct argv and
resolveSafeChildProcessInvocation then reinserted cmd.exe after policy had
already authorized a shell-free launch, bypassing the approval the
explicit wrapper form requires. The direct path now admits only an
absolute .exe or .com image, so the launched transport is identical to the
authorized one. That requirement subsumes the internal-command and batch
checks, which are removed.

Dropping % from the shell-sensitive characters sent commands such as
tool.exe "%TEMP%\output.txt" directly and passed the expression literally,
silently changing approved workflows that cmd.exe used to expand. An
expansion needs a pair of percent signs, so those commands stay on the
shell transport.

analyzeArgvCommand drops empty and whitespace-only arguments, and the node
builds an automatically allowlisted launch from that filtered analysis, so
a direct argv carrying a blank argument would run a command the approval
never saw. The direct path declines it and the shell transport keeps the
argument.
Addresses the remaining ClawSweeper finding on this PR: direct auto-review
binding.

analyzeArgvCommand renders segment text with argv.join(" "), while the
prepared node command for a direct argv is canonical formatExecCommand
text. A quoted executable path or an argument containing spaces made the
two strings differ, so the binding comparison in
analyzeNodeApprovalRequirement left autoReviewArgv undefined and skipped
the reviewer on an allowlist miss.

The Gateway precheck now carries the canonical display identity on the
segments it returns. The evaluation itself still runs on the unmodified
analysis, and the argv arrays stay exactly as prepared, so matching and
launch still see every argument.
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026

This branch has not been deployed

No deployments
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows node exec cannot use auto-review or Gateway allowlist because of the cmd.exe transport wrapper

1 participant