Security fixes#347
Merged
Merged
Conversation
Add ErrEmptyResponse sentinel error and bounds checking for resp.Choices[0] in both streaming and non-streaming API response handlers. Non-streaming path returns an error for empty choices array, while streaming path uses continue to skip empty chunks (which may occur as heartbeats). Prevents index out of bounds panics when OpenAI API returns responses with no choices.
Add SanitizeCommand function to remove: - ANSI escape sequences (CSI and OSC) - Unicode bidirectional override characters - Zero-width characters (U+200B-D, U+FEFF) - Non-printable control characters (preserving newlines and tabs) Apply sanitization in ExecuteCommandWithConfirmation before displaying the command to the user and executing it. This ensures what-you-see-is-what- executes (WYSIWYG) and prevents display-based command injection attacks where malicious Unicode or ANSI sequences could hide dangerous commands.
Add r.exit(1) call in the panic recovery handler. Previously, panics were logged but the program would continue executing and exit with code 0, masking critical failures. Now ensures that any panic results in a non-zero exit code, providing proper error signaling to the calling process.
Implement Unwrap() method on exitError to enable proper error chain traversal with errors.Is() and errors.As(). This allows callers to inspect wrapped errors and maintains Go 1.13+ error handling best practices.
Add scanner.Err() check after the scanning loop in GetSession. Previously, scanner errors (such as lines exceeding bufio.MaxScanTokenSize) were silently ignored, potentially returning incomplete or corrupt session data. Now properly propagates scanner errors to the caller. Follows the same pattern used in pkg/fs/fs.go for consistent error handling.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #347 +/- ##
==========================================
+ Coverage 75.80% 78.63% +2.82%
==========================================
Files 20 20
Lines 1298 1072 -226
==========================================
- Hits 984 843 -141
+ Misses 226 145 -81
+ Partials 88 84 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Remove trailing empty lines in api_test.go and shell_test.go - Align comment spacing in shell.go for consistency
Owner
|
Thanks for finding and fixing these security issues! |
tbckr
pushed a commit
that referenced
this pull request
Feb 18, 2026
* fix: guard against empty API response choices to prevent panic Add ErrEmptyResponse sentinel error and bounds checking for resp.Choices[0] in both streaming and non-streaming API response handlers. Non-streaming path returns an error for empty choices array, while streaming path uses continue to skip empty chunks (which may occur as heartbeats). Prevents index out of bounds panics when OpenAI API returns responses with no choices. * fix: sanitize shell commands to prevent display manipulation Add SanitizeCommand function to remove: - ANSI escape sequences (CSI and OSC) - Unicode bidirectional override characters - Zero-width characters (U+200B-D, U+FEFF) - Non-printable control characters (preserving newlines and tabs) Apply sanitization in ExecuteCommandWithConfirmation before displaying the command to the user and executing it. This ensures what-you-see-is-what- executes (WYSIWYG) and prevents display-based command injection attacks where malicious Unicode or ANSI sequences could hide dangerous commands. * fix: exit with non-zero code on panic recovery Add r.exit(1) call in the panic recovery handler. Previously, panics were logged but the program would continue executing and exit with code 0, masking critical failures. Now ensures that any panic results in a non-zero exit code, providing proper error signaling to the calling process. * fix: add Unwrap method to exitError for error chain traversal Implement Unwrap() method on exitError to enable proper error chain traversal with errors.Is() and errors.As(). This allows callers to inspect wrapped errors and maintains Go 1.13+ error handling best practices. * fix: check scanner error after reading chat session file Add scanner.Err() check after the scanning loop in GetSession. Previously, scanner errors (such as lines exceeding bufio.MaxScanTokenSize) were silently ignored, potentially returning incomplete or corrupt session data. Now properly propagates scanner errors to the caller. Follows the same pattern used in pkg/fs/fs.go for consistent error handling. * style: remove trailing newlines and fix comment alignment - Remove trailing empty lines in api_test.go and shell_test.go - Align comment spacing in shell.go for consistency
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.
Please see commit messages