Skip to content

fix(cli): strip terminal control characters from API content - #3152

Open
enesgules wants to merge 1 commit into
masterfrom
fix/cli-strip-control-chars
Open

enesgules wants to merge 1 commit into
masterfrom
fix/cli-strip-control-chars

Conversation

@enesgules

@enesgules enesgules commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

ctx7 docs and ctx7 library printed API-returned content (library titles, descriptions, doc snippets) straight to stdout. Because the index is crowdsourced, a malicious library entry could embed raw ANSI/OSC escape sequences (screen clear, cursor moves, OSC 52 clipboard writes) that execute in the user's terminal.

This adds a single stripControlChars helper in api.ts and applies it at the trust boundary on the crowdsourced responses: resolveLibrary, searchLibraries, and both the text and JSON branches of getLibraryContext. It removes C0 controls (except tab and newline), DEL, and C1. Our own picocolors styling is unaffected since it is applied after sanitization.

Verification

  • Typecheck, lint, build, and full test suite pass (362 tests)
  • New unit test covers OSC, CSI, CR, C1, and nested objects
  • Ran the built CLI against a mock API serving OSC 52 and CSI clear sequences in library title/description, text docs, structured docs, and --json: zero ESC bytes reach stdout

Credit

Reported by Syed Anas Mohiuddin, independent security researcher.

https://claude.ai/code/session_01XXTv4m4tzcTPQYfa9DvGsv

Library titles, descriptions, and doc snippets are crowdsourced. Sanitize
them at the API boundary so a malicious entry cannot inject ANSI/OSC
escape sequences into the user's terminal via ctx7 docs or ctx7 library.

Reported by Syed Anas Mohiuddin.

Claude-Session: https://claude.ai/code/session_01XXTv4m4tzcTPQYfa9DvGsv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant