CVE-2026-47162: Vim netrw Code Injection Vulnerability – Arbitrary Code Execution
Vim, the popular open-source text editor, contains a code injection vulnerability in its netrw file browser plugin. When you browse directories in Vim, it saves a history of the paths you've visited to a file called .netrwhist. An attacker can craft a malicious directory name containing special characters that, when saved to this history file, breaks out of the intended string format and tricks Vim into executing arbitrary commands the next time you open the editor. This could allow an attacker to run malicious code on your system if you cd into or browse a directory with a carefully crafted name. The vulnerability is fixed in Vim version 9.2.0495 and later.
Source data · NVD / CISA · public domain
- CVSS
- 3.1 · 8.8 HIGH · CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- Weaknesses (CWE)
- CWE-140, CWE-74, CWE-94
- Affected products
- 1 configuration(s)
- Published / Modified
- 2026-06-11 / 2026-07-15
NVD description (verbatim)
Vim is an open source, command line text editor. Prior to version 9.2.0495, a Vimscript code injection vulnerability exists in s:NetrwBookHistSave() in the netrw plugin (runtime/pack/dist/opt/netrw/autoload/netrw.vim) when serializing browsed directory paths to the history file ~/.vim/.netrwhist. A directory name derived from the filesystem is interpolated into a single-quoted Vimscript string literal without escaping embedded single quotes, allowing a crafted directory name to break out of the string context and execute arbitrary Vimscript, including shell commands via system() and :!, the next time the history file is sourced. This issue has been patched in version 9.2.0495.
6 reference(s) · View on NVD →
SEC.co analysis · AI-assisted, reviewed against source
Technical summary
The vulnerability exists in the s:NetrwBookHistSave() function within the netrw plugin's autoload module (runtime/pack/dist/opt/netrw/autoload/netrw.vim). The function serializes directory paths visited during file browsing into Vimscript code that is written to ~/.vim/.netrwhist. Directory names sourced from the filesystem are directly interpolated into single-quoted Vimscript string literals without escaping single quotes. An attacker-controlled directory name containing unescaped single quotes can break the string context, allowing injection of arbitrary Vimscript statements. When the history file is sourced on subsequent Vim invocations, the injected code executes with the privileges of the user running Vim, including access to shell execution functions like system() and the :! command. This represents a classic code injection flaw (CWE-94) compounded by unsafe string serialization (CWE-140) and expression language injection (CWE-74).
Business impact
For organizations where developers, sysadmins, or security teams regularly use Vim across shared or untrusted environments, this vulnerability poses a privilege escalation and code execution risk. An attacker who can create directories with malicious names on a shared filesystem or compromised system could silently inject code that executes when a victim user opens Vim. This could lead to credential theft, lateral movement, or persistent backdoors within developer toolchains or CI/CD environments. The requirement for user interaction (opening Vim to trigger history loading) slightly limits the attack surface, but the risk is elevated in environments where directory traversal or file creation by untrusted parties is possible.
Affected systems
Vim versions prior to 9.2.0495 are affected. All users of Vim who have the netrw plugin active (which is the default for many Vim installations) are potentially vulnerable. The vulnerability is platform-agnostic and affects Linux, macOS, Windows, and other Unix-like systems where Vim is deployed. Both interactive users and automated systems that invoke Vim to browse or interact with the filesystem are in scope.
Exploitability
The attack requires that an attacker can create or control a directory name on a filesystem that a Vim user will browse using netrw. In local or network-accessible scenarios (NFS mounts, shared drives, cloned repositories with malicious directory names), the bar for exploitation is relatively low. The attack is not remotely exploitable without some means of placing a crafted directory on the target system first. User interaction is required—Vim must be opened and the netrw history must be sourced. No special Vim configuration is needed; default installations are vulnerable. The CVSS score of 8.8 (HIGH) reflects high impact (code execution as the user) combined with low attack complexity and no privilege requirements, moderated only by the user interaction requirement.
Remediation
Upgrade Vim to version 9.2.0495 or later. Verify your installed version by running `:version` within Vim or `vim --version` from the command line. Package managers (apt, brew, yum, etc.) should provide updated versions; check your distribution's Vim package. If you cannot upgrade immediately, avoid browsing untrusted or attacker-controlled directories using netrw, and consider disabling the netrw plugin if not essential for your workflow.
Patch guidance
Update Vim through your package manager or build from source. On Linux systems using apt: `sudo apt update && sudo apt upgrade vim`. On macOS with Homebrew: `brew upgrade vim`. For binary distributions and Windows, visit vim.org and download the latest release. After installation, verify the version with `vim --version` and confirm it shows 9.2.0495 or later. If you maintain Vim across a fleet of systems, prioritize updates in environments where users interact with diverse or untrusted filesystems.
Detection guidance
Monitor for Vim processes that load or source the ~/.vim/.netrwhist file, particularly in conjunction with unexpected Vimscript execution or shell command invocation. Look for netrwhist files containing suspicious Vimscript syntax (unbalanced quotes, function calls, system() invocations) that don't match typical directory path entries. In endpoint detection and response (EDR) systems, flag Vim spawning shells or subprocesses without explicit user command. On shared filesystems, scan for directory names containing Vimscript metacharacters (single quotes, pipes, semicolons) that could be injection payloads. Review .viminfo and shell history logs for anomalous Vim invocations or unexpected command execution.
Why prioritize this
This vulnerability should be prioritized for patching because it enables arbitrary code execution with user-level privileges, affecting a widely-used development tool. While exploitation requires directory-level control by an attacker, the risk is substantial in development environments, CI/CD pipelines, and shared filesystem scenarios. The default inclusion of netrw in most Vim installations and the silent nature of the attack (code execution occurs on history load, not during obvious user actions) make this a moderate-to-high priority for security teams. Organizations with strict filesystem access controls can lower prioritization slightly, but development teams and sysadmins should patch promptly.
Risk score, explained
The CVSS 3.1 score of 8.8 reflects: high impact (C:H, I:H, A:H—confidentiality, integrity, and availability all compromised through arbitrary code execution), low attack complexity (AC:L—no special conditions needed), network adjacency not required (AV:N accounts for mounting or accessibility via network protocols like NFS or SMB), no privilege escalation (PR:N), and user interaction required (UI:R—user must open Vim to trigger the vulnerability). The score does not include environmental factors; organizations with strict filesystem controls and isolated development environments may apply severity adjustments downward, while those with shared filesystems or CI/CD automation should view this as a critical issue.
Frequently asked questions
Can this vulnerability be exploited remotely without network access to the filesystem?
Not directly. An attacker must be able to create or control a directory name on a filesystem that the Vim user will browse. This requires either local filesystem access, compromise of a shared storage system (NFS, SMB), or inclusion of a malicious directory in a repository or archive that the user clones or extracts. Once the directory exists and the user browses it with netrw, the exploit is triggered on the next Vim session.
What if I don't use netrw or the file browser feature in Vim?
If you do not use Vim's file browser (netrw) to navigate directories, your exposure is reduced because s:NetrwBookHistSave() would not populate the history file. However, if netrw is simply installed but not actively used by you, history from previous browsing sessions may still be loaded when Vim starts, potentially triggering a previously injected payload. The safest approach is to upgrade to the patched version regardless of your usage patterns.
Does this affect Neovim or other Vim forks?
This vulnerability is specific to Vim's netrw plugin implementation. Neovim and other forks may have their own implementations or may have addressed this issue separately. Check the security advisories and version information for your specific editor distribution. Do not assume that patching Vim means Neovim is patched, and vice versa.
How long does it take to upgrade Vim across an organization?
Upgrade timelines depend on your deployment model. For systems using package managers, updates can be deployed within hours to a day using standard patch management tools. For custom-built or enterprise Vim installations, factor in testing and rollout windows. Given the relatively low risk of upgrading Vim (it is generally a stable, non-critical system component), most organizations can complete patching within 1–2 weeks without significant disruption.
This analysis is based on the CVE record and vendor advisory information available as of the publication date. No exploit code or weaponized proof-of-concept is provided. Organizations should verify patch availability and compatibility with their Vim distributions and deployment environments. Testing in non-production environments before broad rollout is recommended. This assessment does not constitute legal advice or a guarantee of security; consult your own security team and vendor documentation for definitive guidance on your specific infrastructure. Source: NVD (public-domain), retrieved 2026-07-20. Analysis generated by SEC.co (claude-haiku-4-5).
Related vulnerabilities
- CVE-2026-8795HIGHRapid7 Velociraptor YAML Injection in Remapping Artifact (v0.76.6)
- CVE-2026-10175MEDIUMCode Injection in Aider-AI Aider 0.86.3 – Exploit Available
- CVE-2026-10688MEDIUMCode Injection in ahujasid blender-mcp
- CVE-2026-47167MEDIUMVim Cucumber Plugin Code Injection via Unsafe Ruby Eval
- CVE-2026-10110HIGHSQL Injection in code-projects Student Details Management System 1.0
- CVE-2026-10111HIGHSQL Injection in sambitraj STUDENT-MANAGEMENT-SYSTEM 1.0 Login
- CVE-2026-10178HIGHSQL Injection in code-projects Online Music Site 1.0 Admin Panel
- CVE-2026-10184HIGHSQL Injection in SourceCodester Hospitals Patient Records System 1.0