Skip to content

fix(windows): drop no-op -ExecutionPolicy Bypass from -Command spawns - #17873

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/win-edr-bypass-noop-removal
Sep 6, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/win-edr-bypass-noop-removal

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1

What

Removes -ExecutionPolicy Bypass from the two Windows PowerShell spawns where it is a provable no-op, and documents why the third candidate site was left alone.

Part of the Defender for Endpoint remediation. -ExecutionPolicy Bypass is the single highest-weighted token on the command lines in the report.

Site Invocation Action
src/main/system-fonts.ts -Command flag deleted
src/shared/secure-path-windows-acl.ts -Command flag deleted
src/main/cli/wsl-cli-scripts.ts -File on a \\wsl.localhost\ UNC path unchanged - see below

Why Group A is zero-risk: -Command is not execution-policy gated

Execution policy governs script files. It has no bearing on -Command. Measured on Windows 11 Pro 26200, Windows PowerShell 5.1:

$ powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Restricted -Command "Write-Output 'COMMAND-RAN'"
COMMAND-RAN
exit 0

The contrast case, same box, an unsigned .ps1 via -File:

$ powershell.exe -NoProfile -ExecutionPolicy Restricted -File <unsigned .ps1>
File ... cannot be loaded because running scripts is disabled on this system.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
exit 1

So on a -Command line the switch changes nothing except the Defender score.

Behavioural evidence per site

system-fonts.ts - the real font script run both ways against the live font catalog:

before count = 182  after count = 182
diff lines   = 0
sha before = 88CA56F166F5CD254B3209EB5E52861EBBE2B6B6C2B9CADDF8252CA88C667800
sha after  = 88CA56F166F5CD254B3209EB5E52861EBBE2B6B6C2B9CADDF8252CA88C667800

Byte-identical output.

secure-path-windows-acl.ts - the real WINDOWS_RESTRICT_ACL_SCRIPT driven through execFileSync with the exact production argv, with and without the switch: identical result either way (both fail identically - see the pre-existing bug note below, which this PR does not change).

Why Group B (wsl-cli-scripts.ts) is unchanged

The WSL launcher runs powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$ORCA_BRIDGE_PS1_WIN", where $ORCA_BRIDGE_PS1_WIN comes from wslpath -w over a path inside the distro's Linux filesystem. On WSL2 that is a UNC path, and RemoteSigned rejects it. Measured, Ubuntu-24.04:

$ wslpath -w ~/.local/share/orca-eptest/t.ps1
\\wsl.localhost\Ubuntu-24.04\home\neil\.local\share\orca-eptest\t.ps1

-ExecutionPolicy RemoteSigned -> "... is not digitally signed. You cannot run this
                                  script on the current system."  exit 1   (3/3 runs)
-ExecutionPolicy Bypass       -> BRIDGE-RAN                       exit 0   (3/3 runs)

Downgrading that site to RemoteSigned would break orca from inside WSL on every machine, so it is left as-is. It needs a different remediation, and the shape of that follow-up is narrower than it first looks:

  • Relocating the bridge to a local Windows path lets us drop Bypass, not the switch. The measured default effective policy on this box is Restricted, and flagless -File on a local %TEMP% script still fails. The follow-up target is -ExecutionPolicy RemoteSigned, which passes on local paths with no signing.
  • Switching to the \\wsl$\ spelling also passes RemoteSigned - but that is a fragile accident of zone classification on a spelling Microsoft deprecated in favour of \\wsl.localhost\, so it is not a fix.

Regression cover

  • src/main/system-fonts.test.ts - new case asserting the Windows font argv contains -Command and neither -ExecutionPolicy nor Bypass.
  • src/shared/secure-file.test.ts - new case asserting the ACL argv starts with exactly ['-NoProfile','-NonInteractive','-Command'] and carries no -ExecutionPolicy/Bypass. The existing assertions that indexed the script at a hardcoded [5]/[6] now derive it from indexOf('-Command') and assert that anchor exists before slicing, so a -Command -> -File swap names the switch shape that moved instead of surfacing as a path mismatch several asserts later.

