/

CVE-2026-52858

Severity:

HIGH RISK

(7.8)

Code Injection (CWE-94) in Vim Python Omni-Completion

CVE-2026-52858

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-95, CWE-829

Impact:

Arbitrary Code Execution as Local Editing User

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 issue in Vim's Python omni-completion causes import and from statements in the current buffer to be executed via Python's import system.

When editing a hostile Python file near a malicious sibling package and triggering omni-completion, the package's top-level code may run with the editor user's privileges.

Affected context

The vulnerability occurs in Vim builds compiled with the +python3 or +python interpreter and using the Python omni-completion scripts (python3complete.vim or pythoncomplete.vim).

It manifests when a user opens a Python source file whose directory is effectively placed on Python's sys.path, while a sibling Python package or module exists in the same directory tree.

When omni-completion is invoked in that buffer, Vim's completion logic executes Python import and from statements based on the buffer content, which can inadvertently run attacker-controlled code in the local environment.

Exploit preconditions

  • Attack surface: Local Vim sessions editing Python files with omni-completion enabled.
  • Required access: Ability to place or modify Python files and sibling package directories on the victim's filesystem (e.g., in a project folder the victim opens).
  • Trigger point: The victim opens a crafted .py file in Vim and explicitly triggers omni-completion (e.g., via completion keystrokes).
  • Why exploitation is possible: The omni-completion script passes import and from statements found in the buffer directly to Python's import machinery, while the buffer directory is on sys.path. Python's import then executes the top-level code of any matching sibling package or module, allowing attacker-supplied code to run as the editing user.

Why this happens

The root cause is the unsafe execution of interpreted language statements drawn from user-controlled input, mapping to CWE-94: Improper Control of Generation of Code (Code Injection) and related CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code.

Vim's Python omni-completion logic treats import and from statements found in the current buffer as trusted, and feeds them to Python's import mechanisms without restricting which modules may be imported or from where.

Because the current working directory is on sys.path, this creates an implicit trust boundary violation: arbitrary local packages placed alongside the file being edited can be imported and executed as part of the completion process.

This pattern reflects a general anti-pattern where developer tooling executes or evaluates code derived from project files for convenience features (like completion) without isolating or constraining those operations.

Potential impact

  • Execution of arbitrary Python code with the permissions of the editing user.
  • Local compromise of the developer workstation or build environment.
  • Exfiltration or modification of sensitive files accessible to the user account.
  • Installation of persistent backdoors or malicious tooling in the user's environment.
  • Manipulation of source code or configuration within the project being edited.

General mitigation guidance

Mitigation generally focuses on preventing untrusted code from being executed during editor features and tightening trust boundaries around project directories.

Useful defensive patterns include:

  • Avoiding direct execution of code fragments or statements derived from buffer content in completion or analysis scripts.
  • Restricting module loading to a curated allowlist or known-safe search paths rather than including the current working directory on sys.path.
  • Running language tooling and completion logic in restricted or sandboxed environments isolated from the user's full privileges.
  • Treating project directories and incoming repositories (e.g., from VCS or downloads) as potentially untrusted and avoiding automatic execution of their code during editor operations.
  • Applying least-privilege principles on developer systems so that, if code is executed, its ability to affect the broader system is limited.

How teams detect issues like this

Detection can lean on a mix of code-level inspection and behavioral monitoring of development environments:

  • Static analysis and script review for editor plugins or completion scripts that pass user-controlled content into interpreters, import mechanisms, eval, exec, or similar dynamic execution APIs.
  • Policy checks in plugin repositories or internal tooling that flag usage of unsafe import patterns based on buffer content or project files.
  • Code review practices that scrutinize developer tools and IDE/Vim plugins for hidden execution of project code outside explicit test or run commands.
  • Runtime monitoring on sensitive workstations for unexpected Python interpreter activity triggered by editor processes, especially imports from project-local directories.
  • Use of automated security scanning tools to identify patterns associated with CWE-94/CWE-95 in scripting around editors and CLIs.

Sources

SourceLink
github.comgithub.com/vim/vim/commit/4b850457e12e1a678dd209f2868154f7553cbf8d
github.comgithub.com/vim/vim/releases/tag/v9.2.0561
github.comgithub.com/vim/vim/security/advisories/GHSA-52mc-rq6p-rc7c

Frequently asked

questions

Not by default. Exploitation typically requires the victim to open a crafted Python file from a directory containing a malicious sibling package and then trigger omni-completion in Vim. However, attackers can deliver such project structures via source control, archives, or shared folders.

An attacker needs the ability to place or influence files and directories that the victim will open in Vim—such as contributing to a repository, providing a project template, or compromising a shared codebase. Direct shell access to the victim machine is not required if the victim voluntarily opens the hostile project.

The most robust pattern is to avoid executing or importing code based directly on buffer content or project files for editor features, and to ensure that any necessary analysis or completion runs in an isolated context with a constrained, well-defined module search path not including untrusted directories.

Future tooling should treat all project and workspace contents as untrusted by default, avoid dynamic execution of user-derived code in helper scripts, use allowlisted imports and sandboxed runtimes for completion and analysis, and subject editor/IDE plugins to security review that specifically looks for CWE-94 and CWE-95 patterns.

Find out what's already
exploitable in your codebase.