Summary
A code injection flaw in Kitty allows attacker-controlled terminal output to trigger execution of arbitrary Python code inside the Kitty process.
Whenever untrusted data is rendered in a Kitty terminal—such as SSH sessions, files printed with cat, or content viewed in pagers—an attacker may run code with the local user's full privileges.
Affected context
The vulnerability occurs when Kitty is used as the terminal emulator and processes byte streams that include specially crafted escape sequences or control data.
Any context where untrusted or semi-trusted text is displayed—remote shells, logs, emails, build output, or TUI applications—can become a vehicle for triggering the issue.
The risk is higher in workflows that routinely display data from external or multi-tenant sources without inspection, since the user does not need to perform any explicit confirmation for code execution to occur.
Exploit preconditions
- Attack surface: Kitty terminal instances on desktop or workstation systems.
- Required access: Ability to cause bytes to be written to the Kitty terminal (e.g., remote SSH access, control of file contents that a user views, or outputs shown in terminal-based tools).
- Trigger point: Rendering of crafted terminal output that leverages Kitty's escape sequence handling or embedded control features.
- Why exploitation is possible: Certain terminal control sequences or input patterns are interpreted in a way that allows injection of attacker-supplied Python code into the Kitty runtime, which executes with the same privileges as the local user and without additional prompts or permission checks.
Why this happens
The underlying issue maps to CWE-94: Improper Control of Generation of Code ('Code Injection').
Kitty interprets some parts of the terminal data stream as instructions that can reach Python evaluation or execution paths inside the application.
Because this interpretation is applied directly to untrusted terminal input without strict separation between data and code, an attacker can craft sequences that cause arbitrary Python code to be passed into Kitty's scripting or control logic.
Insufficient authorization checks on these control capabilities (related to CWE-862: Missing Authorization) mean that any data source capable of writing to the terminal can invoke them, even when no explicit remote-control or scripting permission has been granted by the user.
Potential impact
- Execution of arbitrary Python code within the Kitty process using the local user's full privileges
- Theft or modification of files accessible to the user account
- Installation of backdoors, malware, or persistence mechanisms on the workstation
- Capture of sensitive data displayed or stored in the user's environment (tokens, SSH keys, configuration files)
- Lateral movement to other systems reachable from the compromised user account
General mitigation guidance
Mitigation efforts generally focus on tightening the boundary between terminal data and executable control logic.
Common defensive patterns include:
- Restricting or hardening any terminal escape sequences or control channels that can reach code evaluation, ensuring they cannot directly embed or construct executable code.
- Introducing strict validation and parsing layers for control sequences, treating all terminal input as untrusted data and only allowing a narrow, declarative command set.
- Applying explicit authorization and opt-in mechanisms for any advanced remote-control or scripting features, so arbitrary application output cannot trigger them silently.
- Running the terminal and its scripting components with the least privileges necessary, and separating risky automation into restricted helper processes where feasible.
- Encouraging workflows that isolate highly untrusted content (e.g., viewing in sandboxed environments) when dealing with data from unknown or hostile sources.
How teams detect issues like this
Detection typically involves a combination of code-level and behavioral approaches:
- Static analysis: Flagging code paths where terminal input or escape sequences are passed to evaluators, interpreters, or dynamic execution constructs in Python (e.g.,
eval,exec, dynamicimport, or similar mechanisms). - Code review: Scrutinizing features that expose remote-control capabilities, scripting hooks, or configuration-driven code paths; reviewers look for cases where untrusted input influences executed Python without serialization or strong validation.
- Policy enforcement: Establishing development guidelines that disallow direct execution of user-controlled terminal data and mandate explicit authorization checks for any embedded scripting or remote-control channels.
- Runtime monitoring: Observing Kitty processes for unusual behavior, such as unexpected outbound connections or file modifications triggered solely by rendering terminal output; endpoint protection and sandboxing tools can help highlight such anomalies.

