Security: ExecApprovalPolicy bypass, thread safety, dispose races#62
Merged
shanselman merged 2 commits intomasterfrom Mar 18, 2026
Merged
Security: ExecApprovalPolicy bypass, thread safety, dispose races#62shanselman merged 2 commits intomasterfrom
shanselman merged 2 commits intomasterfrom
Conversation
…races Triple-model review (Opus, Codex, Gemini) identified 3 consensus issues: 1. ExecApprovalPolicy bypass (CRITICAL): When system.run received an argv array like ["rm", "-rf", "/"], only argv[0] was evaluated against policy rules. Now builds full command string via FormatExecCommand before policy evaluation, so rules like "rm *" correctly match. 2. Thread safety (_sessions/_nodes): Plain Dictionary accessed from both the background WebSocket listen loop and UI thread via GetSessionList(). Added lock(_sessionsLock) and lock(_nodesLock) following the existing _pendingRequestLock pattern. Events fired outside locks to avoid deadlock. 3. SendRawAsync TOCTOU + Dispose race: SendRawAsync now captures a local WebSocket reference before state check (prevents NullReferenceException during reconnect). Dispose no longer calls _cts.Dispose() while the listen loop may still reference it, matching WindowsNodeClient pattern. Includes 3 new tests for array-style command policy evaluation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Each finding was independently validated by a different AI model: 1. CanvasCapability arbitrary file read (Opus→Codex confirmed): jsonlPath now restricted to system temp directory via Path.GetFullPath validation. Blocks path traversal attacks. Added 2 security tests. 2. ChannelHealth DisplayText mismatch (Opus→Codex confirmed): Added 'active' to the '[ON]' case in DisplayText switch to match IsHealthyStatus which already considers 'active' healthy. 3. OnSettingsSaved dual connection (Codex→Opus confirmed): Now mirrors startup if/else pattern — only initializes operator OR node connection, never both. Prevents gateway conflicts. 4. Canvas TryEnqueue hang (Codex→Opus confirmed): OnCanvasEval/OnCanvasSnapshot now check TryEnqueue return value and fail the TaskCompletionSource immediately if dispatch unavailable. Rejected findings (false positives): - Operator precedence in HandleExecApprovalsSet (safe by coincidence) - WebSocket receive loop blocked (no cancel protocol exists) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Triple-Model Consensus Security Fixes
Identified by independent reviews from Claude Opus, GPT Codex, and Gemini - issues where 2+ models agreed.
1. ExecApprovalPolicy bypass (CRITICAL)
When system.run received an argv array like ["rm", "-rf", "/"], only argv[0] was evaluated against policy rules. Rules like "rm *" would not match.
Fix: Build full command string via FormatExecCommand before policy evaluation.
2. Thread safety - _sessions/_nodes dictionaries (Opus + Gemini)
Plain Dictionary accessed from both background WebSocket listen loop and UI thread. Could crash with InvalidOperationException.
Fix: Added lock(_sessionsLock) and lock(_nodesLock) following existing _pendingRequestLock pattern.
3. SendRawAsync TOCTOU + Dispose race (Opus)
SendRawAsync used _webSocket directly after null-check. Dispose called _cts.Dispose() while listen loop still running.
Fix: Applied defensive patterns from WindowsNodeClient: local ws capture, try-catch, skip _cts.Dispose().
Tests