Repository navigation
fix(windows): drop no-op -ExecutionPolicy Bypass from -Command spawns - #17873
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughWindows font discovery no longer passes Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Drop
-ExecutionPolicy Bypassfrom the two Windows-Commandspawns — 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-Commandtext, 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.tsandsrc/shared/secure-file.test.tsassert-Commandis present and-ExecutionPolicy/Bypassabsent, and would fail against the old argv. The secure-file assertions now derive script and argument positions fromindexOf('-Command')instead of hardcoded[5]/[6]. - Correct scoping — the WSL
-Filesite (src/main/cli/wsl-cli-scripts.ts) is left untouched with sound justification, sinceRemoteSignedrejects 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?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Tightened
-Commandargv assertions —powershellScriptArgsinsrc/shared/secure-file.test.tsnow assertsindexOf('-Command') >= 0before slicing, so a future-Command→-Fileswap 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).
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.
|
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. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Merged
origin/main, dropping the ACL half of the change — the branch's edits tosrc/shared/secure-path-windows-acl.tsandsrc/shared/secure-file.test.tsare gone from the diff because main migrated ACL hardening from a PowerShell-Commandspawn toicacls.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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…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>

What
Removes
-ExecutionPolicy Bypassfrom 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 Bypassis the single highest-weighted token on the command lines in the report.src/main/system-fonts.ts-Commandsrc/shared/secure-path-windows-acl.ts-Commandsrc/main/cli/wsl-cli-scripts.ts-Fileon a\\wsl.localhost\UNC pathWhy Group A is zero-risk:
-Commandis not execution-policy gatedExecution policy governs script files. It has no bearing on
-Command. Measured on Windows 11 Pro 26200, Windows PowerShell 5.1:The contrast case, same box, an unsigned
.ps1via-File:So on a
-Commandline 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:Byte-identical output.
secure-path-windows-acl.ts- the realWINDOWS_RESTRICT_ACL_SCRIPTdriven throughexecFileSyncwith 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 unchangedThe WSL launcher runs
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$ORCA_BRIDGE_PS1_WIN", where$ORCA_BRIDGE_PS1_WINcomes fromwslpath -wover a path inside the distro's Linux filesystem. On WSL2 that is a UNC path, andRemoteSignedrejects it. Measured, Ubuntu-24.04:Downgrading that site to
RemoteSignedwould breakorcafrom 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:Bypass, not the switch. The measured default effective policy on this box isRestricted, and flagless-Fileon a local%TEMP%script still fails. The follow-up target is-ExecutionPolicy RemoteSigned, which passes on local paths with no signing.\\wsl$\spelling also passesRemoteSigned- 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-Commandand neither-ExecutionPolicynorBypass.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 fromindexOf('-Command')and assert that anchor exists before slicing, so a-Command->-Fileswap names the switch shape that moved instead of surfacing as a path mismatch several asserts later.Notes for reviewers (found, deliberately not fixed here)
bestEffortRestrictWindowsPath/restrictWindowsPathSyncdo not currently apply any ACL. They pass-Command <script> <path> <sid> <isDir>, but-Commanddoes not populate$args. It concatenates the trailing tokens into the script text, where they execute as a statement. Measured:$argsis empty, andAAA/BBBare not discarded - they land inside the script text and run.The real script therefore dies at
$allowedSids[$sidText] = $truewithNullArrayIndexbecause$args[1]is$null.$ErrorActionPreference = 'Stop'makes that exit 1, the sync path returnsfalse, 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 -
-Fileon a packaged script, or moving the values into the script text, not a repair that leaves-Commandwith trailing arguments.src/shared/secure-path-windows-acl.tscallsnode:child_processexecFile/execFileSyncdirectly rather thanrunProcess/spawnProcess. It is a pre-existing entry inchild-process-import-allowlist.txt; not touched here.system-fonts.tsalready goes throughrunProcess.Verification
node config/scripts/run-typecheck-projects-in-parallel.mjs- exit 0vitest run src/main/system-fonts.test.ts src/shared/secure-file.test.ts- 24 passed, 2 skippedvitest 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 skippedoxlinton the four changed files - cleanoxfmt --checkreports 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:
src/main/computer/desktop-script-provider-bridge.ts:17-19--Fileon a real.ps1, so genuinely policy-gated; already fixed in fix(computer-use): run the Windows runtime as one persistent helper #17858.src/relay/windows-port-scan.ts- already fixed in fix(windows): scan ports natively instead of encoded PowerShell #17861.src/main/agent-hooks/windows-powershell-hook-launcher.tsand everything underwrapWindowsPowerShellEncodedCommand- flag shape is load-bearing and backed by measured AV data ([Bug]: Claude Code agent-hooks (claude-hook.cmd) fail with "Permission denied" when invoked by the hook runner #16003, fix(agent-hooks): stop the Windows hook launcher spelling the AV-denied flag triple #16576).src/main/daemon/shell-ready.ts,src/main/providers/local-pty-shell-ready.ts,src/main/providers/windows-shell-args.ts.-EncodedCommandsites:src/shared/setup-agent-sequencing.ts,src/shared/windows-cmd-runner-delayed-launch.ts,src/main/ssh/ssh-remote-powershell.ts,src/shared/windows-interactive-login-spawn.ts:84, and the mobile firewall site.