/

CVE-2026-42851

Severity:

HIGH RISK

(7.8)

Code Injection (CWE-94) in Kitty GPU Terminal Emulator

CVE-2026-42851

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-862

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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, dynamic import, 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.

Sources

SourceLink
github.comgithub.com/kovidgoyal/kitty/security/advisories/GHSA-w98g-hpvr-r332

Frequently asked

questions

Yes, indirectly. An attacker who controls content rendered in a Kitty terminal—such as through SSH output, log entries, or files the user views—can exploit the vulnerability without local access, as long as the victim displays the crafted data in Kitty.

The attacker only needs the ability to cause bytes to be written to the victim's Kitty terminal instance. This can come from remote shell access, multi-user systems, malicious files, or any service whose output the user inspects in Kitty.

The safest pattern is to ensure that terminal input is always treated as data and never as directly executable code. Control sequences should be parsed using strict, declarative handlers that cannot pass attacker-controlled strings into Python execution or evaluation paths, and sensitive control functions should require explicit, trusted authorization.

Future prevention depends on designing terminal and UI features with a clear separation of data and code, enforcing strong input validation, and requiring explicit opt-in for any remote-control or scripting capabilities. Regular security reviews, static analysis focused on dynamic execution constructs, and threat modeling of text-rendering pathways can help catch similar flaws early in development.

Find out what's already
exploitable in your codebase.