Skip to content

fix: make Gateway shell execution work on Windows nodes - #972

Merged
steipete merged 4 commits into
mainfrom
codex/approve-gateway-shell-wrappers
Jul 12, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/approve-gateway-shell-wrappers

Conversation

@steipete

@steipete steipete commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Gateway system.run wraps Windows commands as cmd.exe /d /s /c <command>, but the Hub rejected the unmatched outer wrapper before checking the exact approved command. The MXC sandbox also treated an administrator-group ACL as usable by its restricted token, omitted a safe default cwd, and returned no success field for the agent exec projection.
  • Why it matters: an operator could approve hostname, receive the correct stdout and exit code from the live Surface, yet the agent still saw a failed command.
  • What changed: parse Gateway shell wrappers before approval; allow only exact approved nested targets; preserve explicit deny/prompt precedence; validate direct-user WRITE_DAC; default omitted cwd to the writable MXC scratch directory; return the shared system.run.success contract.
  • User impact: exact approved Windows commands now execute through the Gateway and appear successful to the agent without granting a broad shell rule.
  • What did NOT change: no new capability, default permission, network call, credential path, config surface, or release artifact.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs / instructions
  • Tests / validation
  • Security hardening
  • Chore / infra

Scope (select all touched areas)

  • Tray / WinUI UX
  • Windows node capability
  • Local MCP / winnode
  • Gateway / connection / pairing
  • Setup / onboarding
  • Permissions / privacy / security
  • Tests / CI / docs

Linked Issue/PR

Validation

  • ./build.ps1 on Surface ARM64 — Shared, CLI, WinNode CLI, SetupEngine, and WinUI built.
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj -c Debug --no-build — 2,739 passed, 31 skipped, 0 failed.
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore — 1,669 passed, 0 failed.
  • Focused wrapper, ACL, cwd, and result-contract regressions passed.
  • Release ARM64 WinUI rebuild — 0 warnings, 0 errors.
  • Fresh autoreview after both review repair cycles — no accepted/actionable findings.
  • ./scripts/validate-mxc-e2e.ps1 -Configuration Release — blocked before either MXC assertion: the isolated unpackaged WinUI host exited during startup with 0xC000027B. Debug and Release both reproduce the pre-MCP harness crash; the production-data Release host runs and completes the real Gateway scenario below.

Real behavior proof

  • Environment: Surface ARM64, Windows 11 10.0.26200; live Gateway on clawmac.
  • Exact tested head: c98e695e.
  • Paired Windows Node (STEIPETESURFACE) to the live Gateway with its production node identity and an exact hostname allow rule.
  • Direct node.invoke system.run using Gateway argv cmd.exe /d /s /c hostname returned stdout: steipetesurface, exitCode: 0, timedOut: false, success: true.
  • Agent run a42d77a0-848d-489b-95e5-c91b2859a32b used exec host=node; result: Hostname: steipetesurface, Exit status: Success, one tool call, zero failures.
  • Before the final result-contract fix, the same live command returned the correct stdout and zero exit code but the agent marked it failed because Windows omitted success.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? Yes
  • Data access scope changed? No
  • Risk + mitigation: wrapped commands can use inner allow rules. Only an unmatched default-deny wrapper may defer; every parsed target must match an exact allow; parse errors fail closed; prompts and explicit outer/inner denies still win. MXC readonly preparation now requires a direct-user WRITE_DAC grant and respects every token SID deny.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Review Conversations

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f172d1e4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +558 to +564
var hasNestedTargets = parseResult.Targets.Count > 0;
var hasExplicitOuterRule = !string.IsNullOrWhiteSpace(approval.MatchedPattern);
var evaluateOuter =
!hasNestedTargets ||
hasExplicitOuterRule ||
approval.Allowed ||
approval.Action == ExecApprovalAction.Prompt;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict inner-only approval to shell wrappers

When the full command is denied only by the default policy, this treats any parsed target as enough to skip evaluating the outer command. ExecShellWrapperParser.Expand also creates targets for top-level separators, not just Gateway wrappers, so a direct request like hostname; whoami now bypasses the default deny for the full command and runs because both segments match exact default allow rules. That broadens exact approvals from single commands to shell chains; only commands proven to be wrapper payloads should be allowed to defer the outer denial.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 Urgent regression or broken agent/channel workflow affecting real users now. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed July 11, 2026, 9:42 PM ET / July 12, 2026, 01:42 UTC.

Summary
The branch changes Windows Gateway system.run wrapper authorization, MXC cwd and DACL fallback behavior, the success result contract, MCP command documentation, and focused regression tests.

Reproducibility: yes. The original hostname failure has an exact live Gateway reproduction, and the remaining defect follows deterministically from formatting cmd.exe /d /s /c "dir C:\Users", tokenizing it as dir C:Users, and attempting an exact policy match.

Review metrics: 2 noteworthy metrics.

  • Changed surface: 5 files, 315 additions, 53 deletions. The focused patch still spans approval policy, sandbox configuration, result projection, MCP documentation, and tests.
  • Reported automated validation: 2,739 shared passed; 1,669 tray passed. Broad suites passed, but the missing quoted-path case and blocked required MXC E2E leave a merge-critical gap.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #971
