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.

