fix(security): strip terminal control chars from untrusted session fields#191
Merged
stephenleo merged 2 commits intoJun 28, 2026
Merged
Conversation
…elds Claude Code session JSON embeds attacker-influenced strings (directory names, model display names, vim mode, agent name, etc.). A malicious repo can name a directory with raw ESC sequences (JSON-escaped as �); cship rendered these verbatim to stdout, where the terminal interprets them — enabling window-title spoofing, cursor repositioning to overwrite on-screen text, or OSC 52 clipboard writes (CWE-150). Add ansi::sanitize_control (drops Unicode Cc control chars) and apply it once at ingest in context.rs, after deserialization, to every untrusted string field. Raw values never legitimately contain control bytes, and styling escapes are added later from trusted config, so this loses nothing while neutralizing injected sequences. Sanitizing at ingest covers every downstream consumer (modules, passthrough, explain, cache) uniformly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. Confirmed all 12 untrusted 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
…itization Document the ingest-time sanitization so users aren't surprised when control bytes are stripped from paths or model names. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Owner
|
Pushed two docs additions to this branch (aa87e0e) to go with the code change:
No code changes — just documenting existing behavior so the stripping isn't surprising. |
Owner
|
Thank you for your submission! |
Merged
stephenleo
added a commit
that referenced
this pull request
Jun 29, 2026
- Bump crate version to 1.8.0
- Promote the Unreleased changelog section to [1.8.0], including the
previously-omitted {reset_at} entry (#192)
- Drop {reset_at} from the cship.toml showcase usage_limits formats
Ships the security fix (#191), the breaking cost-duration formatting
change, and the new effort (#187) and account (#153) modules.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
stephenleo
added a commit
that referenced
this pull request
Jun 29, 2026
- Bump crate version to 1.8.0
- Promote the Unreleased changelog section to [1.8.0], including the
previously-omitted {reset_at} entry (#192)
- Drop {reset_at} from the cship.toml showcase usage_limits formats
Ships the security fix (#191), the breaking cost-duration formatting
change, and the new effort (#187) and account (#153) modules.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Claude Code session JSON embeds attacker-influenced strings (directory names, model display names, vim mode, agent name, etc.). A malicious repo can name a directory with raw ESC sequences (delivered as JSON
\u001bescapes, which serde decodes to real control bytes); cship rendered these verbatim to stdout, where the terminal interprets them — enabling window-title spoofing, cursor repositioning to overwrite on-screen text, or OSC 52 clipboard writes (CWE-150).Fix
ansi::sanitize_control, which drops every UnicodeCc(control) character — ESC, BEL, BS, CR/LF/TAB, and the C1 range.context.rs::from_reader, after deserialization, to every untrusted string field. Raw JSON values never legitimately contain control bytes, and styling escapes are added later from trusted config, so this loses nothing while neutralizing injected sequences. Sanitizing at ingest covers every downstream consumer (modules, passthrough,explain, cache) uniformly.Testing
sanitize_control(strips C0/C1/DEL, preserves Unicode/spaces) and ingest (sanitize()over all fields, afrom_readerJSON-escape decode→strip check, and a regression guard that clean values are untouched).cargo fmt --check,cargo clippy -D warnings, release build.\u001b-escaped sequences inmodel.display_nameandworkspace.current_dirrenders as inert text (]0;HACKEDX,[1A) with zero stray ESC bytes, while legitimate[s](bold green)styling still emits its ANSI.🤖 Generated with Claude Code