Summary: This PR is the candidate fix for the linked reproducible Gateway wrapper issue, but it remains incomplete for exact-approved Windows path payloads.

Members:

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

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦞 diamond lobster
Patch quality: 🦪 silver shellfish
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Preserve literal Windows backslashes in wrapper payload extraction and add the quoted-path regression.
  • [P2] Rerun all required validation and provide current-head Gateway output for the repaired quoted-path case.

Risk before merge

  • [P1] Merging as written would leave exact allow rules containing quoted Windows paths unusable through Gateway wrappers, despite the intended compatibility fix.
  • [P1] The approval decision is made against modified command text rather than the exact command configured by the operator, making policy behavior inconsistent at a security boundary.
  • [P1] The repository-required isolated MXC E2E script did not reach either assertion because the unpackaged WinUI host crashed; the live proof covers hostname but not the quoted-path case.

Maintainer options:

  1. Preserve Windows paths before merge (recommended)
    Repair wrapper parsing so exact-approved payloads retain literal backslashes, add focused regression coverage, and rerun the required validation and live proof.
  2. Pause for a broader parser decision
    Hold the PR if preserving Windows path text cannot be done without changing established POSIX or PowerShell wrapper escape semantics.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve literal Windows backslashes when extracting quoted shell-wrapper payloads, add a regression proving an exact allow rule for a command such as `dir C:\Users` succeeds through `cmd.exe /d /s /c`, and rerun the repository-required validation including MXC E2E.

Next step before merge

  • The confirmed blocker has a narrow mechanical parser-and-test repair suitable for the repair lane before normal maintainer review.

Security
Needs attention: The approval flow remains fail-closed, but it compares altered payload text rather than the exact Windows command approved by the operator.

Review findings

  • [P2] Preserve backslashes before exact inner approval — src/OpenClaw.Shared/Capabilities/SystemCapability.cs:586
Review details

Best possible solution:

Preserve literal Windows backslashes while extracting wrapper payloads, add an exact-allow regression using a quoted path such as dir C:\Users, then rerun the required build, shared/tray tests, MXC E2E, and redacted current-head live Gateway proof.

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

Yes. The original hostname failure has an exact live Gateway reproduction, and the remaining defect follows deterministically from formatting cmd.exe /d /s /c "dir C:\Users", tokenizing it as dir C:Users, and attempting an exact policy match.

Is this the best way to solve the issue?

No, not yet. Deferring an unmatched recognized wrapper to exact inner rules is an appropriate narrow fix, but exact policy matching cannot safely use a payload whose Windows path text was modified.

Full review comments:

  • [P2] Preserve backslashes before exact inner approval — src/OpenClaw.Shared/Capabilities/SystemCapability.cs:586
    The Gateway formatter quotes payloads containing spaces, but the wrapper tokenizer removes every backslash inside double quotes before this exact-rule check. Consequently, cmd.exe /d /s /c "dir C:\Users" is checked as dir C:Users, so an operator's exact dir C:\Users rule is still rejected. Preserve Windows path backslashes during payload extraction and add a regression for this Gateway argv shape. This is a late discovery on the same previously reviewed head; the parser dependency was unchanged, but its effect on the new exact-match path was missed.
    Confidence: 0.99
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 622c0e27c6b0.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact current-head live Gateway and agent output demonstrating the reported hostname fix; after repairing the finding, add redacted live output for an exact-approved quoted Windows path and avoid exposing private paths, endpoints, host details, or credentials.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦞 diamond lobster and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body provides exact current-head live Gateway and agent output demonstrating the reported hostname fix; after repairing the finding, add redacted live output for an exact-approved quoted Windows path and avoid exposing private paths, endpoints, host details, or credentials.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The PR addresses a broken live Gateway workflow, but common exact-approved Windows path commands remain blocked by the proposed implementation.
  • merge-risk: 🚨 compatibility: The new wrapper authorization path can reject existing exact allow rules after changing Windows path text during parsing.
  • merge-risk: 🚨 security-boundary: The diff changes when an outer shell denial may defer to nested command authorization, so the nested payload must be evaluated exactly and fail closed.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦞 diamond lobster and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body provides exact current-head live Gateway and agent output demonstrating the reported hostname fix; after repairing the finding, add redacted live output for an exact-approved quoted Windows path and avoid exposing private paths, endpoints, host details, or credentials.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact current-head live Gateway and agent output demonstrating the reported hostname fix; after repairing the finding, add redacted live output for an exact-approved quoted Windows path and avoid exposing private paths, endpoints, host details, or credentials.
Evidence reviewed

Security concerns:

  • [medium] Approval compares a modified Windows command — src/OpenClaw.Shared/Capabilities/SystemCapability.cs:586
    Quoted backslashes are stripped before nested exact-rule evaluation, creating a mismatch between configured policy text and the command execution request.
    Confidence: 0.99

