Skip to content

fix: sanitize terminal control sequences in streamed Markdown - #595

Open
Sudip Kandel (sudipawtg) wants to merge 1 commit into
langchain-ai:mainfrom
sudipawtg:sudipawtg/fix/sanitize-markdown-terminal-controls
Open

fix: sanitize terminal control sequences in streamed Markdown#595
Sudip Kandel (sudipawtg) wants to merge 1 commit into
langchain-ai:mainfrom
sudipawtg:sudipawtg/fix/sanitize-markdown-terminal-controls

Conversation

@sudipawtg

@sudipawtg Sudip Kandel (sudipawtg) commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #540

Streamed assistant Markdown could pass ESC/CSI/OSC sequences (including OSC 52 clipboard writes) into Ink and the user's terminal. Model output can be influenced by repository and connector content, so this crosses a trust boundary.

Sanitize untrusted Markdown at the MarkdownText boundary before lexing: strip ESC/CSI/OSC/DCS-family sequences and unsafe C0/C1 controls, while preserving newlines and tabs. Ink's own styling is unchanged.

Verified with pnpm run format, pnpm run lint:check, and pnpm test (including new test/terminal-sanitize.test.ts coverage for OSC 52/8, CSI clear/cursor, BEL, CR, C1 controls, incomplete OSC tails, and code-fence/inline cases).

AI assistance: used for drafting the implementation; changes were manually reviewed and verified locally.

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 179c512

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openwiki Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sudipawtg
Sudip Kandel (sudipawtg) force-pushed the sudipawtg/fix/sanitize-markdown-terminal-controls branch from ff10b71 to 065cfbc Compare August 5, 2026 09:47
Prevent model/repo-influenced CLI output from injecting OSC/CSI/C0
sequences (including OSC 52) into developer terminals.
@sudipawtg
Sudip Kandel (sudipawtg) force-pushed the sudipawtg/fix/sanitize-markdown-terminal-controls branch from 065cfbc to 179c512 Compare August 5, 2026 09:47
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.

[Bug]: Streamed model output can emit terminal control sequences including OSC 52

1 participant