[Repo Assist] fix(security): handle all PowerShell -EncodedCommand abbreviations and separator forms in ExecShellWrapperParser#270
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
…d separator forms ExecShellWrapperParser.ParsePowerShellPayload previously only recognised -EncodedCommand, -enc, and -ec. PowerShell also accepts: * All unique prefix abbreviations from the minimum disambiguation point (-en, -enco, -encod, -encode, -encoded, ...) to the full flag name. * Inline separator forms: -enc:PAYLOAD and -enc=PAYLOAD (single token). * The same colon/equals separator forms for -Command / -c. Without these, a command like powershell -encode <b64 payload> was not decoded by the wrapper parser, so the encoded inner command was never evaluated against the exec approval policy. The outer command 'powershell -encode <b64>' might pass policy while executing arbitrary encoded code unchecked. Changes - Extract IsEncodedCommandFlag / IsCommandFlag helpers using prefix matching (-en minimum) and the explicit -ec alias. - Add IndexOfFlagSeparator to detect inline colon/equals forms. - Refactor decoding into DecodeEncodedPayload for reuse. - 22 new tests covering all abbreviation lengths, both separator forms, and the ambiguous -e-alone case (must NOT be treated as EncodedCommand). Pre-existing test baseline (unaffected by these changes): - Shared.Tests: 1172 pass / 2 fail (canvas JSONL, Linux-only) / 20 skip - Tray.Tests: 406 pass / 1 fail (DPAPI, Windows-only) / 0 skip Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist.
Problem
ExecShellWrapperParser.ParsePowerShellPayloadonly recognised three forms of the-EncodedCommandflag:-EncodedCommand(full name)-enc(short prefix)-ec(explicit alias)PowerShell also accepts:
-en,-enco,-encod,-encode,-encoded, ...-enc:PAYLOAD,-EncodedCommand:PAYLOAD-enc=PAYLOAD,-EncodedCommand=PAYLOADSecurity impact
ExecShellWrapperParseris called inSystemCapability.HandleRunAsync(line 374) after the top-level command has already passed the exec approval policy. Its job is to expand shell wrappers so the inner commands are independently evaluated. If an unrecognised flag form is used (e.g.powershell -encode <b64>), the parser emits no targets and the encoded inner command is never checked against policy — while the outerpowershell -encode <b64>command may pass as-is.Fix
IsEncodedCommandFlaghelper: matches-ec(explicit alias) and all unique prefix abbreviations from the minimum disambiguation point (-en, 2 chars after-) up to the full flag name.-ealone is intentionally excluded as it is ambiguous with-ExecutionPolicy.IndexOfFlagSeparatorto detect inline:/=separator forms (a single token containing both flag and value).IsCommandFlaghelper for-Command/-c.DecodeEncodedPayloadhelper to avoid duplicating the base-64 try/catch.-Command/-cas a bonus fix.Tests
22 new tests added:
-enthrough-encodedcommand)-enc:,-EncodedCommand:,-encodedcommand:)-enc=,-EncodedCommand=)-Command:/-c:colon separator-Command=/-c=equals separator-emust NOT decodeTest Status
OpenClaw.Shared.TestsOpenClaw.Tray.Tests† Pre-existing canvas JSONL failures on Linux (addressed by PR #264, not yet merged).
‡ Pre-existing DPAPI failure on non-Windows (addressed by PR #265, not yet merged).