Notes for reviewers (found, deliberately not fixed here)

  1. bestEffortRestrictWindowsPath / restrictWindowsPathSync do not currently apply any ACL. They pass -Command <script> <path> <sid> <isDir>, but -Command does not populate $args. It concatenates the trailing tokens into the script text, where they execute as a statement. Measured:

    $ powershell.exe -NoProfile -NonInteractive -Command 'Write-Output "count=$($args.Count)"' AAA BBB
    count=0
    AAA                            <- not arguments: parsed into the script text and emitted
    BBB
    
    $ powershell.exe -NoProfile -NonInteractive -Command '<script ending in }>' <path to a .cmd>
    script-body-ran
    TRAILING-TOKEN-EXECUTED        <- the trailing path ran as a command
    exit 0
    

    $args is empty, and AAA/BBB are not discarded - they land inside the script text and run.

    The real script therefore dies at $allowedSids[$sidText] = $true with NullArrayIndex because $args[1] is $null. $ErrorActionPreference = 'Stop' makes that exit 1, the sync path returns false, and the async path swallows it.

    Any fix that populates the values while keeping this spelling turns a dead no-op into command execution on a path string. The trailing tokens are only unreachable today because the script throws at line 8 first. This predates this PR and is unchanged by it (both spellings fail identically), but it is a live security-hardening gap and wants its own fix - -File on a packaged script, or moving the values into the script text, not a repair that leaves -Command with trailing arguments.

  2. src/shared/secure-path-windows-acl.ts calls node:child_process execFile/execFileSync directly rather than runProcess/spawnProcess. It is a pre-existing entry in child-process-import-allowlist.txt; not touched here. system-fonts.ts already goes through runProcess.

Verification

  • node config/scripts/run-typecheck-projects-in-parallel.mjs - exit 0
  • vitest run src/main/system-fonts.test.ts src/shared/secure-file.test.ts - 24 passed, 2 skipped
  • vitest run src/shared/child-process src/main/cli/wsl-cli-installer.test.ts src/main/cli/wsl-cli-powershell-boundary.test.ts src/main/cli/native-cli-powershell-argv-boundary.test.ts src/main/powershell-osc133-bootstrap.test.ts - 13 files, 128 passed, 4 skipped
  • oxlint on the four changed files - clean

oxfmt --check reports issues on every file in this checkout including untouched controls; write-mode output is CRLF -> LF only, so the gap is environmental and no formatting drift is introduced by this diff.

Out of scope

All owned by other agents and correctly excluded here:

Execution policy gates script *files* only; it has no effect on -Command.
Measured on Windows 11:

  powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Restricted \
    -Command "Write-Output 'COMMAND-RAN'"   -> COMMAND-RAN, exit 0

So the switch bought nothing on these two call sites while contributing the
highest-weighted token on the command lines Defender for Endpoint flags.

Font enumeration returns a byte-identical family list with and without the
switch (182 families, matching SHA-256), and the ACL script's argv behaves
identically either way.

Tests now assert the argv carries no -ExecutionPolicy/Bypass, and the
secure-file assertions derive the script position from -Command instead of a
fixed index so they cannot rot the next time the switch list moves.
@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 629f3622-58d4-4033-8a0f-a2255179a627

📥 Commits

Reviewing files that changed from the base of the PR and between ec030f1 and 2333ba5.

📒 Files selected for processing (2)
  • src/main/system-fonts.test.ts
  • src/main/system-fonts.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/system-fonts.ts
  • src/main/system-fonts.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Windows font discovery no longer passes -ExecutionPolicy Bypass to PowerShell. It retains -NoProfile, -NonInteractive, and -Command. A Windows-specific test verifies the updated arguments.

Merge Risk: ⚪ Minimal · up to 2333b

The Windows font-discovery PowerShell invocation removes an unnecessary execution-policy bypass while retaining command execution arguments and test coverage. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: removing the no-op -ExecutionPolicy Bypass flag from Windows PowerShell -Command spawns.
Description check ✅ Passed The description is detailed, focused, and covers the change, rationale, affected sites, regression tests, verification results, limitations, and out-of-scope items. Several template sections are absen…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Review follow-ups on the -ExecutionPolicy Bypass removal:

- powershellScriptArgs asserts the -Command anchor before slicing, so a
  -Command -> -File swap names the switch shape that moved instead of
  surfacing as a path mismatch several asserts later.
- Collapse both no-op rationale comments to one line per AGENTS.md.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Drop -ExecutionPolicy Bypass from the two Windows -Command spawns — removed the switch from font enumeration (src/main/system-fonts.ts) and ACL hardening (src/shared/secure-path-windows-acl.ts). Execution policy gates script files, never inline -Command text, so the switch was a provable no-op that only inflated the EDR/Defender score.
  • Regression tests — new cases in src/main/system-fonts.test.ts and src/shared/secure-file.test.ts assert -Command is present and -ExecutionPolicy/Bypass absent, and would fail against the old argv. The secure-file assertions now derive script and argument positions from indexOf('-Command') instead of hardcoded [5]/[6].
  • Correct scoping — the WSL -File site (src/main/cli/wsl-cli-scripts.ts) is left untouched with sound justification, since RemoteSigned rejects the \\wsl.localhost\ UNC path.

