iTerm2βs Kitty image protocol implementation has an arbitrary command execution vulnerability in the file transmit error response path. An APC escape sequence embedded in any file is consumed by the VT100 parser and does not appear in the cat output itself, but the Kitty file transmit error response preserves literal newlines from a crafted file path and writes them to PTY stdin β the shell interprets these newlines as command separators, resulting in arbitrary command execution. This is a logic bug β no memory corruption or race condition required β and is 100% reproducible. It works on a default iTerm2 installation with no configuration changes, and triggers on all shells including bash, zsh, and fish.
Three independent issues combine into a single exploit chain: (1) the APC handler lacks the trust check present in OSC handlers, (2) the Kitty file transmit error path preserves literal newlines from NSError.localizedDescription, and (3) the response is unconditionally written to PTY stdin.
It has been revealed that when the VT100 parser receives an APC sequence, it calls executeAPC:. At [A], it checks for tmux mode β if active, it returns early. At [B], it checks only whether the string starts with βGβ, and at [C] creates a Kitty image command and passes it to the delegate. Compared to OSC sequence handling, the terminalIsTrusted check is completely absent. Any APC that reaches the VT100 parser is unconditionally executed regardless of source.
Recent findings suggest that no trust check exists in the delegate chain either. At [A], the command is passed directly to kittyImageController.
When the Kitty image controller receives a t=f (file transmit) command, it decodes the base64 payload and uses it as a file path. At [A], URL.resourceValues() checks whether the file exists β if it doesnβt, an exception is thrown. At [B], the filenameIsSafe() blocklist check exists, but this code is only reachable after resourceValues() succeeds, so it never executes for non-existent files. At [C], the catch block embeds error.localizedDescription directly into the error message. macOSβs NSError.localizedDescription preserves literal newlines (0x0A) in filenames without escaping them.
The response containing the error message is written to PTY stdin. At [A], the default verbosity .normal always sends the response β it is sent regardless of whether it is an error. At [B], the response is wrapped in APC format (ESC_G...ESC\) and passed to the delegate.
Sources indicate that at the end of the delegate chain, [A] the response data is written to the PTY via screenSendReportData:. This function sends data through the same path as keyboard input, so the shell interprets this data as if the user typed it.
Sources indicate that the developer confirmed and fixed the vulnerability across two commits. Adding a terminalIsTrusted check to the APC handler would not have protected default installations β terminalIsTrusted is simply the inverse of the advanced setting βDisable potentially insecure escape sequences,β which is off by default (the terminal is trusted by default). The response sanitization is what closes the hole for everyone.
In a recent development, the first fix adds sanitizedResponseMessage(_:) to KittyImageController.swift. It replaces every C0 control character (0x00β0x1F, including ESC, CR, LF) and DEL (0x7F) with a space before the response is framed and sent. The error payload in respondToTransmit() and respondToDisplay() is passed through this sanitizer. a53b1bc.
The follow-up commit extracts a shared sanitizer stringByReplacingControlCharactersWithSpace on NSString, extending coverage to C1 characters (0x80β0x9F) while preserving Unicode format characters (Cf) such as ZWJ and bidi marks. It replaces the per-file sanitizer and is applied to three report paths: Kitty image, Kitty drag-and-drop (OSC 72), and title reporting. 2a63835.
The Kitty drag-and-drop sanitizer was changed from stripping only CR/LF to stripping all control characters, and the title report sanitizer was hardened the same way.
The attack vector is embedding APC escape sequence bytes into a malicious file. When the entire file content is output to the terminal (e.g., via cat), the raw bytes are delivered to the terminal and processed by the VT100 parser. This works on all shells β bash, zsh, fish, etc. β the shell type is irrelevant.
Industry observers note that the APC sequence (starting with ESC _, ending with ESC \) is consumed by iTerm2βs VT100 parser and is invisible in the cat output β the file appears to be a normal document. However, when the exploit triggers, the error response injected into PTY stdin produces visible garbled shell errors on the terminal. The injected command executes between these garbled lines, so the command execution itself is visible to the user. Concealment of this output was not explored in this research.
The core of the attack relies on two facts: macOS NSError.localizedDescription preserves literal newlines in filenames, and the error message uses curly quotes instead of ASCII double-quotes.
Why ASCII double-quotes are not used: If ASCII " is included in the file path, it appears as-is in the error message. When delivered to the shell via PTY, bash enters double-quote mode upon encountering ", and newlines no longer act as command separators. macOSβs NSError.localizedDescription uses Unicode curly quotes (β, β), which are not special characters in bash and do not trigger quote mode.
The file path set by the attacker (before base64 encoding):.
APC bytes can be embedded in any file type β .md, .txt, .log, .csv, configuration files, source code, etc. The only requirement is that the file content is output to the terminal via cat. The following example uses a README.md, but any file that a user might cat is a valid vector. The APC itself is invisible in cat output (consumed by the VT100 parser), but the error response injected into PTY stdin appears as garbled shell errors alongside the executed command.