Repository navigation
fix(exec): PowerShell /c and bash -l -c can be saved as allow-always rules - #1511
Conversation
Allow-always could store powershell.exe /c and bash -l -c as reusable rules because those spellings were not treated as inline shells. - Treat PowerShell /c, /command, and colon-attached forms as wrappers - Treat POSIX -c, --command, and -lc in any argument after the shell name - Keep bash script.sh and bash -l script.sh bindable Signed-off-by: Sebastien Tardif <[email protected]>
|
🦞👀 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. |
|
Codex review: needs real behavior proof before merge. What this changesThe PR prevents recognized inline shell commands from receiving reusable approvals while preserving supported direct-script approvals. Example: An agent requests powershell.exe /c "Get-Date".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 5 items remain Keep this PR open: main still needs the fix, but a remaining PowerShell prefix regression blocks merging. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway and MCP system.run requests enter the shared approval pipeline, which classifies argv, derives reusable identities, evaluates stored policy, and supplies approved execution to the sandbox. flowchart TD
Request[Gateway or MCP request] --> Classifier[Shell wrapper classifier]
Classifier --> Binder[Reusable command binder]
Binder --> Policy[Approval coordinator]
Store[Stored approval rules] --> Policy
Policy --> Recheck[Execution policy recheck]
Recheck --> Sandbox[MXC process execution]
Technical reviewBest possible solution: Keep classification in the existing normalizer and match PowerShell's parameter-specific minimum prefixes instead of requiring globally unique prefixes. Do we have a high-confidence way to reproduce the issue? Source establishes both the original classification gaps on main and the remaining Configuration prefix failure; no target code was executed during this review. Is this the best way to solve the issue? Repairing the existing classifier is the right boundary, but its global prefix-count heuristic must follow the host's actual parameter precedence. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0131e4ce1f79. Provenance checked
TestingProof path: shipped entry point. SecurityNeeds attention: The remaining prefix mismatch weakens the boundary between individual approval and reusable command authorization. EvidenceSecurity concerns:
What I checked:
Likely related people:
LabelsLabel 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 (24 earlier review cycles; latest 8 shown)
Reviewed October 20, 2026, 1:47 PM ET / 17:47 UTC (Revision 25). |
Signed-off-by: Sebastien Tardif <[email protected]>
|
Global triage: HOLD_FOR_AUTHOR. Take confidence 5%; recommendation confidence 99%; effort medium; risk high. Three verified parsing gaps block this security-boundary change:
Please implement operand-aware, shell-specific option parsing and add saved-rule replay coverage for combined flags, post-script arguments, PowerShell The PR must declare and run The red hosted lanes are not linked to this patch: Core failed an unrelated bounded-cancellation test, the E2E shards failed during shared setup initialization, and CI Gate is derivative. They do not replace the missing MXC proof. |
bash script.sh -c value and pwsh -File script.ps1 /c value are direct script invocations. Scanning past the script operand classified those arguments as inline shell commands and blocked reusable approval. Inline -c and /c before the script operand still stay one-time. Shared tests: 4125 passed, 32 skipped. Tray tests: 3067 passed, 5 failed on the LF source-contract mismatch tracked in openclaw#1518. Signed-off-by: Sebastien Tardif <[email protected]>
A single-dash letter cluster that contains c, such as -ec or -ce, is an inline shell command. The next argument is the payload. Scanning still stops at the script name, so bash script.sh -ec value stays a direct script. Shared tests: 4128 passed, 32 skipped. Tray tests: 3067 passed, 5 failed on the LF source-contract mismatch tracked in openclaw#1518. Signed-off-by: Sebastien Tardif <[email protected]>
A combined flag is inline only when it contains a lowercase c. Uppercase C is noclobber, so bash -C and bash -eC script.sh stay direct scripts. bash -ec remains inline. Exact POSIX flags are case-sensitive, so -C does not match -c. Shared tests: 4129 passed, 32 skipped. Tray tests: 3067 passed, 5 failed on the LF source-contract mismatch tracked in openclaw#1518. Signed-off-by: Sebastien Tardif <[email protected]>
|
HOLD_FOR_AUTHOR at I ran harmless native commands with profiles disabled, bounded completion and task-owned scripts/directories. In an owned working directory containing a directory literally named The old scanner reached Both independent reviewers used the same prompt and agree:
Single-reviewer findings and scope disposition:
The last two are portability/adjacent-contract follow-up evidence, not a request to expand this lane. The reported WSL proxy, Unicode dash, log-only upgrade explanation and unused payload-tail findings are also preexisting or outside the live changed boundary, so no speculative redesign or patches were made for them. Additional native controls: One separate introduced cross-shell regression is source-backed, not native-fish proof: the case-sensitive flag set applies to Please keep the repair in this PR's classifier owner, with shell-specific switch position, operand arity, termination and PowerShell prefix rules backed by actual CLI semantics, rather than another special-case token patch. Add binder/saved-rule regressions for the newly weakened case and direct-script controls. I confirmed that a missed Bash wrapper allows slash/backslash-normalized argument patterns to match two payloads with different actual semicolon behavior. That observation is native shell plus helper-level matching evidence, not Gateway-to-node final-I/O proof. The intended upgrade behavior enforces the existing documented one-time shell policy: recognized inline wrappers have no reusable identity or saved-rule matches. Existing records remain untouched; this is not permission to delete, rewrite or keep unsafe rules. Validation is green but does not override these source blockers. Original head: full build passed, Shared 4129 passed / 32 skipped, Tray 3072 passed, focused exec 339 passed. Unpushed normal integration Live MXC 0.8.0 probe still reports |
A PowerShell option value named -File stopped classification before a later -c, so the binder could save that inline command. A positional script made a later /c look like a host switch. fish -C is an init command and stays a wrapper. bash -C stays noclobber. Validation: ./build.ps1 exit 0. Shared 4132 passed, 32 skipped. ExecApprovalV2NormalizationTests 120 passed. Tray 3067 passed and 5 failed, the LF source-contract mismatch in openclaw#1518. Signed-off-by: Sebastien Tardif <[email protected]>
Core and CLI failed only RunAsync_OutputDrainIsBoundedAndPreservesFinalFragments_WhenDescendantRetainsHandles. The drain took 1547 ms against a 1 second bound. That test is not in this change. Signed-off-by: Sebastien Tardif <[email protected]>
pwsh binds -wd as the WorkingDirectory alias and unique prefixes such as -wo and -wor the same way. An operand named -File was classified as file mode, so a later -c could be saved as an allow-always rule. Consume those forms, and the other documented value aliases, before the file check. Normalization tests cover -wd, -wo, -wor, /wd, -w, and -ep, including the binder and the allow-always identity. Native pwsh -wd -File -c and -wo -File -c still print the inline command. Signed-off-by: Sebastien Tardif <[email protected]>
-i and -in match Interactive, which takes no argument. The value-option prefix matcher treated them as InputFormat and skipped the following -c, so the inline command could be saved as an allow-always rule. A prefix that also matches a no-value switch stays a switch. -inp still consumes its format value. Normalization tests cover -i, -in, and -int with the binder and the allow-always identity, and -inp Text -c still stays inline. Signed-off-by: Sebastien Tardif <[email protected]>
Signed-off-by: Sebastien Tardif <[email protected]>
|
Narrow current-head check at
Exact-head fixed controls: Please finish this classifier-owned default-command boundary and provide a stable candidate for the next floor/proof pass. No Bash/fish expansion, stored-rule redesign or downstream authorization changes are requested. This pass ran only the Shared dependency build (exit 0) and six harmless native/binder controls, with profiles disabled, task-owned files/cwd and bounded completion. Runtime used normal unpushed integration |
|
I am preparing one local, uncommitted correction against 13441c6 for the sole Windows PowerShell implicit-command argument-count guard, with explicit File and pwsh positional-script controls. No alias grammar, Bash/fish, storage or protocol expansion, and no branch push or fixture launch. Please keep this candidate stable while I validate an applyable two-file patch; if you are already repairing this boundary, reply and I will stop rather than compete. Native Windows PowerShell treats implicit positional text as evaluated Command mode; explicit File mode remains the reusable script control. |
Signed-off-by: Sebastien Tardif <[email protected]>
|
Validated two-file maintainer patch for the sole Windows PowerShell positional-command guard. No commit or push was made. The patch is against The only production change removes the second-argument requirement. Native Windows PowerShell 5.1 evaluates a single positional command string, including an implicit script-path string. Both now remain runnable one-time but cannot obtain durable approval. Explicit Windows PowerShell Validation of uncommitted patch SHA-256
The first full Shared run failed Apply the following patch locally with diff --git a/src/OpenClaw.Shared/ExecApprovals/ExecShellWrapperNormalizer.cs b/src/OpenClaw.Shared/ExecApprovals/ExecShellWrapperNormalizer.cs
index 14d0f2c4..ac0a1c48 100644
--- a/src/OpenClaw.Shared/ExecApprovals/ExecShellWrapperNormalizer.cs
+++ b/src/OpenClaw.Shared/ExecApprovals/ExecShellWrapperNormalizer.cs
@@ -190,9 +190,9 @@ internal static class ExecShellWrapperNormalizer
if (!t.StartsWith('-') && !t.StartsWith('/'))
{
- // Windows PowerShell joins a positional token and everything
- // after it into command text. A lone positional stays a script.
- if (windowsPowerShell && i + 1 < command.Count)
+ // Windows PowerShell evaluates positional input as command text,
+ // even one token. Explicit File mode was handled above.
+ if (windowsPowerShell)
return t;
return null;
}
diff --git a/tests/OpenClaw.Shared.Tests/ExecApprovalV2NormalizationTests.cs b/tests/OpenClaw.Shared.Tests/ExecApprovalV2NormalizationTests.cs
index 5fe408b2..cc0ac650 100644
--- a/tests/OpenClaw.Shared.Tests/ExecApprovalV2NormalizationTests.cs
+++ b/tests/OpenClaw.Shared.Tests/ExecApprovalV2NormalizationTests.cs
@@ -235,6 +235,51 @@ public class ExecApprovalV2NormalizationTests
Assert.NotNull(bound);
}
+ [Theory]
+ [InlineData("Write-Output marker")]
+ [InlineData("Write-Output marker; Write-Output second")]
+ [InlineData("script.ps1")]
+ public void Normalizer_WindowsPowerShellSinglePositional_IsOneTimeCommand(string command)
+ {
+ string[] argv = ["powershell.exe", "-NoProfile", command];
+ AssertWrapper(argv, command);
+ Assert.Null(ExecReusableCommandBinder.TryBind(argv, cwd: null, env: null, out var failure));
+ Assert.Equal(ExecReusableCommandBinder.BindFailure.ShellWrapper, failure);
+
+ var outcome = ExecApprovalV2Normalizer.Normalize(Req(argv));
+ Assert.True(outcome.IsResolved);
+ Assert.Null(outcome.Identity!.ReusableCommand);
+ Assert.Empty(outcome.Identity.AllowAlwaysPatterns);
+ Assert.Empty(outcome.Identity.AllowlistResolutions);
+ }
+
+ [Theory]
+ [InlineData("powershell.exe", "-File")]
+ [InlineData("powershell.exe", "-fi")]
+ [InlineData("powershell.exe", "-InputFormat", "Text", "-File")]
+ [InlineData("pwsh.exe")]
+ public void Normalizer_SingleScriptInFileMode_RemainsReusable(string executable, params string[] options)
+ {
+ var directory = Directory.CreateTempSubdirectory("exec-single-script");
+ try
+ {
+ var tool = Path.Combine(directory.FullName, executable);
+ File.WriteAllBytes(tool, [0x4D, 0x5A]);
+ var argv = new List<string> { tool, "-NoProfile" };
+ argv.AddRange(options);
+ argv.Add("script.ps1");
+
+ Assert.False(ExecShellWrapperNormalizer.Extract(argv).IsWrapper);
+ var bound = ExecReusableCommandBinder.TryBind(argv, cwd: null, env: null, out var failure);
+ Assert.Equal(ExecReusableCommandBinder.BindFailure.None, failure);
+ Assert.NotNull(bound);
+ }
+ finally
+ {
+ directory.Delete(recursive: true);
+ }
+ }
+
[Fact]
public void Normalizer_FishInitCommand_IsWrapper()
{
@@ -1078,15 +1123,14 @@ public class ExecApprovalV2NormalizationTests
}
[Fact]
- public void ResolveForAllowlist_DirectPowerShellScriptFile_NotFailClosed()
+ public void ResolveForAllowlist_WindowsPowerShellPositionalScript_ResolvesCommandText()
{
- // Direct exec path: ["powershell", "script.ps1"] — no inline flag, no -EncodedCommand.
- // DirectExecUsesEncodedCommand must not trigger; must resolve as a single resolution.
+ // This historical resolver inspects the command text, not durable eligibility.
var resolutions = ExecCommandResolver.ResolveForAllowlist(
["powershell", "script.ps1"],
evaluationRawCommand: null, cwd: null, env: null);
Assert.Single(resolutions);
- Assert.Contains("powershell", resolutions[0].ExecutableName, StringComparison.OrdinalIgnoreCase);
+ Assert.Equal("script.ps1", resolutions[0].ExecutableName);
}
[Fact] |
powershell Get-Date runs as command text, but a lone positional was saved as a script. Command text is now inline, including when nothing follows it. A lone script.ps1 path stays a script. Signed-off-by: Sebastien Tardif <[email protected]>
A lone script name is still implicit -Command. Guessing from a .ps1 suffix left that command bindable. Explicit -File remains the reusable script form. Signed-off-by: Sebastien Tardif <[email protected]>
|
Global triage: HOLD_FOR_AUTHOR. Take confidence 20%; recommendation confidence 98%; effort small; risk high. Reviewed exact head Author: resolve the current durable review findings, add focused regressions, and request a fresh exact-head review. This is a triage classification, not a merge action. No branch changes were made. |
Recognize EncodedArguments aliases without changing EncodedCommand prefixes, and preserve ServerMode switch arity. Add normalization and persistent-approval regressions plus isolated script controls. Separate the E2E roaming root and guard its lifecycle wiring. Co-authored-by: Copilot App <[email protected]>
Integrate main at 431bd8f. Preserve both the E2E roaming-root guard and the independent startup safety tests when resolving their insertion conflict. Co-authored-by: Copilot App <[email protected]>
What Problem This Solves
Fixes: Allow always can save PowerShell
-cand Bash-l -cinline commands as reusable rules, so a later command can run without a fresh prompt.User Impact
Inline shell commands stay one-time. A direct program, a direct script, and Bash noclobber
-Ccan still be reusable. A previously saved allow-always rule for a newly recognized inline command stays on disk and does not authorize that run.Why This Change Was Made
The existing reusable-command binder already refuses a shell wrapper. This head makes PowerShell, Bash, and fish classification match the real host flags, including PowerShell value aliases, File prefixes, and a lone Windows PowerShell positional command. Stored records are not rewritten.
Evidence
Head
ddcf698fd5d1cee6d7f27077897775348b6cb28a. The earlier October 1 note that alias and File-prefix cases were still misclassified described older candidates. Those parser holes are fixed on this head. The trace below is the current-head gateway path.Change Type
Scope
winnodeRequired proof pools
windows-wsl-mxc: the direct-script allow reachedmxc-direct-appcwith host fallback blocked.windows-wsl-gateway-e2e: saved inline-rule denial, direct-script allow, and revoked in-flight approval werenode.invokecalls.windows-winui-interactive: the command approval window was present and Allow Once was clicked after the policy was tightened.Validation
Windows x64, worktree
wt-wn-1511,OPENCLAW_REPO_ROOTset to that worktree..\build.ps1dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csprojdotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj.\scripts\validate-mxc-e2e.ps1was started through the MXC E2E fixture. Setup stopped inrun-wizardwithGATEWAY_RESTART_PREPARATION_REFUSED(cannot verify a live serving Gateway owner). That is the shared #1498 failure. It was not run again and setup was not patched. The approval trace below uses the Ubuntu-24.04 gateway that was already listening on port 18789.Real Behavior Proof
ocwn1511directory, current-head Debug tray,SystemRunBlockHostFallbackWhenMxcUnavailabletrue andSystemRunAllowWindowsUitrue. Gateway OpenClaw on Ubuntu-24.04 atws://127.0.0.1:18789. The paired node reported version2026.9.5-fix-f108-inline-shell-allow-rules.1.ddcf698fd5d1cee6d7f27077897775348b6cb28a.security=allowlist,ask=off,askFallback=deny, with twoallow-alwaysentries for**/powershell.exe. One entry's argument pattern was the inline-ccommand. The other waspowershell.exe -NoProfile -Fileplus the direct script path.Old inline rule,
openclaw gateway call node.invokeforsystem.run:ok=false,exec-approvals-v2: AllowlistMiss (allowlist-miss).c242ff24:decision=deny reason=allowlist-miss promptAttempted=False. No sandbox request for that correlation.OPENCLAW_1511_INLINE_RAN. That file was not created.Direct script control, same gateway call,
powershell.exe -NoProfile -Fileon a local.ps1:0709ac2b:decision=allow reason=approved promptAttempted=false grant=arg-bound.[mxc] system.run sandbox requestwithexecutor=mxc-direct-appc,contained=True,blockHostFallbackWhenMxcUnavailable=True,shell=<direct-argv>.OPENCLAW_1511_DIRECT_OK. Stderr said the sandbox deniedSet-Contentto the host temp file. The host file was not created. The script still ran inside MXC.Revoked approval while the window was open:
ask=alwayswith the direct-script rule still present, thensystem.runwas invoked again.OpenClaw Companion - Command Approvaland theExecApprovalAllowOnceActionbutton.security=denywith an empty allowlist.exec-approvals-v2: ValidationFailed (policy-changed-before-execution).060d156d:decision=deny reason=policy-changed-before-execution promptAttempted=True. The direct marker file was still absent.MCP, same isolated tray:
winnode --list-toolsincludedsystem.run,system.run.prepare,system.which, andsystem.execApprovals.get.winnode --command system.run.prepareforpowershell.exe -NoProfile -c "Write-Output OPENCLAW_1511_INLINE_RAN"returned that argv inplanand did not create the marker file.winnode --command system.which --params {"bins":["powershell.exe"]}returned{"bins":{}}.Screenshot or artifact links verified? No.
PrintWindowof the approval window was a black frame with only the caption buttons, so it is not attached.Not verified or blocked:
.\scripts\validate-mxc-e2e.ps1did not finish the three named Gateway MXC proofs because the fresh setup fixture hit Gateway 2026.9.6 blocks WSL setup at guarded post-wizard restart #1498. The containedsystem.runabove is the MXC observation for this head.Security Impact
-Filescript can still match an argument-bound rule. Tightening the policy while the approval window is open fails closed before process I/O. No saved record is deleted.Compatibility and Migration
Review Conversations