T09 · Insecure Skill Coding Practices
Note
- Location
scripts/cargo_toml_validator.py:899- Finding
Terminal Control-Sequence Injection Through Unsanitized Manifest Values
- Content
View full analysis
- Remediation
View remediation
str: text = str(value) return "".join( ch if ch in "\n\t" or ord(ch) >= 0x20 and ord(ch) != 0x7F else repr(ch)[1:-1] for ch in text ) ``` 2. Prefer escaping control characters visibly rather than silently removing them. For example, render an escape byte as `\x1b` so reviewers can identify malformed or hostile manifest values. 3. Sanitize data at the output boundary rather than relying only on individual validation rules. This ensures future rules cannot accidentally introduce the same issue: ```python message = sanitize_terminal(f["message"]) detail = sanitize_terminal(f.get("detail", "")) lines.append(f"[{sev}] {f['rule_id']}: {message}") if detail: lines.append(f" {detail}") ``` 4. Ensure the title and supplied file path are sanitized as well, because the path is also displayed in text output. 5. Consider providing a strict output mode that rejects manifest values containing terminal control characters. 6. Recommend JSON output for automated processing and untrusted manifests, while retaining proper sanitization in text and summary output. 7. Add regression tests using values containing ESC, BEL, carriage return, backspace, and OSC-like sequences. Verify that raw control bytes never appear in formatted text output. ]]>
