Skip to content

tui: sanitize terminal controls in user messages#31494

Open
etraut-openai wants to merge 7 commits into
mainfrom
etraut/tui-sanitize-terminal-controls
Open

tui: sanitize terminal controls in user messages#31494
etraut-openai wants to merge 7 commits into
mainfrom
etraut/tui-sanitize-terminal-controls

Conversation

@etraut-openai

@etraut-openai etraut-openai commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Why

A pasted user message can contain a raw CSI sequence that corrupts terminal scrollback, making the latest response or input appear missing. The same sequence may already be present in persisted history when an affected conversation is resumed.

What changed

  • Remove CSI sequences and non-whitespace control characters from explicit paste input before it enters the composer.
  • Apply the same small transform before normal UserHistoryCell wrapping, so existing conversations render safely without mutating stored message content.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d6748df7b8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/terminal_hyperlinks.rs Outdated
Comment thread codex-rs/tui/src/terminal_hyperlinks.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a08407bf5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/terminal_hyperlinks.rs Outdated
Comment thread codex-rs/tui/src/insert_history.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32f6fd5a1c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/terminal_text.rs Outdated
Comment thread codex-rs/tui/src/terminal_text.rs Outdated
Comment thread codex-rs/tui/src/terminal_hyperlinks.rs Outdated
@etraut-openai etraut-openai changed the title tui: sanitize terminal controls in untrusted text tui: sanitize terminal controls in user messages Jul 7, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cacebe620b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/history_cell/messages.rs Outdated
Comment thread codex-rs/tui/src/terminal_text.rs Outdated
Comment thread codex-rs/tui/src/history_cell/messages.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd4638542a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs Outdated
Comment thread codex-rs/tui/src/terminal_text.rs Outdated
Comment thread codex-rs/tui/src/history_cell/messages.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc6f7fa7af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/tui/src/bottom_pane/chat_composer.rs

@fcoury-oai fcoury-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke tested and the sanitization worked as expected. Codex found one issue on restored messages in raw mode that I left inline.

Changes are straightforward and look good.

I recommend we also address the raw mode on resumed message case below, but otherwise approved.


impl HistoryCell for UserHistoryCell {
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
let message = sanitize_user_text(&self.message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display_lines sanitizes restored messages, but raw mode bypasses it: UserHistoryCell::raw_lines() still emits the original self.message, which transcript reflow prints directly. A resumed message containing \x1b[...] can therefore corrupt the terminal after Alt-R or a resize in raw mode. Please sanitize the source used by raw_lines, or enforce sanitization before terminal insertion for every render mode.

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.

2 participants