/

CVE-2026-59858

Severity:

HIGH RISK

(7.8)

Code Injection (CWE-94) via Vim C omni-completion tags

CVE-2026-59858

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Command Execution in Editor Context

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

Vim's C omni-completion script mishandles tag metadata by interpolating it directly into a :vimgrep pattern that is executed without escaping.

If a project's tags file contains a crafted typeref or typename field and a user opens a hostile C file and triggers omni-completion, arbitrary Ex commands can be executed with the user's privileges.

Affected context

This vulnerability appears in Vim environments that:

  • Use the built-in C omni-completion feature
  • Load tag metadata from project tags files (e.g., ctags output)
  • Trust typeref: or typename: extension fields without sanitization

It becomes relevant when users open C source files from potentially untrusted projects and rely on omni-completion, allowing crafted tag entries to influence editor commands.

Exploit preconditions

  • Attack surface: Local editor session running Vim with C omni-completion enabled
  • Required access: Ability to create or modify the project tags file consumed by Vim (e.g., via ctags generation or repository control)
  • Trigger point: Invoking C omni-completion on a C buffer that uses tags containing malicious typeref:/typename: fields
  • Why exploitation is possible: The omni-completion script interpolates tag extension fields directly into a :vimgrep pattern, which is passed through :execute; since :vimgrep treats the bar character as a command separator, an attacker can terminate the search and append arbitrary Ex commands.

Why this happens

The underlying issue is a code injection pattern where untrusted data is composed into a command string that is later interpreted by a powerful command engine.

In this case, tag extension fields such as typeref: and typename: are assumed to be benign search tokens and embedded into a :vimgrep pattern without escaping special characters or enforcing a strict grammar.

Because the constructed pattern is executed via :execute, any embedded command separators can break out of the search context and introduce arbitrary Ex commands, mapping directly to CWE-94: Code Injection through misused metacharacters and lack of input validation.

Potential impact

  • Execution of arbitrary Ex commands within the user's Vim session
  • Modification or deletion of files accessible to the editing user
  • Insertion of malicious content into source files or configuration files
  • Potential chaining with other local tools or scripts invoked from Vim
  • Disruption of the development environment and tampering with project artifacts

General mitigation guidance

Effective mitigation focuses on reducing trust in external metadata and preventing command construction from unsanitized input.

Common defensive patterns include:

  • Escaping or quoting any user-controlled or file-derived data before embedding it in command strings
  • Using structured APIs for search and completion that separate data from command syntax rather than assembling raw Ex commands
  • Limiting the completion scripts' ability to invoke generic :execute with dynamically built strings
  • Encouraging workflows where tags files from untrusted sources are treated with caution and not automatically consumed
  • Running editors with reduced privileges relative to system-wide resources and sensitive files, so that accidental command execution has limited impact

How teams detect issues like this

Detection generally relies on reviewing script code and configuration for insecure command construction patterns.

Useful approaches include:

  • Static analysis or linting rules that flag :execute usage with concatenated strings derived from tags or other external metadata
  • Manual review of Vimscript and editor plugins for interpolation of untrusted values into :vimgrep, :grep, or other Ex commands
  • Policy checks in version control to scrutinize changes to completion scripts and tag handling logic
  • Optional use of security-focused scanners or automated review tools that recognize CWE-94 patterns in scripting languages

Sources

SourceLink
github.comgithub.com/vim/vim/commit/6b611b0d15603c52ebdad17172b0232b4f65704e
github.comgithub.com/vim/vim/security/advisories/GHSA-mf92-v4xw-j45x

Frequently asked

questions

It is not directly remote in the traditional network sense. Exploitation typically requires control over the project tags file or repository contents that the Vim user opens, which can occur via compromised source archives, malicious repositories, or shared project artifacts.

An attacker needs the ability to influence the tags file consumed by Vim—commonly by providing a malicious project, repository, or generated tags output. Once the victim opens a hostile C file within that project and triggers C omni-completion, the embedded commands can run with the victim's user privileges.

The safest pattern is to avoid constructing Ex commands from untrusted data entirely. When command composition is unavoidable, any external values must be robustly escaped or constrained to a well-defined grammar, and helper APIs that separate command structure from parameters should be preferred over raw string concatenation.

Prevention hinges on treating all external metadata and project artifacts as untrusted by default, enforcing strict validation or escaping before use in commands, and establishing coding guidelines for Vimscript and other editor plugins that forbid dynamic :execute with unvalidated input. Integrating code review and automated checks for code injection patterns into development workflows further reduces the risk of similar vulnerabilities.

Find out what's already
exploitable in your codebase.