Summary
A code injection flaw in Vim's PHP omni-completion allows attacker-controlled class or trait names from an open buffer to be interpolated into an unescaped search pattern executed as Ex commands.
When a victim opens a crafted PHP file and triggers omni-completion, this can lead to arbitrary operating-system command execution via Vim's command interface.
Affected context
This vulnerability arises in Vim environments where the built-in PHP omni-completion script is enabled and used while editing PHP source files.
It specifically affects scenarios where class or trait names from the current buffer are consumed by completion logic and then used to construct search patterns and Ex command strings without proper escaping.
The risk is most pronounced when users routinely open untrusted or third-party PHP files and rely on omni-completion features during editing sessions.
Exploit preconditions
- Attack surface: Local Vim session while editing PHP files.
- Required access: Ability to get a victim to open a crafted PHP file (e.g., via shared repositories, patches, or downloaded code).
- Trigger point: User invokes PHP omni-completion (for example, using completion shortcuts) while the malicious class or trait name is present in the buffer.
- Why exploitation is possible: The PHP omni-completion script interpolates the class/trait name into a
search()pattern passed throughwin_execute()without escaping; a single quote and command separator (|) allow termination of the string literal and injection of arbitrary Ex commands, including:!to run OS commands.
Why this happens
The underlying issue is improper handling of untrusted text when building and executing interpreter-level command strings in Vim.
The PHP omni-completion script takes a class or trait name directly from the buffer and embeds it into a search() expression that is later executed via win_execute() as part of an Ex command.
Because the user-controlled name is not escaped for quotes or command separators, it can prematurely terminate the intended argument and inject additional commands, mapping to CWE-94: Improper Control of Generation of Code (Code Injection).
Conceptually, this is the same pattern as constructing shell commands or script code using string concatenation with unvalidated user input.
Potential impact
- Arbitrary operating-system command execution in the context of the user running Vim.
- Execution of malicious scripts or tooling embedded in the crafted PHP file.
- Exfiltration or modification of files accessible to the victim user account.
- Persistence mechanisms established via editor configuration or local shell environment.
- Potential lateral movement if the victim user has access to shared development infrastructure.
General mitigation guidance
Mitigation centers on eliminating direct string interpolation of untrusted text into command constructs and enforcing strict escaping.
Secure patterns include:
- Treating all buffer-derived text (such as class names) as data, not code, and applying robust escaping before using it in
search(),execute(), or similar APIs. - Avoiding concatenation of user-controlled content into Ex commands or code fragments; prefer APIs that separate command and argument contexts when possible.
- Restricting or sandboxing features that execute external commands (
:!) or limiting their availability in configurations that regularly open untrusted files. - Applying least-privilege principles so that Vim runs under a user account with minimal access to sensitive files and systems.
- Encouraging workflows where potentially untrusted source files are edited in hardened or isolated environments to reduce impact if injection occurs.
How teams detect issues like this
Detection efforts can focus on both source analysis and runtime behavior:
- Static analysis and code review: Examine editor scripts and plugins for patterns where user-controlled buffer content is concatenated into Ex commands,
execute(), orwin_execute()calls without escaping, especially in completion or refactoring features. - Pattern-based scanning: Use grep or custom linters to flag usage of
execute(),win_execute(), orsearch()where arguments include string concatenation of buffer variables or function outputs representing user content. - Policy enforcement: Establish guidelines for plugin and script authors to avoid constructing dynamic commands from untrusted input and to centralize safe-escaping helpers for command arguments.
- Behavior monitoring: On high-value systems, monitor for unusual invocations of Vim executing external commands (
:!) during normal editing workflows, though this is more suited for investigative rather than preventative detection.

