Terminal escape sequence injection via malicious HTTP response data
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず httpie/output/streams.py、特に BaseStream.iter、EncodedStream、PrettyStream を読み、次に httpie/output/writer.py が write_stream と write_stream_with_colors_win をどのように処理するかを追ってください。提供されている悪意のあるサーバーの再現手順を TTY で使って動作を確認してください。TTY 出力では端末制御シーケンスがサニタイズされ、リダイレクトされた出力では生のまま維持され、ヘッダーとボディ内容がカバレッジに含まれていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Terminal escape sequence injection via HTTP response data
Summary
HTTPie writes HTTP response headers and body content to the terminal without stripping or escaping terminal control sequences. A malicious HTTP server can embed ANSI escape codes or other terminal control characters in response headers or body text, potentially manipulating the user's terminal display, changing the terminal title, injecting clipboard content (on supported terminals), or in worst-case scenarios with vulnerable terminal emulators, executing commands.
Details
When HTTPie renders a response to a TTY, the data flows through output/streams.py and output/writer.py without any sanitization of terminal control characters. While Pygments-based colorization adds its own ANSI escape sequences for syntax highlighting, it does not filter out escape sequences that are already present in the response data.
The relevant code path is:
- Response received from server with embedded escape sequences
BaseStream.__iter__()yields header and body chunks (streams.py, line 63)write_stream()writes chunks directly to the output buffer (writer.py, line 73)- Terminal interprets all embedded escape sequences
Affected locations:
httpie/output/streams.py-BaseStream.__iter__(),EncodedStream,PrettyStreamhttpie/output/writer.py-write_stream(),write_stream_with_colors_win()
Impact
Terminal display manipulation: An attacker controlling a server can overwrite previous terminal output, hide the real response, or display misleading content. For example, a response could clear the screen and display fake content that looks like a different response.
Terminal title/clipboard injection: On terminals that support OSC escape sequences:
\x1b]2;text\x07changes the terminal window title\x1b]52;c;base64\x07sets clipboard content on some terminals (iTerm2, some xterm configs)
Terminal emulator vulnerabilities: Some terminal emulators have had historical vulnerabilities where specific escape sequences can trigger command execution or file writes (e.g., CVE-2003-0063 for xterm window title reporting, various iTerm2 and Konsole issues).
This is particularly relevant for HTTPie because it's commonly used in security research and API testing, contexts where users frequently interact with untrusted servers.
Reproduction
Start a malicious server:
import http.server
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
# Inject terminal title change via header
self.send_header('X-Custom', '\x1b]2;INJECTED TITLE\x07normal value')
self.end_headers()
# Body: clear screen + fake content
body = '\x1b[2J\x1b[HHTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nEverything is fine.'
self.wfile.write(body.encode())
http.server.HTTPServer(('localhost', 9999), Handler).serve_forever()
Then:
http localhost:9999
The terminal title will change, and the real response content will be replaced with fake output.
Suggested Fix
Filter terminal control characters when outputting to a TTY. A conservative approach:
import re
# Match ANSI escape sequences and other control characters
CONTROL_CHAR_RE = re.compile(
r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]' # C0 control chars (except \t, \n, \r)
r'|\x1b(?:\[[^a-zA-Z]*[a-zA-Z]' # CSI sequences
r'|\][^\x07]*\x07' # OSC sequences
r'|\(.' # charset selection
r'|.)' # other escape sequences
)
def sanitize_for_terminal(text: str) -> str:
return CONTROL_CHAR_RE.sub('', text)
Apply this sanitization in the stream output path when env.stdout_isatty is True, but not when output is redirected to a file or pipe (to preserve raw data for scripting).
This could be implemented as a flag (e.g., --raw-terminal to disable sanitization) for users who explicitly want raw output.
- 主要言語
- Python
- スター
- 38.6k
- フォーク
- 4k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
httpie/cli のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
new
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug new
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
correction metadata
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
acl-org/acl-anthology#10104 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug status/needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
prowler-cloud/prowler#12885 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Bug in GaussianTailProbabilityCalibrator: running_statistics=False still uses a windowed varianceオープンbug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
selimfirat/pysad#107 ·
メンテナーはふだん 1 日以内に返信
-
bug ci-failure high priority
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
vllm-project/vllm-omni#8194 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信