Repository navigation
Conversation
This was referenced Nov 17, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Incremental rendering sanitizes blank-line fragments independently, allowing control-string payloads hidden by one-shot rendering to become visible when they span fragment boundaries.
1 open issue
What changed in this PR
This PR hardens the shared Markdown renderer against terminal-control injection from untrusted text, laying groundwork for trusted styling and display-only Markdown transformers.
Changes:
- Strips input escape sequences and control characters while preserving renderer-generated controls.
- Sanitizes image labels and media fallbacks inserted after Markdown rendering.
- Adds sanitization tests; rendered code and code-block copies now omit input terminal styling.
| File | Description |
|---|---|
pkg/tui/components/message/message.go |
Sanitizes image labels and media fallbacks. |
pkg/tui/components/message/append_content_test.go |
Tests label and fallback sanitization. |
pkg/tui/components/markdown/sanitize.go |
Adds shared escape-sequence and control-character removal. |
pkg/tui/components/markdown/sanitize_test.go |
Tests control removal and preservation of generated hyperlinks. |
pkg/tui/components/markdown/fast_renderer.go |
Removes the limited sanitizer in favor of the shared implementation. |
Review effort: Balanced
This was referenced Nov 17, 2026
rumpl
force-pushed
the
rumpl/markdown-strip-terminal-controls
branch
from
November 17, 2026 22:47
631822c to
7aceebe
Compare
The renderer only removed \r, \b, \f and \v, so escape sequences in model, tool, or shell output reached the terminal: they could clear the screen, hide the cursor, set the title, or write the clipboard via OSC 52. Strip every escape sequence, including DCS/SOS/PM/APC control strings with their payload, and all C0/C1 controls other than newline and tab. Renderer-generated controls such as hyperlinks are added afterwards and are unaffected. Image labels and media fallbacks are inserted after rendering, so they are sanitized separately. Signed-off-by: Djordje Lukic <[email protected]>
rumpl
force-pushed
the
rumpl/markdown-strip-terminal-controls
branch
from
November 17, 2026 22:58
7aceebe to
24315e2
Compare
This branch has not been deployed
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
The Markdown renderer only removed
\r,\b,\fand\v, so escape sequences in model, tool, or shell output reached the terminal. They could clear the screen, hide the cursor, set the window title, or write the clipboard via OSC 52.The renderer now strips:
The incremental renderer sanitizes the whole input before choosing block boundaries, so a control string spanning a blank line is removed exactly as in one-shot rendering.
Renderer-generated controls, such as hyperlinks, are added after sanitizing and are unaffected. Image labels and media fallbacks are inserted after rendering, so they are sanitized separately through the new
markdown.StripTerminalControls.Behavior change: colors in
!shell output, rendered as aconsoleblock, are stripped along with the other controls. Code-block copy buttons copy the sanitized text, matching what is displayed. This was already the case for\r\b\f\v.First of a stack, split out of #4952:
Validation
task build; race tests forpkg/tui/...andpkg/leantui/...golangci-lintreports no new issues