/

CVE-2026-59856

Severity:

HIGH RISK

(7.8)

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

CVE-2026-59856

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution / OS Command Execution

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 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 through win_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(), or win_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(), or search() 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.

Sources

SourceLink
github.comgithub.com/vim/vim/commit/43afc581a37a35762dd0ef292f038b9dc5680a24
github.comgithub.com/vim/vim/security/advisories/GHSA-fh26-8f79-wj97

Frequently asked

questions

Exploitation is local to users who run Vim and use PHP omni-completion. An attacker must convince a victim to open a crafted PHP file and then trigger omni-completion, but no additional privileges are needed once that workflow occurs.

The attacker primarily needs the ability to supply or modify PHP files that the victim will edit (for example, via source control, shared projects, or downloaded samples). They do not need direct access to the victim's system beyond influencing the files being opened.

The safest pattern is to ensure that any user-controlled or buffer-derived data is properly escaped before being embedded in Ex commands or search() patterns, and to avoid constructing executable command strings from such data wherever possible.

Adopting a defensive coding standard for editor scripts and plugins helps: treat all buffer content as untrusted, avoid mixing data and code in command strings, use dedicated escaping utilities for command arguments, and include automated checks in your development workflow to flag risky command construction patterns.

Find out what's already
exploitable in your codebase.