fix(tools): block MSYS and WSL shells under the Windows sandbox - #587
Conversation
Git-for-Windows bash.exe and sh.exe are MSYS binaries: the MSYS runtime secures its signal pipe and shared-memory sections with explicit DACLs granting only the user, Administrators, and SYSTEM (sigproc.cc sigproc_init -> sec_user_nih), so under the WRITE_RESTRICTED token the second access check can never pass and startup dies with "couldn't create signal pipe" or "CreateFileMapping <SID>.1", Win32 error 5. The System32 WSL bash launcher fails equivalently: the restricted token cannot connect to the WSL service (Bash/Service/CreateInstance/ E_ACCESSDENIED). Every executable a bare bash can resolve to fails, so block bash and sh preflight like the MSYS coreutils from Gitlawb#476, mention the indirect spawn paths (git hooks, git/gh credential helpers) in the shared suggestion, detect the WSL launcher's UTF-16LE service-denied stderr, and document the root cause in the runner's KNOWN LIMITATION comment beside the Schannel note.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR expands Windows sandbox restricted-token guidance and shell-runtime detection for MSYS2/Cygwin and WSL bash launcher failures, adds tests for the new detection paths, and updates one picker test for an expanded return signature. ChangesWindows Shell Sandbox Detection
Picker Test Signature Update
Estimated code review effort: 2 (Simple) | ~12 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
jatmn
left a comment
There was a problem hiding this comment.
please rebase on main and fix smoke issues.
|
Follow-up to #587 (review). Rebased on main and the smoke failures are fixed. @jatmn The original CHANGES_REQUESTED was driven by CI failing at internal/tui/picker_test.go:771. m.switchProviderModel gained a 4th return value and the test only captured 3, so go test/go vet aborted the whole internal/tui build. The actual PR change (MSYS/WSL shell blocking in internal/tools/shell_runtime.go) was fine. The break was a pre-existing caller that hadn't been updated. Fixed in d1c4a1f by aligning picker_test to the 4-value signature, on top of 45261a2 (the sandbox blocking work). Branch is rebased on upstream/main and all smoke/CI checks are green. Please mark resolved when you re-review. |
Review: PR #587Local run
BlockersNone. Suggestions (non-blocking)
SecurityStrengthens the sandbox. No bypass, no secret exposure. All changes Windows-only, Linux/macOS unaffected. TestsGood coverage. Minor gap: no dedicated |
gnanam1990
left a comment
There was a problem hiding this comment.
Reviewed locally: gofmt, go vet, go build, and affected tests all pass. Clean merge with main. Fixes a pre-existing compile error in picker_test.go. Changes are Windows-only, well-tested, and strengthen the sandbox. No blockers.
Vasanthdev2004
left a comment
There was a problem hiding this comment.
I reviewed the MSYS/WSL block. Failing closed when the detected shell is MSYS or a WSL shell-distribution is the right call — those shells break the sandbox's path/argv assumptions, and a silent passthrough would be worse than a clear refusal. The detection keys on the right environment markers and the error tells the user how to point at a native shell.
One nit before this merges: the diff carries a hunk in picker_test.go that updates the switchProviderModel call site from a 3-value to a 4-value return. That same fix is already pending on main as PR #589 (a recent merge added the bool return but missed that call site). Drop that hunk here — keeping it will collide with #589 once it lands, and it's redundant once main is fixed.
Heads up: main has that unrelated test-build break right now (PR #589 is the fix, queued for merge), so Smoke is red here too until that lands — not from this change. Approving once the picker_test hunk is dropped.
|
@gnanam1990 thanks for the review. Added the dedicated sh.exe case to TestDetectShellCommandIssueFlagsShells in ba23479, closing the test gap you noted. Leaving the two non-blocking suggestions (shell-specific blocking message, separate WSL detection kind) for a follow-up so this stays small. |
Git-for-Windows bash.exe and sh.exe are MSYS binaries: the MSYS runtime secures its signal pipe and shared-memory sections with explicit DACLs granting only the user, Administrators, and SYSTEM (sigproc.cc sigproc_init -> sec_user_nih), so under the WRITE_RESTRICTED token the second access check can never pass and startup dies with "couldn't create signal pipe" or "CreateFileMapping .1", Win32 error 5. The System32 WSL bash launcher fails equivalently: the restricted token cannot connect to the WSL service (Bash/Service/CreateInstance/ E_ACCESSDENIED).
Every executable a bare bash can resolve to fails, so block bash and sh preflight like the MSYS coreutils from #476, mention the indirect spawn paths (git hooks, git/gh credential helpers) in the shared suggestion, detect the WSL launcher's UTF-16LE service-denied stderr, and document the root cause in the runner's KNOWN LIMITATION comment beside the Schannel note.
Changes
Summary by CodeRabbit
bash/shcases and WSL-denied output shapes, plus a small TUI picker test adjustment.