-
Notifications
You must be signed in to change notification settings - Fork 2
fix: consolidated bug fixes and security improvements #91
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
base: main
Are you sure you want to change the base?
Conversation
Greptile OverviewGreptile SummaryThis PR consolidates critical security fixes and robustness improvements from multiple previous PRs into a single cohesive change. The changes address security vulnerabilities, prevent resource exhaustion, and improve error handling across the codebase. Key ChangesSecurity Hardening
Memory and Resource Management
Data Durability
Error Handling
Numeric Safety
TestingAll changes include comprehensive test coverage, including tests for edge cases like path traversal attempts, quote bypasses, and multi-byte UTF-8 handling. Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/cortex-tui/src/mcp_storage.rs | Added path traversal prevention by sanitizing server names before filesystem operations |
| src/cortex-tui/src/session/storage.rs | Added path traversal prevention and fsync after writes for crash safety and durability |
| src/cortex-tui/src/external_editor.rs | Replaced predictable temp file names with cryptographically secure random names to prevent symlink attacks |
| src/cortex-shell-snapshot/src/snapshot.rs | Added shell escaping for paths containing single quotes to prevent shell injection in restore scripts |
| src/cortex-engine/src/tools/response_store.rs | New bounded storage for tool responses with automatic cleanup to prevent unbounded memory growth |
| src/cortex-engine/src/validation.rs | Added command normalization to prevent validation bypasses via quotes, paths, and extra whitespace |
| src/cortex-common/src/file_locking.rs | Added automatic cleanup of stale lock entries to prevent memory leaks in long-running processes |
| src/cortex-engine/src/streaming.rs | Added buffer size limits and saturating conversions for token counts to prevent overflow and unbounded growth |
| src/cortex-mcp-server/src/server.rs | Fixed TOCTOU race condition by holding write lock during state check and modification |
| src/cortex-plugins/src/registry.rs | Fixed TOCTOU race using HashMap entry API for atomic check-and-insert operations |
Sequence Diagram
sequenceDiagram
participant User
participant TUI
participant Storage
participant Engine
participant MCP
Note over TUI,Storage: Security Layer
User->>TUI: Request external editor
TUI->>TUI: Generate cryptographically secure temp file (TOCTOU fix)
TUI-->>User: Opens editor safely
User->>TUI: Request session save
TUI->>Storage: Sanitize session ID (path traversal prevention)
Storage->>Storage: Write with atomic rename
Storage->>Storage: fsync() for crash safety
Storage-->>TUI: Session saved durably
User->>Engine: Execute tool with large dataset
Engine->>Engine: Check ToolResponseStore bounds (MAX_STORE_SIZE)
Engine->>Engine: Evict oldest if at capacity
Engine-->>User: Response (memory bounded)
User->>Engine: Stream processing
Engine->>Engine: Check buffer limits (MAX_BUFFER_SIZE)
Engine->>Engine: Saturating token conversions
Engine-->>User: Stream events (overflow prevented)
User->>MCP: Initialize server
MCP->>MCP: Atomic state check-and-transition (TOCTOU fix)
MCP-->>User: Server initialized
Note over Engine: Command Validation
User->>Engine: Execute bash command
Engine->>Engine: Normalize command (bypass prevention)
Engine->>Engine: Check against blocked patterns
alt Command allowed
Engine-->>User: Execute safely
else Command blocked
Engine-->>User: Validation error
end
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.
10 files reviewed, no comments
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
1e4adb3 to
535de7b
Compare
Summary
This PR consolidates all bug fixes and security improvements from PRs #69-88 into a single cohesive change.
Security Fixes
TUI Improvements
Error Handling
Memory and Storage
Protocol Robustness
Numeric Safety
Tools
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