Summary
A command injection flaw in the Kitty GPU-based terminal allows shell commands to be executed when certain error messages are reflected back into a subshell without proper escaping.
If a user connects to a malicious endpoint (for example via netcat) and the attacker emits crafted Kitty escape codes, arbitrary commands may run in the victim's active shell session.
Affected context
This vulnerability appears when Kitty is used as the terminal emulator and a subshell (such as a login shell or an interactive shell spawned by a tool) is active.
It particularly affects scenarios where the user connects to or listens on a remote endpoint using utilities like netcat, socat, or similar tools, which then relay remote output directly to the terminal.
In such cases, specially crafted Kitty escape sequences that trigger unescaped error messages can be injected into the data stream and reflected into the shell.
Exploit preconditions
- Attack surface: Interactive terminal sessions running inside Kitty.
- Required access: Ability to send data to the victim's terminal session (e.g., remote endpoint connected via netcat).
- Trigger point: A specially crafted Kitty escape code that forces Kitty to emit an error message containing attacker-controlled content.
- Why exploitation is possible: The error output is not properly escaped or sanitized before being echoed, so it is interpreted as shell input with CRLF, allowing injected commands to execute.
Why this happens
The root cause is improper neutralization of special characters and shell metacharacters when handling error output within Kitty.
When a crafted escape sequence causes Kitty to generate an error, the error text—containing untrusted, attacker-controlled content—is written back to the terminal as if it were normal user input.
Because this content is not escaped or quoted and is delivered with appropriate line terminators, the running shell interprets it as commands.
This behavior maps to CWE-77: Improper Neutralization of Special Elements used in a Command, where untrusted text is allowed to influence command execution.
Potential impact
- Execution of arbitrary commands in the victim's shell environment
- Compromise of the user account running Kitty, including file access and modification
- Installation of malware or persistence mechanisms under the user's profile
- Exfiltration of sensitive data such as SSH keys, configuration files, and command history
- Use of the compromised system as a pivot point for further attacks on internal networks
General mitigation guidance
Mitigation generally centers on breaking the path from untrusted error text to executable shell input.
Useful patterns include:
- Ensuring all error messages originating from control sequences are escaped, quoted, or otherwise rendered non-executable before being echoed to the shell.
- Treating escape-code-driven errors as data, not commands, and routing them through a safe, non-interpreted output channel (e.g., status bar, log file).
- Applying strict parsing and validation of terminal control sequences, discarding malformed or unexpected sequences instead of reflecting them.
- Reducing the privileges of shells and processes spawned within the terminal, so that even if a command is injected, its capabilities are limited.
- Encouraging workflows where remote, untrusted output is viewed via tools that neutralize escape codes, or through layers that strip control characters before they reach the terminal.
How teams detect issues like this
Detection can focus on both code-level review and runtime behavior:
- Static analysis / code review: Look for paths where control-sequence errors or diagnostic messages are constructed from untrusted input and written directly to the TTY or shell without escaping.
- Pattern checks: Flag functions that format or relay terminal error messages, especially when they accept arbitrary strings and forward them to standard input of shells or pseudo-terminals.
- Logging and monitoring: Instrument terminal error-handling paths to log unexpected or malformed escape sequences, enabling correlation with suspicious shell activity.
- Policy enforcement: Use CI/CD checks to enforce guidelines around safe handling of ANSI/terminal control sequences and avoidance of feeding untrusted data into interactive shells.
Automated code scanning tools and linters can help highlight command construction that includes untrusted content or direct re-emission of escape-sequence-derived errors.

