VAITP Dataset

← Back to the dataset

CVE-2026-52860

Vim Python omni-completion allows code execution from malicious buffers.

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

Vim is an open source, command line text editor. Prior to version 9.2.0597, Vim's Python omni-completion executes reconstructed function and class definitions from the current buffer with exec() as part of populating the completion dictionary. Python evaluates function default values, parameter annotations, and class base expressions at definition time, so a hostile buffer can execute attacker-controlled Python expressions during omni-completion. The existing g:pythoncomplete_allow_import mitigation (GHSA-52mc-rq6p-rc7c) does not cover this path, because the attacker-controlled code is not a harvested import/from statement. This issue has been patched in version 9.2.0597.

CVSS base score
7.5
Published
2026-06-11
OWASP
A03 Injection
Orthogonal defect classification
Checking
Code defect classification
Incorrect Algorithm
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.0597 or later.

Vulnerable code sample

import os

def simulate_vulnerable_vim_completion(code_from_buffer):
    """
    This function simulates the vulnerable logic in Vim's Python omni-completion
    prior to the patch. It executes reconstructed code from the text buffer
    using exec() to inspect objects for completion suggestions.
    """
    print(f"[*] Simulating completion by executing code block with exec()...")

    # The core of the vulnerability is this exec() call on untrusted code.
    # Python evaluates default arguments at function definition time. When exec()
    # processes the 'def' statement, the os.system() call is immediately executed.
    try:
        exec(code_from_buffer, {})
    except Exception as e:
        # In a real scenario, this might be suppressed or logged differently.
        print(f"[!] An error occurred, but the payload may have already executed: {e}")

    print("[*] Simulation finished.")


# This string represents the malicious text content in a file opened in the
# vulnerable version of Vim.
malicious_file_content = """
print("[+] Malicious buffer code is being defined...")

def vulnerable_function(
    default_arg=__import__('os').system('echo "[!!!] VULNERABILITY TRIGGERED via default argument"')
):
    # The function body is never called and is irrelevant.
    # The code execution happens when this function is defined by the completion engine.
    pass

print("[+] Malicious buffer code definition finished.")
"""

# To demonstrate the vulnerability, we run the simulator on the malicious code.
# The `os.system` command will run as a side effect of the `exec()` call inside
# the simulation function, proving that code execution occurs during definition.
simulate_vulnerable_vim_completion(malicious_file_content)

Patched code sample

import ast

def safe_parse_definitions(code_string):
    """
    Safely extracts function and class definitions from a string of Python
    code without executing it by using an Abstract Syntax Tree (AST).

    This represents the fixed approach, replacing a dangerous `exec()` with
    safe parsing. It avoids the execution of potentially malicious default
    arguments in functions or base class expressions in classes.
    """
    completions = {}
    try:
        # The core of the fix: parse the code into a tree of nodes
        # instead of executing it. This is safe and does not evaluate expressions.
        tree = ast.parse(code_string)

        # Iterate through the top-level nodes in the parsed tree.
        for node in tree.body:
            if isinstance(node, ast.FunctionDef):
                # Safely extract the function's name.
                func_name = node.name
                # Safely extract argument names.
                arg_names = [arg.arg for arg in node.args.args]
                # For a completion dictionary, we store a representation.
                # Importantly, default values (node.args.defaults) are NOT
                # evaluated, preventing arbitrary code execution.
                completions[func_name] = f"def {func_name}({', '.join(arg_names)})"

            elif isinstance(node, ast.ClassDef):
                # Safely extract the class's name.
                class_name = node.name
                # Base classes (node.bases) are also part of the AST but are not
                # evaluated here, preventing execution of code in base class lists.
                completions[class_name] = f"class {class_name}"

    except SyntaxError:
        # If the code is not valid Python, parsing fails gracefully
        # without any security risk.
        return {}

    return completions

Payload

import os
def vulnerable_function(param=os.system('touch /tmp/exploited')):
    pass

Cite this entry

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