Skip to content

[Repo Assist] fix(security): handle all PowerShell -EncodedCommand abbreviations and separator forms in ExecShellWrapperParser#270

Merged
shanselman merged 2 commits intomasterfrom
repo-assist/fix-ps-encoded-command-abbreviations-2026-05-04-b9c567e1bb989817
May 7, 2026
Merged

[Repo Assist] fix(security): handle all PowerShell -EncodedCommand abbreviations and separator forms in ExecShellWrapperParser#270
shanselman merged 2 commits intomasterfrom
repo-assist/fix-ps-encoded-command-abbreviations-2026-05-04-b9c567e1bb989817

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 4, 2026

🤖 This is an automated PR from Repo Assist.

Problem

ExecShellWrapperParser.ParsePowerShellPayload only recognised three forms of the -EncodedCommand flag:

  • -EncodedCommand (full name)
  • -enc (short prefix)
  • -ec (explicit alias)

PowerShell also accepts:

Form Example
All unique prefix abbreviations -en, -enco, -encod, -encode, -encoded, ...
Inline colon separator -enc:PAYLOAD, -EncodedCommand:PAYLOAD
Inline equals separator -enc=PAYLOAD, -EncodedCommand=PAYLOAD

Security impact

ExecShellWrapperParser is called in SystemCapability.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 outer powershell -encode <b64> command may pass as-is.

Fix

  • Add IsEncodedCommandFlag helper: matches -ec (explicit alias) and all unique prefix abbreviations from the minimum disambiguation point (-en, 2 chars after -) up to the full flag name. -e alone is intentionally excluded as it is ambiguous with -ExecutionPolicy.
  • Add IndexOfFlagSeparator to detect inline : / = separator forms (a single token containing both flag and value).
  • Add IsCommandFlag helper for -Command / -c.
  • Extract DecodeEncodedPayload helper to avoid duplicating the base-64 try/catch.
  • Same separator handling added for -Command/-c as a bonus fix.

Tests

22 new tests added:

Category Count
All 12 prefix abbreviations (-en through -encodedcommand) 12
Colon separator (-enc:, -EncodedCommand:, -encodedcommand:) 3
Equals separator (-enc=, -EncodedCommand=) 2
-Command: / -c: colon separator 2
-Command= / -c= equals separator 2
Ambiguous -e must NOT decode 1

Test Status

Suite Before After
OpenClaw.Shared.Tests 1172 pass / 2 fail† / 20 skip 1194 pass / 2 fail† / 20 skip
OpenClaw.Tray.Tests 406 pass / 1 fail‡ / 0 skip 406 pass / 1 fail‡ / 0 skip (unchanged)

† 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).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

@shanselman
Copy link
Copy Markdown
Contributor

Thanks for tightening the encoded-command handling here. I think this still needs one security-critical adjustment before it is safe to merge.

On Windows, powershell.exe -e <base64> is accepted as an alias for -EncodedCommand and executes the encoded payload. This PR intentionally excludes -e, so an allowlisted PowerShell invocation can still hide the actual command behind encoded content.

I also could not reproduce direct process acceptance for the colon/equals forms (-enc:<payload>, -enc=<payload>, -Command:..., -Command=...) in Windows PowerShell. Conservative rejection is fine, but the real blocker is that -e must be treated as encoded-command as well.

github-actions Bot and others added 2 commits May 7, 2026 17:53
…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>
Windows PowerShell accepts -e as an EncodedCommand alias, so the shell-wrapper parser must decode it to keep approval evaluation fail-closed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@shanselman shanselman force-pushed the repo-assist/fix-ps-encoded-command-abbreviations-2026-05-04-b9c567e1bb989817 branch from 3118a8b to 25a2a46 Compare May 7, 2026 21:59
@shanselman shanselman marked this pull request as ready for review May 7, 2026 21:59
@shanselman shanselman merged commit 56d956d into master May 7, 2026
12 checks passed
@shanselman shanselman deleted the repo-assist/fix-ps-encoded-command-abbreviations-2026-05-04-b9c567e1bb989817 branch May 7, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant