Summary
Vim's shell-related filetype plugins may pass attacker-controlled Visual-mode selections to keyword help commands without safely separating shell arguments. When a crafted selection is processed by the affected plugins, arbitrary operating-system commands may execute with the privileges of the user running Vim.
Vim's shell-related filetype plugins may pass attacker-controlled Visual-mode selections to keyword help commands without safely separating shell arguments. When a crafted selection is processed by the affected plugins, arbitrary operating-system commands may execute with the privileges of the user running Vim.
Affected context
The issue can occur in Vim installations using the affected shell and scripting-language filetype plugins, including sh.vim, zsh.vim, and ps1.vim. Risk is present when attacker-controlled text is opened or selected in Visual mode and the K command invokes a keyword-help path that ultimately calls Bash, Zsh, or PowerShell without adequate shell-argument separation.
The issue can occur in Vim installations using the affected shell and scripting-language filetype plugins, including sh.vim, zsh.vim, and ps1.vim. Risk is present when attacker-controlled text is opened or selected in Visual mode and the K command invokes a keyword-help path that ultimately calls Bash, Zsh, or PowerShell without adequate shell-argument separation.
Exploit preconditions
- Attack surface: Vim's Visual-mode keyword-help functionality and related filetype plugins
- Required access: The victim must open or edit content containing attacker-controlled text
- Trigger point: Processing a Visual-mode selection with the
Kcommand in an affected filetype context - Execution context: The command runs with the operating-system privileges of the Vim process
- Why exploitation is possible: File and path escaping does not reliably neutralize shell metacharacters when selections are incorporated into shell commands
- Attack surface: Vim's Visual-mode keyword-help functionality and related filetype plugins
- Required access: The victim must open or edit content containing attacker-controlled text
- Trigger point: Processing a Visual-mode selection with the
Kcommand in an affected filetype context - Execution context: The command runs with the operating-system privileges of the Vim process
- Why exploitation is possible: File and path escaping does not reliably neutralize shell metacharacters when selections are incorporated into shell commands
Why this happens
The underlying bug is insufficient separation between untrusted text and shell command arguments. The affected plugins pass Visual-mode selections through keyword-program command paths that invoke external shells, while escaping mechanisms such as fnameescape() and PATH_ESC_CHARS do not provide complete shell metacharacter protection for this use case. This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because attacker-controlled data can influence an operating-system command.
The underlying bug is insufficient separation between untrusted text and shell command arguments. The affected plugins pass Visual-mode selections through keyword-program command paths that invoke external shells, while escaping mechanisms such as fnameescape() and PATH_ESC_CHARS do not provide complete shell metacharacter protection for this use case. This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, because attacker-controlled data can influence an operating-system command.
Potential impact
- Arbitrary operating-system commands may execute
- Files accessible to the Vim user could be read, modified, or deleted
- User credentials, tokens, or other local data could be exposed
- The affected workstation or development environment could be compromised
- Malicious content could cause code or configuration tampering
- Arbitrary operating-system commands may execute
- Files accessible to the Vim user could be read, modified, or deleted
- User credentials, tokens, or other local data could be exposed
- The affected workstation or development environment could be compromised
- Malicious content could cause code or configuration tampering
General mitigation guidance
Mitigation generally focuses on preventing untrusted selections from becoming shell syntax or executable command arguments.
Common defensive patterns include:
- Passing arguments through APIs that preserve argument boundaries rather than constructing shell command strings
- Avoiding shell interpretation when invoking external tools
- Applying context-appropriate escaping only where shell execution is unavoidable
- Restricting or disabling external keyword-program integrations in high-risk editing workflows
- Running Vim with least-privilege user permissions and limiting access to sensitive files
- Treating files from untrusted sources as potentially active input during review and editing
Mitigation generally focuses on preventing untrusted selections from becoming shell syntax or executable command arguments.
Common defensive patterns include:
- Passing arguments through APIs that preserve argument boundaries rather than constructing shell command strings
- Avoiding shell interpretation when invoking external tools
- Applying context-appropriate escaping only where shell execution is unavoidable
- Restricting or disabling external keyword-program integrations in high-risk editing workflows
- Running Vim with least-privilege user permissions and limiting access to sensitive files
- Treating files from untrusted sources as potentially active input during review and editing
How teams detect issues like this
Organizations can identify similar weaknesses through:
- Static analysis for concatenation of user-controlled text into shell commands
- Code review checks for
system(), shell execution, or command-building APIs fed by selections, filenames, or editor buffers - Searches for escaping functions used outside their intended context or without argument-boundary preservation
- Tests that exercise shell metacharacters through editor commands and filetype integrations
- Policy enforcement requiring safe process-spawning interfaces and explicit restrictions on shell invocation
Automated code review and security scanning tools may help flag command-construction patterns for manual assessment.
Organizations can identify similar weaknesses through:
- Static analysis for concatenation of user-controlled text into shell commands
- Code review checks for
system(), shell execution, or command-building APIs fed by selections, filenames, or editor buffers - Searches for escaping functions used outside their intended context or without argument-boundary preservation
- Tests that exercise shell metacharacters through editor commands and filetype integrations
- Policy enforcement requiring safe process-spawning interfaces and explicit restrictions on shell invocation
Automated code review and security scanning tools may help flag command-construction patterns for manual assessment.

