(#2377) fix(shell): sanitize terminal-facing output and harden path checks#2378
(#2377) fix(shell): sanitize terminal-facing output and harden path checks#2378vjanelle wants to merge 1 commit intosipeed:mainfrom
Conversation
…path checks Harden terminal-facing output in the exec tool and logger by escaping control and format characters before they reach the console or LLM-facing output. Refine exec workspace path validation so normalized relative paths inside the working directory remain allowed while real escapes are blocked. - [x] 🐞 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 📖 Documentation update - [ ] ⚡ Code refactoring (no functional changes, no api changes) - [ ] 🤖 Fully AI-generated (100% AI, 0% Human) - [x] 🛠️ Mostly AI-generated (AI draft, Human verified/modified) - [ ] 👨💻 Mostly Human-written (Human lead, AI assisted or none) N/A - **Reference URL:** N/A - **Reasoning:** Raw ANSI escape sequences and Unicode bidi overrides should not be able to alter operator terminal state. The previous workspace guard also rejected any path containing `../` even when the normalized path still resolved inside the working directory. - **Hardware:** PC - **OS:** Linux - **Model/Provider:** GPT-5.2 / OpenAI codex - **Channels:** internal terminal / exec tool usage <details> <summary>Click to view Logs/Screenshots</summary> - Added tests for ANSI and bidi escaping in terminal-facing output - Added tests for allowing normalized in-workspace relative traversal - Added tests for blocking relative traversal that escapes the working directory </details> - [x] My code/docs follow the style of this project. - [x] I have performed a self-review of my own changes. - [ ] I have updated the documentation accordingly.
yinwm
left a comment
There was a problem hiding this comment.
Great work on hardening the terminal output and path validation! The overall approach is solid. I have a few items that need attention before this can be merged:
Blocking:
- Merge conflict + Linter failure — Please rebase onto latest
mainand fix the lint errors. - C1 control characters gap —
EscapeControlCharsdoesn't catch C1 control characters (U+0080–U+009F). In UTF-8 these are encoded as0xC2 0x80–0xC2 0x9F. While most modern terminals use 7-bit CSI, some still interpret 8-bit C1 codes (e.g.,0x9B= CSI). Consider addingr >= 0x80 && r <= 0x9fto the escape condition.
Please verify:
3. Logger Component color in TTY mode — FormatPrepare injects ANSI color codes into the Component field (\x1b[33m...\x1b[0m), but formatFieldValue now calls EscapeControlChars on all field values. If zerolog's ConsoleWriter calls FormatFieldValue for the Component part, the injected color codes will be escaped to literal text. Could you verify this doesn't break TTY color output?
Non-blocking suggestions:
4. Consider adding dedicated unit tests for EscapeControlChars in pkg/termutil/ covering C0, C1, DEL, bidi, zero-width chars, and edge cases.
5. Shell variable expansion (\/../path) can theoretically bypass the path traversal check since filepath.Abs treats \ as a literal directory name. This is low-risk given the AI agent context, but worth documenting as a known limitation.
|
Additional finding from deeper review: Timeout path bypasses EscapeControlChars — In The fix is straightforward: apply |
|
@yinwm any opinions about ZWJ and complex emoji? |
Harden terminal-facing output in the exec tool and logger by escaping control and format characters before they reach the console or LLM-facing output. Refine exec workspace path validation so normalized relative paths inside the working directory remain allowed while real escapes are blocked.
Type of change
🤖 AI Code Generation
N/A
Reference URL: N/A
Reasoning: Raw ANSI escape sequences and Unicode bidi overrides should not be able to alter operator terminal state. The previous workspace guard also rejected any path containing
../even when the normalized path still resolved inside the working directory.Hardware: PC
OS: Linux
Model/Provider: GPT-5.2 / OpenAI codex
Channels: internal terminal / exec tool usage
Click to view Logs/Screenshots