Summary
Vim's Python omni-completion feature reconstructs and executes function and class definitions from the current buffer using exec(), which allows embedded Python expressions to run at definition time.
When a user triggers omni-completion on a hostile Python buffer, attacker-controlled code in default values, annotations, or base classes can execute with the user's local privileges.
Affected context
This vulnerability arises in Vim installations with Python omni-completion enabled while editing Python source files.
It becomes relevant when users open or interact with untrusted or third-party Python code that may contain crafted function or class definitions.
The issue manifests specifically when omni-completion is triggered, causing Vim to reconstruct and execute definitions from the current buffer as part of building completion candidates.
Exploit preconditions
- Attack surface: Local editing session within Vim, typically during Python development.
- Required access: Ability to supply or influence the contents of a Python buffer opened in Vim (e.g., via cloned repositories, shared files, or pasted snippets).
- Trigger point: User interaction that invokes Python omni-completion, such as completion commands or keybindings tied to omni-complete.
- Why exploitation is possible: The completion engine reconstructs and executes function and class definitions with
exec()in the editor process.
Python evaluates default parameter values, type annotations, and class base expressions at definition time, so attacker-controlled expressions in those positions are executed even though no explicit import statements are used.
Why this happens
The core issue is a code injection pattern where untrusted content from the current buffer is treated as executable Python code during completion.
Vim's Python omni-completion reconstructs function and class definitions and passes them directly to exec() without isolating or constraining the evaluated expressions.
Because Python executes default argument expressions, annotations, and base class expressions when a definition is created, the mere act of reconstructing these definitions triggers execution of attacker-supplied code.
This behavior maps to CWE-94: Improper Control of Generation of Code, where dynamically generated code is built from data that may be influenced by an attacker and executed in a trusted context.
Potential impact
- Execution of arbitrary Python code under the user's account while editing a malicious buffer.
- Installation of backdoors or modification of local configuration and project files.
- Exfiltration or corruption of sensitive files accessible to the user.
- Alteration of development artifacts, such as source code, virtual environments, or build scripts.
- Use of the compromised editor session as a pivot to run additional tooling or commands.
General mitigation guidance
Defenses generally focus on avoiding direct execution of buffer-derived code and constraining how completion logic processes untrusted content.
Useful mitigation patterns include:
- Eliminating or minimizing use of
exec()and similar dynamic code evaluation on content derived from editable buffers. - Treating source text as data during completion: parse and analyze code structurally rather than re-executing reconstructed definitions.
- Applying strict sanitization and validation to any dynamically generated code fragments, ensuring they exclude side-effect-bearing expressions.
- Running completion or analysis logic in a more constrained environment (for example, a separate process or interpreter with reduced capabilities) to limit damage if malicious expressions are encountered.
- Encouraging users and organizations to treat code from untrusted repositories or shared snippets as potentially hostile, especially when using advanced completion features.
How teams detect issues like this
Detection typically relies on a combination of code inspection and behavioral analysis:
- Static review of editor and plugin code paths to identify uses of
exec(),eval(), or other dynamic execution primitives on buffer content or user-controlled text. - Pattern-based checks in code scanners or IDE security linters that flag reconstruction and execution of language constructs taken from documents being edited.
- Configuration and policy review to identify completion engines or plugins that run interpreters with full user privileges and dynamically execute document content.
- Monitoring development environments for unexpected interpreter activity originating from editor processes, particularly when triggered by completion or similar UI events.
Automated review tools and SAST rules that highlight dynamic code generation using untrusted inputs can help surface similar issues before release.

