-
Notifications
You must be signed in to change notification settings - Fork 3
fix: consolidated security and robustness improvements #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR consolidates the following fixes: - #74: Prevent shell injection in restore_script via path escaping - #76: Replace unsafe unwrap() with expect() in init_client - #78: Use secure random temp files in external editor to prevent symlink attacks - #79: Add per-chunk streaming timeout to prevent indefinite hangs Key changes: - Added shell escaping for paths in shell-snapshot restore scripts - Replaced unwrap() with expect() for better error context in exec runner - Use secure random temp files instead of predictable names - Added streaming chunk timeout to prevent hangs during LLM responses
Greptile OverviewGreptile SummaryThis PR consolidates four well-implemented security and robustness improvements into a single cohesive change. Key improvements:
All changes are well-documented, include appropriate tests, and follow Rust security best practices. Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/cortex-shell-snapshot/src/snapshot.rs | added shell_escape_path function to prevent shell injection in restore scripts, with comprehensive test coverage |
| src/cortex-exec/src/runner.rs | replaced unwrap with expect for better error context, added per-chunk streaming timeout to prevent indefinite hangs |
| src/cortex-tui/src/external_editor.rs | replaced predictable temp filenames with secure random temp files using tempfile crate to prevent symlink attacks |
| src/cortex-tui/Cargo.toml | added tempfile dependency for secure temp file creation |
Sequence Diagram
sequenceDiagram
participant User
participant TUI as Cortex TUI
participant ExecRunner
participant ShellSnapshot
participant LLMProvider
participant TempFile as Temp File System
Note over User,TempFile: Security Improvements in Action
User->>TUI: Press Ctrl+G for external editor
TUI->>TempFile: Create secure temp file<br/>(random 16-byte suffix)
TempFile-->>TUI: Secure file handle with O_EXCL
Note over TUI,TempFile: Prevents symlink attacks
TUI->>TUI: Open editor with temp file
User->>TUI: Edit and save content
TUI->>TempFile: Read edited content
TUI->>TempFile: Delete temp file securely
User->>ExecRunner: Execute LLM request
ExecRunner->>ExecRunner: init_client()
Note over ExecRunner: Uses expect() for<br/>better error context
ExecRunner->>LLMProvider: Start streaming request
loop For each chunk (30s timeout)
LLMProvider->>ExecRunner: Stream response chunk
Note over ExecRunner,LLMProvider: Per-chunk timeout<br/>prevents indefinite hangs
ExecRunner->>ExecRunner: Process chunk
end
LLMProvider->>ExecRunner: Complete response
ExecRunner->>ShellSnapshot: Generate restore script
ShellSnapshot->>ShellSnapshot: shell_escape_path()
Note over ShellSnapshot: Escapes single quotes<br/>using '"'"' technique
ShellSnapshot-->>ExecRunner: Safe shell script
ExecRunner-->>User: Return result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, no comments
|
Closing this PR to consolidate into a single mega-PR combining all bug fixes. The changes will be included in a new consolidated PR. |
This PR consolidates all bug fixes and security improvements from PRs #69-88 into a single cohesive change. ## Categories ### Security Fixes - Path traversal prevention in MCP and session storage - Shell injection prevention in restore scripts - Secure random temp files for external editor - TOCTOU race condition fixes ### TUI Improvements - Overflow prevention for u16 conversions - Cursor positioning fixes in selection lists - Unicode width handling for popups - Empty section handling in help browser ### Error Handling - Graceful semaphore and init failure handling - Improved error propagation in middleware - Better client access error handling - SystemTime operation safety ### Memory and Storage - Cache size limits to prevent unbounded growth - File lock cleanup for memory leak prevention - fsync after critical writes for durability - Bounded ToolResponseStore with automatic cleanup ### Protocol Robustness - Buffer size limits for StreamProcessor - ToolState transition validation - State machine documentation ### Numeric Safety - Saturating operations to prevent overflow/underflow - Safe UTF-8 string slicing throughout codebase ### Tools - Parameter alias support for backward compatibility - Handler name consistency fixes ## Files Modified Multiple files across cortex-tui, cortex-engine, cortex-exec, cortex-common, cortex-protocol, cortex-storage, cortex-mcp-server, and other crates. Closes #69, #70, #71, #73, #75, #80, #82, #87, #88
This PR consolidates all bug fixes and security improvements from PRs #69-88 into a single cohesive change. ## Categories ### Security Fixes - Path traversal prevention in MCP and session storage - Shell injection prevention in restore scripts - Secure random temp files for external editor - TOCTOU race condition fixes ### TUI Improvements - Overflow prevention for u16 conversions - Cursor positioning fixes in selection lists - Unicode width handling for popups - Empty section handling in help browser ### Error Handling - Graceful semaphore and init failure handling - Improved error propagation in middleware - Better client access error handling - SystemTime operation safety ### Memory and Storage - Cache size limits to prevent unbounded growth - File lock cleanup for memory leak prevention - fsync after critical writes for durability - Bounded ToolResponseStore with automatic cleanup ### Protocol Robustness - Buffer size limits for StreamProcessor - ToolState transition validation - State machine documentation ### Numeric Safety - Saturating operations to prevent overflow/underflow - Safe UTF-8 string slicing throughout codebase ### Tools - Parameter alias support for backward compatibility - Handler name consistency fixes ## Files Modified Multiple files across cortex-tui, cortex-engine, cortex-exec, cortex-common, cortex-protocol, cortex-storage, cortex-mcp-server, and other crates. Closes #69, #70, #71, #73, #75, #80, #82, #87, #88
Summary
This PR consolidates 4 security and robustness fixes into a single, cohesive change.
Included PRs:
Key Changes:
unwrap()withexpect()for better error context in exec runnerFiles Modified:
src/cortex-shell-snapshot/src/snapshot.rssrc/cortex-exec/src/runner.rssrc/cortex-tui/Cargo.tomlsrc/cortex-tui/src/external_editor.rsCloses #74, #76, #78, #79