Executive brief
Vim is a widely-used command-line text editor. The bundled shell script filetype plugins fail to properly escape user-selected text when performing keyword lookups, allowing attackers to inject arbitrary shell commands. A user opening a malicious shell script file and pressing the K key on a selected line could unknowingly execute attacker-controlled commands with their user privileges.
Technical details
The vulnerability exists in runtime/ftplugin/sh.vim, runtime/ftplugin/zsh.vim, and runtime/ftplugin/ps1.vim, which define buffer-local keywordprg commands that pass Visual-mode selections directly to bash -c, zsh -c, or PowerShell -Command without proper shell metacharacter escaping. The fnameescape() function used by Vim's K command (in Normal mode) omits shell metacharacters like ;, &, (, ), and >, which are only stripped by SHELL_ESC_CHARS in non-Ex-command contexts. In Visual mode, K passes the entire selection verbatim rather than just the keyword, preserving shell metacharacters and allowing command injection. Exploitation requires the victim to deliberately select crafted text in Visual mode and invoke K; Normal-mode K is unaffected. The issue is fixed in Vim 9.2.0839.
Affected products
- Vim Vim < 9.2.0839
Timeline
- 2026-07-23: disclosed
- 2026-07-23: patched: Vim 9.2.0839 released
- 2026-08-11: advisory