ℹ️ Pre-existing ACL hardening no-op is worth a dedicated follow-up issue

The change is correct and behavior-neutral. The PR's own note is accurate: restrictWindowsPathSync / bestEffortRestrictWindowsPath pass <path> <sid> <isDir> as trailing tokens after -Command, which concatenate into the command text instead of populating $args, so the script throws before applying anything and hardening silently no-ops (sync returns false, async swallows). This predates the PR and is not made worse by it, but it is a live security-hardening gap — recommend filing a tracking issue so it is not lost.

Technical details
# Track the Windows ACL hardening no-op

## Affected sites
- src/shared/secure-path-windows-acl.ts:16-21 — `-Command` receives trailing tokens that never reach `$args`; `WINDOWS_RESTRICT_ACL_SCRIPT` (lines 66-114) reads `$args[0..2]` and dies under `$ErrorActionPreference='Stop'`.

## Required outcome
- A follow-up issue/PR that makes the ACL actually apply, via `-File` on a packaged script or by moving `targetPath`/`sid`/`isDir` into the script text. Do not keep `-Command` with trailing arguments — populating them while keeping this spelling turns a dead no-op into command execution on a path string.

## Open questions for the human (optional)
- Is there already a tracking issue for this gap?

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Tightened -Command argv assertions — powershellScriptArgs in src/shared/secure-file.test.ts now asserts indexOf('-Command') >= 0 before slicing, so a future -Command → -File swap fails at the anchor instead of surfacing as a path mismatch several asserts later. This closes the gap between the PR description ("assert that anchor exists before slicing") and the prior code, which sliced unconditionally.
  • Comment cleanup — the two production comments (src/main/system-fonts.ts, src/shared/secure-path-windows-acl.ts) were condensed and the cross-reference removed; the reasoning (policy gates script files, not -Command) is unchanged.

Verified the two changed suites still pass (26 passed).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

The ACL hunks are obsolete: #17884 replaced the PowerShell ACL path with
icacls, so there is no ACL PowerShell left to strip a switch from. Took
main's side there; system-fonts.ts is the remaining live site.
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Merged origin/main, dropping the ACL half of the change — the branch's edits to src/shared/secure-path-windows-acl.ts and src/shared/secure-file.test.ts are gone from the diff because main migrated ACL hardening from a PowerShell -Command spawn to icacls.exe/whoami.exe. The PowerShell spawn this PR set out to clean up no longer exists, so those files and the associated regression test were correctly removed. The PR now touches only the font-enumeration spawn, which is byte-identical to the previously reviewed state.

ℹ️ PR description still documents the removed ACL site

The body's "Why Group A" table row, the WINDOWS_RESTRICT_ACL_SCRIPT evidence, and the "Notes for reviewers" pre-existing no-op all describe the secure-path-windows-acl.ts PowerShell spawn, which is no longer in the diff. The prior review's recommendation to file a follow-up for that no-op is now moot — the entire PowerShell ACL path was replaced by icacls.exe. Worth trimming the description before merge so reviewers aren't pointed at code that no longer runs.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit 8b88b3b into main Sep 6, 2026
27 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#17873)

* fix(windows): drop no-op -ExecutionPolicy Bypass from -Command spawns

Execution policy gates script *files* only; it has no effect on -Command.
Measured on Windows 11:

  powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Restricted \
    -Command "Write-Output 'COMMAND-RAN'"   -> COMMAND-RAN, exit 0

So the switch bought nothing on these two call sites while contributing the
highest-weighted token on the command lines Defender for Endpoint flags.

Font enumeration returns a byte-identical family list with and without the
switch (182 families, matching SHA-256), and the ACL script's argv behaves
identically either way.

Tests now assert the argv carries no -ExecutionPolicy/Bypass, and the
secure-file assertions derive the script position from -Command instead of a
fixed index so they cannot rot the next time the switch list moves.

* refactor(windows): tighten -Command argv assertions and comments

Review follow-ups on the -ExecutionPolicy Bypass removal:

- powershellScriptArgs asserts the -Command anchor before slicing, so a
  -Command -> -File swap names the switch shape that moved instead of
  surfacing as a path mismatch several asserts later.
- Collapse both no-op rationale comments to one line per AGENTS.md.

---------

Co-authored-by: Orca Worker <orca-worker@localhost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant