Skip to content

Strip ANSI and OSC escape sequences from untrusted terminal output - #5928

Open
ranas-mukminov wants to merge 5 commits into
Aider-AI:mainfrom
ranas-mukminov:fix/strip-ansi-untrusted-output
Open

ranas-mukminov wants to merge 5 commits into
Aider-AI:mainfrom
ranas-mukminov:fix/strip-ansi-untrusted-output

Conversation

@ranas-mukminov

Copy link
Copy Markdown

Untrusted terminal output reaches the terminal unfiltered: command output is printed with plain print() in run_cmd_subprocess(), and tool/assistant messages go to Rich as Text, which passes CSI and OSC bytes through. A file from an untrusted checkout, shown via a command or quoted in model output, can clear the screen or print a fake confirmation prompt.

  • aider/utils.py: strip_ansi helper covering CSI (ESC[...letter) and OSC (ESC]...BEL / ESC]...ESC), plus AnsiStripper for sequences split across reads.
  • aider/run_cmd.py: run_cmd_subprocess() prints and returns stripped output.
  • aider/io.py: InputOutput._tool_message() and assistant_output() strip message text before console.print. Rich style arguments are unchanged, so aider's own colors are unaffected. Code blocks quoting escape bytes lose those bytes in display.
  • tests/basic/test_utils.py, tests/basic/test_run_cmd.py: helper cases, split-sequence cases, and stripped run_cmd output.

Tests:

  • pytest tests/basic/test_utils.py tests/basic/test_run_cmd.py: 7 passed
  • pytest tests/basic/test_io.py: 23 passed

Notes:

  • Public hardening, not a validated vulnerability.
  • Aider Individual CLA signature is still owed before merge; filing is not blocked by it, merge is.
  • The pexpect interactive path is out of scope.
  • No live spoofing demo against aider itself was run.

@CLAassistant

CLAassistant commented Oct 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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