Acceptance criteria:

  • [P1] ./build.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore.
  • [P1] ./scripts/validate-mxc-e2e.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore --filter "FullyQualifiedNameExecShellWrapperParserTests|FullyQualifiedNameRun_GatewayCmdWrapper".

What I checked:

Likely related people:

  • Scott Hanselman: Current-main blame and file history connect this contributor to the wrapper parser, system.run approval flow, and MXC configuration now affected by the PR. (role: introduced current behavior; confidence: high; commits: 4166e0fd63f8; files: src/OpenClaw.Shared/ExecShellWrapperParser.cs, src/OpenClaw.Shared/Capabilities/SystemCapability.cs, src/OpenClaw.Shared/Mxc/MxcConfigBuilder.cs)
  • Barbara Kudiess: Recent merged work modified the central MCP tool bridge that this PR updates to document the expanded system.run result contract. (role: recent adjacent contributor; confidence: medium; commits: 053501c6dfae; files: src/OpenClaw.Shared/Mcp/McpToolBridge.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (3 earlier review cycles)
  • reviewed 2026-07-12T00:12:59.949Z sha 2f172d1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-12T01:29:48.160Z sha d0c5550 :: needs real behavior proof before merge. :: [P1] Restrict default-deny deferral to actual wrapper payloads
  • reviewed 2026-07-12T01:37:36.709Z sha c98e695 :: needs real behavior proof before merge. :: [P1] Raise the auto-deny event for exact-rule wrapper rejections

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0c55502e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +611 to +614
{
const string reason = "Wrapped commands require an exact allow rule";
Logger.Warn($"system.run DENIED: {target.Command} ({reason})");
return Error($"Command denied by exec policy: {reason}");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Raise auto-deny events for wrapper exact-allow rejections

When this new guard rejects a wrapper whose inner command matched only a broad allow rule (for example, the default-deny policy with echo * and cmd.exe /c echo ok), it returns an error directly instead of going through EnsureApprovedAsync/RaisePolicyAutoDenied. NodeService relies on PolicyAutoDecided to drive OnLocalExecApprovalDecided denial notifications, so these new policy denials are silent in the tray even though other auto-denies still raise the event.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c98e695e83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +609 to +611
if (!evaluateOuter &&
innerApprovalCheck.PromptDecisionKind == null &&
!IsExactAllowRuleForCommand(innerApproval, target.Command))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Windows paths before exact inner approval

When the Gateway sends an argv wrapper such as cmd.exe /d /s /c "dir C:\Users", FormatExecCommand quotes the payload because it contains a space, but ExecShellWrapperParser.Tokenize treats backslashes inside double quotes as escapes and strips them before target.Command reaches this new exact-rule check. As a result, an operator's exact allow rule for common Windows path commands like dir C:\Users or type C:\... still fails through the Gateway path because the parsed inner command is compared as dir C:Users.

Useful? React with 👍 / 👎.

@steipete steipete changed the title fix: authorize exact commands inside Gateway wrappers fix: make Gateway shell execution work on Windows nodes Jul 12, 2026
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Jul 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head c98e695e838ea5f91216ead7258bf29883ae3d02:

  • Full ./build.ps1 succeeded.
  • OpenClaw.Shared.Tests: 2,739 passed, 31 skipped.
  • OpenClaw.Tray.Tests: 1,669 passed.
  • Focused wrapper approval, MXC ACL/cwd, and system.run result-contract tests passed.
  • Release ARM64 build succeeded with zero warnings and zero errors.
  • Exact-head hosted CI run 29175378196 is green: test, x64/ARM64 builds, setup-connect, revocation-recovery, network-recovery, repo hygiene, and CodeQL all passed.
  • Fresh autoreview completed with no actionable findings after repairing the nested-command authorization and restricted-token ACL findings.

Real behavior proof from the exact-head Release app (0.6.13-codex-approve-gateway-shell-wrappers.1):

  • Gateway node.invoke system.run with cmd.exe /d /s /c hostname returned stdout steipetesurface, exit code 0, timedOut: false, and success: true.
  • Agent run a42d77a0-848d-489b-95e5-c91b2859a32b used the Windows node once and reported Hostname: steipetesurface / Exit status: Success, with one tool call and zero tool failures.

The mandatory isolated validate-mxc-e2e.ps1 Debug and Release launches remain blocked before MCP assertions by a host WinUI crash (0xC000027B, Microsoft.UI.Xaml 3.2.2, WER 80070057). The full setup completes and the production-data exact-head Release app passes the actual Gateway-mediated MXC execution path above, so this is recorded as a harness/host blocker rather than hidden as passing proof.

@steipete
steipete merged commit cab6f02 into main Jul 12, 2026
19 checks passed
@steipete
steipete deleted the codex/approve-gateway-shell-wrappers branch July 12, 2026 01:49
@steipete

Copy link
Copy Markdown
Contributor Author

Landed as cab6f02eb9b6234c5090c9b52487cb6db3ce244c. Issue #971 closed automatically. No release was created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway-wrapped commands bypass usable Windows exec allow rules

1 participant