Summary
Kitty terminals before 0.47.3 mishandle OSC 21 color-control query replies by reflecting attacker-controlled bytes, including newlines, directly into the shell input.
Under conditions where a remote host or process can emit crafted OSC sequences, this can lead to unintended command execution in the user's shell.
Affected context
The vulnerability occurs in environments where the Kitty terminal is used to connect to systems or processes capable of emitting OSC 21 (color-control) sequences.
When Kitty processes a color query reply, it reflects unvalidated response bytes back into the shell input line.
This behavior becomes risky when the terminal is attached to an interactive shell and the remote endpoint is not fully trusted, such as SSH sessions, multiplexer sessions, or tools that can output arbitrary escape sequences.
Exploit preconditions
- Attack surface: Interactive Kitty terminal sessions handling OSC 21 color-control sequences
- Required access: Ability for an attacker-controlled system or process to write arbitrary OSC escape sequences to the terminal
- Trigger point: Reception of a crafted OSC 21 reply containing embedded command text and newline characters
- Why exploitation is possible: The terminal reflects response bytes directly into the shell input without sanitizing control characters or separating protocol data from user input
Why this happens
The root cause is improper separation between control protocol handling and user input streams in the terminal.
Kitty's OSC 21 (color-control) handling logic treated the reply as safe to reinject into the shell input, without sanitizing or filtering newline and other control characters.
This maps to CWE-94 (Improper Control of Generation of Code) because user-controllable data is effectively turned into shell commands, and CWE-150 (Improper Neutralization of Escape, Meta, or Control Sequences) due to inadequate handling of terminal control sequences that influence command input.
Potential impact
- Injection of arbitrary shell commands into the user's interactive session
- Execution of commands under the user's account, potentially leading to data exfiltration
- Modification of configuration files or environment settings in the current session
- Pivoting to other systems reachable from the compromised shell
General mitigation guidance
Mitigation generally focuses on isolating control sequences from shell input and treating all terminal escape replies as untrusted data.
Useful patterns include:
- Sanitizing OSC replies to strip or neutralize newline and other command-delimiting characters before they reach the shell input
- Ensuring that protocol responses are handled internally by the terminal and never reinjected into user input streams
- Applying strict parsing and validation of control sequences, rejecting malformed or unexpected content
- Running interactive shells with least-privilege and limiting the trust placed in remote endpoints that can emit escape sequences
How teams detect issues like this
Detection can rely on both behavioral and code-level signals:
- Reviewing terminal code paths where OSC or other control sequences are processed and checking for any reflection into input streams
- Using static analysis or linters to flag code that mixes control protocol handling with user input injection
- Instrumenting terminals or shells to log unexpected escape sequences and monitoring for suspicious command patterns appearing without user typing
- Incorporating security-focused code reviews around terminal emulation and escape sequence parsing logic

