Repository navigation
fix(node-host): Windows node commands cannot use the allowlist or auto-review because of the cmd.exe wrapper - #166140
Dimitri-lcht wants to merge 6 commits into
Conversation
…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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…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.
|
Codex review: needs real behavior proof before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Complete 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 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fd0403b40c98. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: in-process harness. SecurityNeeds attention: The previous batch-shim bypass is excluded in source, while the new unattended transport boundary remains subject to the recorded owner decision. EvidenceWhat I checked:
PR surfaceSource +253, Tests +632, Docs +1, Other -1. Total +885 across 11 files. Added test files: 2. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)
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.
Closes #157930
What Problem This Solves
On a Windows node host, every
system.runcommand is wrapped ascmd.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/.batscripts) 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/.battarget, the Gateway sends it to the node as a direct argv. ThewindowsShellWrapperBlockedrule is untouched, and the node's existing direct-argv path, allowlist and approval binding apply unchanged.Splitting follows both Windows command-line rules (
CommandLineToArgvWand 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
.cmd/.bat, shell wrappers.a & b | c < d > e ^ f (g) 50% %PATH% !x! say "hi"plus a newline exactly;allow-alwaysis offered for an ordinary executable and reused.claude.exein the node allowlist, the agent ranclaude.exe -p "<prompt with ( ) & % ? and accents>" --permission-mode planwith no approval prompt, and Claude Code answered the full prompt. Before this change, the same calls required an approval each time and loggedExec auto-review skipped: dispatch chain cannot be bound; after it, that line no longer appears.