Repository navigation
Conversation
Greptile SummaryThis PR adds a safe Windows bypass for
Confidence Score: 5/5Safe to merge — the new PowerShell shim path is opt-in on the local side and correctly isolated to Windows batch scripts with unsafe args on the relay side; all other platforms and safe-arg invocations are unaffected. The two previously flagged issues (wrong env consulted for SystemRoot and duplicated shim logic) are both resolved by the shared module. The shim resolver uses only the caller-supplied env, validates SystemRoot as an absolute drive path, checks sibling existence before use, and falls back safely to the existing rejection when no .ps1 is present. Tests cover all key paths. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/shared/windows-powershell-shim-spawn.ts | New shared module that resolves a sibling .ps1 shim and builds PowerShell argv; correctly uses the passed env for SystemRoot, validates the path as an absolute drive root, and guards against a missing sibling. |
| src/shared/windows-batch-spawn.ts | Adds opt-in allowPowerShellShimFallback + env options; on the first unsafe arg it tries the shared shim resolver before throwing, cleanly preserving the existing rejection path when no sibling .ps1 exists. |
| src/relay/agent-exec-handler.ts | Relay's getWindowsSafeSpawn now delegates to the shared getWindowsPowerShellShimSpawn (with the merged spawnEnv) for unsafe args, fixing the previously flagged env-propagation gap and deduplication issue. |
| src/main/text-generation/commit-message-text-generation.ts | Passes allowPowerShellShimFallback: true and the merged spawnEnv into getSpawnArgsForWindows so multiline prompts can use the PS1 shim path on Windows. |
| src/relay/agent-exec-handler-windows.test.ts | Adds an end-to-end relay test: creates real .cmd/.ps1 temp files, sends multiline args over the relay handler, and asserts the resulting spawn targets the correct PowerShell path with the client-supplied SystemRoot. |
| src/main/text-generation/commit-message-text-generation.test.ts | New integration test exercises the full local-generation path with a multiline staged patch, verifying the PS1 shim is selected and the prompt text reaches the last spawn argument. |
| src/main/win32-utils.test.ts | Adds unit tests for both the safe-args cmd.exe path and the unsafe-args PowerShell shim fallback through getSpawnArgsForWindows, including SystemRoot propagation. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Spawn request with binary + args] --> B{Windows platform?}
B -- No --> Z[spawn binary directly]
B -- Yes --> C[resolveWindowsCommand via PATH]
C --> D{Is .cmd / .bat script?}
D -- No --> Z
D -- Yes --> E{Any unsafe batch metachar in command or args?}
E -- No --> F[cmd.exe /d /c command args]
E -- Yes --> G[getWindowsPowerShellShimSpawn: replace ext to .ps1]
G --> H{sibling .ps1 exists on disk?}
H -- Yes --> I[Build SystemRoot from env.SystemRoot/WINDIR, fallback C:\Windows]
I --> J[powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File shim.ps1 args]
H -- No --> K{allowPowerShellShimFallback path}
K -- relay always-on --> L[fall through to quoteWindowsBatchToken, throws]
K -- local opt-in fallback=false --> M[throw UnsafeWindowsBatchArgumentsError]
Reviews (7): Last reviewed commit: "style: format Windows shim tests" | Re-trigger Greptile
|
Important Review skippedWe couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughWindows batch execution now supports PowerShell shim fallback when arguments contain unsafe syntax. The fallback validates sibling 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/relay/agent-exec-handler-windows.test.ts (1)
128-128: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest doesn't actually discriminate the
envvs.process.envbug.Using
env: { SystemRoot: 'C:\\Windows' }— the same value the code's hardcoded fallback would produce anyway — means this assertion passes even with theprocess.env-based bug flagged ingetWindowsSafeSpawn(lines 66-85). Use aSystemRootvalue that differs from the fallback default (e.g.,'D:\\Windows') to make this test actually catch the regression once fixed.Also applies to: 136-136
src/main/text-generation/commit-message-text-generation.test.ts (1)
1742-1746: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest doesn't discriminate the missing
envforwarding.The custom
env.SystemRoot: 'C:\\Windows'matches the code's hardcoded fallback, so this test would still pass even with theenv: spawnEnvomission flagged incommit-message-text-generation.ts(lines 581-583). Use a distinguishingSystemRootvalue to make this assertion meaningful.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6560e804-a33b-4d6e-9807-8c3e638ac998
📥 Commits
Reviewing files that changed from the base of the PR and between 4543bb6 and 1cc5c3a135e6f73d14504026f76ea926f0096f75.
📒 Files selected for processing (6)
src/main/text-generation/commit-message-text-generation.test.tssrc/main/text-generation/commit-message-text-generation.tssrc/main/win32-utils.test.tssrc/main/win32-utils.tssrc/relay/agent-exec-handler-windows.test.tssrc/relay/agent-exec-handler.ts
|
Thanks for putting this together. I tested this PR's head ( Results:
Process inspection confirmed that the sibling PowerShell shim was used:
For completeness, a 31,605-character patch / 32,143-character prompt reached the Windows command-line limit and failed with |
a720d0b to
5f2e399
Compare
|
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0cacec40-8440-4a91-9657-a3fccf6f19cf
📥 Commits
Reviewing files that changed from the base of the PR and between 9507cbc and 5f2e399e63c5440358a180a25f6a9c65d9190f8d.
📒 Files selected for processing (7)
src/main/text-generation/commit-message-text-generation.test.tssrc/main/text-generation/commit-message-text-generation.tssrc/main/win32-utils.test.tssrc/relay/agent-exec-handler-windows.test.tssrc/relay/agent-exec-handler.tssrc/shared/windows-batch-spawn.tssrc/shared/windows-powershell-shim-spawn.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/text-generation/commit-message-text-generation.ts
- src/shared/windows-powershell-shim-spawn.ts
- src/main/win32-utils.test.ts
5f2e399 to
59567e7
Compare
|
I picked up #11374 from the issue queue, found this PR already open on the same seam, and stopped rather than open a competing one. Here is everything I worked out, so it is useful to you rather than duplicated. Short version: the sibling- Confirming what this covers, with measurementsI measured the current
Two things fall out of that:
The two gaps, preciselyPer @iFwu's live results and the scope note, this stays open for:
A design for closing both, as a follow-up on top of thisKeep your sibling- $shim = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('<b64 of the .ps1 path>'))
$argv = @(foreach ($item in @('<b64>','<b64>',…)) {
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($item))
})
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false
$OutputEncoding = [Console]::OutputEncoding
& $shim @argv
exit $LASTEXITCODEWhy base64 rather than quoting — this is the non-obvious part, and it is what makes the fix durable rather than another round of escaping whack-a-mole. Three separate parsers get a look at anything written on a Windows command line, and they disagree:
Base64 sidesteps all three at once: every byte that reaches a command line is This does not close the Caveats on all of the aboveI have no Windows host. Everything above is either arithmetic, a platform-pinned unit measurement, or reasoning from the parser behaviour already documented in Happy to build the follow-up once this lands, or to hand the design over if you would rather carry it yourself. Either way this PR is the dependency, not the competitor. |
|
Thanks for stopping instead of opening a competing PR, and for writing the measurements down. This PR stays the sibling-
So the seam you confirmed is still the one that needs to land. I am not opening another PR on it. I am not folding extra work into this head right now. Head On the two follow-ups:
@iFwu's live If you or Brennan would rather rebase this yourselves, I will stay comments-only. If you want me to port the sibling- |
59567e7 to
e551983
Compare
e551983 to
5dbfc6f
Compare
5dbfc6f to
8baf3a6
Compare
Summary
When a Windows source-control agent or relay agent execution resolves to a batch shim, multiline or cmd-sensitive arguments currently fail the batch-argument safety check. These two paths now use an existing sibling
.ps1throughpowershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File, passing the original arguments separately.The fallback is opt-in. Safe batch arguments retain the existing cmd path; missing sibling PowerShell shims still reject unsafe arguments. Other callers, including external editors, Git and setup runners, retain their existing behavior. No
-Commandconcatenation, temporary-script fallback or command-length expansion is introduced. The Windows overall command-line length ceiling remains a limitation.Testing and review
At
e551983779f5bc03743e0bcc66da300dda19deac, independent verification passed 172 tests across 19 files, including source-control subprocess planning, the Windows helper and relay agent execution. CLI, Node and Web TypeScript (--composite false), all changed-file lint/format, diff whitespace and native preflight/postflight passed. Two independent Cursor security reviews passed on this exact commit.Tests cover opt-in scope, a sibling present with the default flag disabled, missing sibling rejection, fixed PowerShell flags and preservation of multiline/metacharacter arguments. Checks ran on macOS with platform-pinned tests. Actual Windows/SSH execution, full repository tests and packaging were not run on this commit. Earlier Windows field results in the discussion are historical, not validation inherited by this head.
AI disclosure
Cursor ported and independently security-reviewed the change. Codex independently checked the original scope, current code, reviewer transcripts and validation results.