T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:336- Finding
Terminal Control-Sequence Injection Through Unsanitized Diagnostic Input
- Content
View full analysis
- Remediation
View remediation
= 0x20 else f"\\x{ord(ch):02x}" for ch in value ) ``` 2. Apply the sanitizer before substituting captured groups: ```python safe_group = sanitize_terminal(g or "") f = f.replace(f"{{match{j}}}", safe_group) ``` 3. Sanitize direct output: ```python print(f" Detected keyword: {CYAN}{sanitize_terminal(line.strip())}{RESET}") print(f"\n{BOLD}📖 Error Code: {sanitize_terminal(text)}{RESET}") ``` 4. Consider replacing ESC (`0x1b`), C0/C1 controls, DEL, carriage returns, and other non-printable characters with explicit escaped representations. A production implementation should account for complete CSI and OSC sequence forms rather than relying only on a narrow regular expression. 5. Enable color output only when `sys.stdout.isatty()` is true, and provide a `--no-color` or safe plain-text mode. 6. Add regression tests using ANSI CSI sequences, OSC title changes, OSC 8 hyperlinks, OSC 52 clipboard sequences, carriage returns, backspaces, and mixed multiline input to verify that attacker-controlled bytes are displayed literally rather than interpreted. ]]>
