Skip to content

Fix: sanitize terminal control characters to prevent escape sequence injection - #1993

Open
vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/escape-sequence-injection
Open

vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/escape-sequence-injection

Conversation

@vinayK34

Copy link
Copy Markdown

This PR fixes CVE-2026-XXXX by sanitizing terminal control characters and escape sequences when outputting to a TTY. This prevents malicious HTTP responses from injecting terminal escape sequences that could manipulate the user's terminal display, change titles, inject clipboard content, or potentially exploit terminal vulnerabilities.

Changes

  • Added sanitize_for_terminal() function that removes ANSI escape sequences, OSC escape sequences, and other terminal control characters
  • Applied sanitization in all stream processing classes (EncodedStream, PrettyStream, BufferedPrettyStream) when outputting to a TTY (when env.stdout_isatty is True)
  • Preserves raw data when output is redirected to files or pipes to maintain backward compatibility

Fixes

Fixes #1812

Testing

The fix has been tested with various escape sequences including:

  • ANSI color codes (\x1b[31mRed Text\x1b[0m)
  • OSC title setting (\x1b]2;Title\x07)
  • Clear screen sequences (\x1b[2J\x1b[H)
  • Control characters (\x01\x02)
  • Mixed content with multiple escape sequences

All escape sequences are properly removed when outputting to a TTY, preventing terminal manipulation attacks.

…injection

This fix addresses CVE-2026-XXXX by sanitizing terminal control characters 
and escape sequences when outputting to a TTY. This prevents malicious HTTP 
responses from injecting terminal escape sequences that could manipulate 
the user's terminal display, change titles, inject clipboard content, or 
potentially exploit terminal vulnerabilities.

The fix:
1. Adds a sanitize_for_terminal() function that removes ANSI escape sequences,
   OSC escape sequences, and other terminal control characters
2. Applies this sanitization in all stream processing classes when outputting
   to a TTY (when env.stdout_isatty is True)
3. Preserves raw data when output is redirected to files or pipes

Fixes httpie#1812
@vinayK34
vinayK34 marked this pull request as ready for review October 31, 2026 14:10
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.

Terminal escape sequence injection via malicious HTTP response data

1 participant