openclaw-windows-node icon indicating copy to clipboard operation
openclaw-windows-node copied to clipboard

[deep-review][duplication] D3: V1 and V2 exec-wrapper detectors have diverged on shell vocabulary and flag handling

Open codemonkeychris opened this issue 6 months ago • 1 comments

Summary

Two shell-wrapper detectors exist, both reachable today, with different shell vocabularies and different PowerShell flag handling.

  • V1: src/OpenClaw.Shared/ExecShellWrapperParser.cs — string-based BFS, used by the live legacy exec-approval path (SystemCapability.HandleRunAsync → wrapper expansion at lines 374-389).
  • V2: src/OpenClaw.Shared/ExecApprovals/ExecShellWrapperNormalizer.cs — argv-based single-level, used by the V2 pipeline that's currently inert (ExecApprovalV2NullHandler is the only registered handler).

How they diverged

V2 added: zsh, dash, ash, ksh, fish to the recognized shell list.

V1 kept: cmd, cmd.exe, powershell, powershell.exe, pwsh, pwsh.exe, bash, bash.exe, sh, sh.exe.

V1 handles -EncodedCommand Base64 UTF-16LE decoding and -Cmd:value inline-separator forms. V2 does not (the inline-separator form was apparently dropped intentionally; the -EncodedCommand decoding lives elsewhere in V2 via ExecCommandResolver).

Why it matters

Once V2 ships (the coordinator is wired in), the legacy V1 path stops firing — that's the design. But until then, the live exec gate doesn't recognize zsh/dash/ash/ksh/fish wrappers. An agent invoking zsh -c "rm -rf" reaches the policy evaluator as a literal zsh -c "rm -rf" string match. The default defaultAction: deny saves us, but the policy author who wrote Allow: bash * and Deny: rm * finds neither rule matches a zsh invocation reliably.

Security review filed this as E-6 (depth-4 short-circuiting under nested wrappers) — this duplication is the structural cause.

Proposed fix

Three options, in order of preference:

  1. Promote the shared vocabulary to a single static ShellRegistry.RecognizedShells set with the union of V1 and V2. Both parsers read from it. Eliminates drift by construction.
  2. Backport V2's expanded shell list to V1. Simpler but doesn't address future drift.
  3. Ship V2 and delete V1. Highest payoff, but requires the coordinator wiring that's been pending.

Add an assertion test that walks both parsers' recognized shell lists and asserts they match (or that V1 is a subset of V2).

Severity

Medium — security-relevant duplication; observable as "policy rules don't match zsh wrappers."

Related

  • C7 (validator gap on execApprovals.set) — defense-in-depth in the same area.
  • D-V2-coordinator (out of scope for this review, but addressing the V2 rollout dissolves several items).

codemonkeychris avatar May 14 '26 00:05 codemonkeychris

Picking this up. Will backport zsh/dash/ash/ksh/fish from V2 (ExecShellWrapperNormalizer) to V1 (ExecShellWrapperParser) to close the vocabulary gap.

AlexAlves87 avatar May 14 '26 07:05 AlexAlves87