/

CVE-2026-57456

Severity:

HIGH RISK

(7.8)

Code Injection (CWE-94) via Vim Python Completion

CVE-2026-57456

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution in Editor Process

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

Vim's Python omni-completion reconstructs code from the current buffer and executes it with exec() to build completion suggestions, inserting docstrings directly into triple-quoted strings.

A malicious buffer can craft docstrings that escape the string literal and inject arbitrary Python code, turning a seemingly benign completion request into code execution within the editor process under user context.

Affected context

This vulnerability occurs when Vim users enable or invoke Python omni-completion features while editing buffers that may contain untrusted or partially trusted Python code.

The completion logic reconstructs function and class definitions by combining identifiers, signatures, and docstrings, then executing that reconstruction using exec() within the editor's Python environment.

Because docstrings are inserted verbatim into triple-quoted literals without escaping or validation, attacker-controlled buffer content can transform what should be passive text analysis into active code execution.

Exploit preconditions

  • Attack surface: Local editing session using Vim with Python omni-completion (python3complete.vim or legacy pythoncomplete.vim).
  • Required access: Ability to influence or provide the Python source in the buffer (e.g., opening untrusted files, cloned repositories, shared snippets, or generated code).
  • Trigger point: User action that invokes omni-completion for Python (such as completion keystrokes in insert mode) while cursor is positioned in or near hostile constructs.
  • Why exploitation is possible: The completion engine reconstructs definitions and executes them using exec() without sanitizing docstrings, allowing crafted literals to escape triple quotes and run attacker-supplied Python in the editor's runtime environment.

Why this happens

The underlying flaw aligns with CWE-94: Code Injection, where dynamically constructed code from external input is executed without sufficient validation or constraints.

Vim's Python omni-completion assembles a Python source string from buffer content—including docstrings—then passes that string directly to exec() as part of the completion logic.

Docstrings are treated as inert text but are interpolated between triple quotes without escaping special characters or delimiters, so an attacker can embed closing quotes and additional statements to break out of the intended literal.

This design assumes buffer contents are trustworthy, blurring the line between data and executable code and enabling arbitrary code injection during completion processing.

Potential impact

  • Arbitrary Python code execution within the Vim process under the user's account.
  • Modification of local files opened in Vim, including insertion or alteration of source code or configuration.
  • Exfiltration or tampering of sensitive data accessible to the user, such as SSH keys, API tokens, or project secrets on disk.
  • Invocation of external commands via Python's standard library, potentially enabling broader system compromise depending on user privileges.
  • Persistent editor or environment manipulation (e.g., altering Vim configuration files or plugin scripts to maintain influence).

General mitigation guidance

Effective mitigation focuses on reducing trust in buffer content and eliminating dynamic execution of reconstructed code during completion.

General patterns include:

  • Avoid constructing executable code strings from buffer-derived text; instead, parse and analyze code using structured APIs or static inspection without exec() or eval().
  • Treat docstrings and comments as untrusted text inputs and apply robust escaping or encoding wherever they are embedded in template literals or generated code.
  • Constrain interpreter capabilities used inside tooling features: prefer restricted execution contexts, minimized imports, and clear separation of analysis routines from execution paths.
  • Apply least-privilege principles to editor and plugin behavior, limiting file system and network access where feasible for code-introspection features.
  • Favor secure-by-default plugin architectures where completion and analysis operate on parse trees or language server protocols rather than executing reconstructed user code.

How teams detect issues like this

High-level detection approaches typically involve:

  • Static analysis or grep-based rules that flag uses of exec() and eval() where inputs derive from buffer content, user-editable strings, or docstrings in editor plugins or tooling scripts.
  • Code review practices that scrutinize completion, introspection, and automation features for patterns that execute reconstructed user code or configuration without sanitization.
  • Policy enforcement in plugin ecosystems: mandating that contributions avoid direct dynamic code execution from documents being edited and documenting safe parsing patterns.
  • Use of automated security scanners or linters on Vimscript and Python-based plugins to identify injection-prone APIs and missing input validation around text interpolation.

Sources

SourceLink
github.comgithub.com/vim/vim/commit/cce141c42740f122dd8486ae04e21c2a81016ba8
github.comgithub.com/vim/vim/releases/tag/v9.2.0699
github.comgithub.com/vim/vim/security/advisories/GHSA-ppj8-wqjf-6fp3

Frequently asked

questions

It is primarily a local vulnerability that triggers when a user opens and edits malicious Python files and invokes omni-completion. However, files may originate from remote sources such as repositories, code generators, or shared snippets, turning remote content into a local execution risk inside the editor.

An attacker needs to influence the contents of the Python buffer being edited—typically by convincing the user to open or work on a file that contains crafted docstrings. No elevated system privileges are required; exploitation runs with the same permissions as the Vim process.

The safest pattern is to remove or strictly limit dynamic evaluation of user-derived text. Completion and analysis features should rely on parsing or introspection techniques that treat buffer contents as data, not executable code, and should never pass reconstructed code that includes untrusted segments directly to exec() or equivalent APIs.

Developers can prevent similar issues by adopting secure coding practices for automation and completion features: avoid dynamic evaluation, sanitize and escape any user-controlled text embedded in templates, enforce clear trust boundaries between documents and tooling, and incorporate security review and static analysis into the development pipeline for plugins and editor extensions.

Find out what's already
exploitable in your codebase.