/

CVE-2026-34982

Severity:

HIGH RISK

(8.2)

OS Command Injection in Vim

CVE-2026-34982

Modified

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Arbitrary OS Command Execution on the User's Machine

Severity:

HIGH RISK

(8.2)

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 modeline sandbox bypass in Vim allows arbitrary OS command execution when a user opens a crafted file containing malicious modeline directives or expressions.

Missing security flags on several options and insufficient checks in the mapset() function enable commands to escape the expected sandbox, making file viewing itself a potential attack vector.

Affected context

This vulnerability affects environments where Vim is used to open files that may not be fully trusted, including code repositories, shared file servers, email attachments, or downloaded content.

It manifests when Vim evaluates modelines and related expressions while interpreting options like complete, guitabtooltip, and printheader, or when mapset() is called in a sandboxed context.

Systems that rely on Vim for routine editing or automated processing of third-party files are particularly exposed if modelines or secure mode settings are not tightly controlled.

Exploit preconditions

  • Attack surface: Local file handling in Vim (invocation of Vim to view or edit a file).
  • Required access: Ability for an attacker to supply or modify a file that the victim will open in Vim (e.g., via repository contribution, shared folder, or download).
  • Trigger point: The moment Vim opens the crafted file and processes its modelines or sandboxed expressions.
  • Why exploitation is possible:
  • The complete, guitabtooltip, and printheader options lack the P_MLE flag, permitting modelines to alter them in ways that should be restricted.
  • The mapset() function does not call check_secure(), allowing it to be invoked from within supposedly sandboxed expressions without enforcing security constraints.
  • Combined, these gaps allow modeline-controlled configuration and mappings to escape sandbox limitations and reach OS command execution paths.

Why this happens

The core issue is incomplete enforcement of sandbox and secure-mode restrictions in Vim's configuration and modeline processing.

Modelines are a feature that lets files influence editor behavior by setting options and defining mappings, but they must be tightly constrained to avoid running untrusted logic.

By not marking certain options (complete, guitabtooltip, printheader) with the P_MLE flag, Vim treated them as safe for modeline manipulation when they were not, expanding the capabilities of file-controlled configuration.

Similarly, the mapset() function failed to invoke check_secure(), a safeguard intended to prevent privileged or unsafe operations when running in secure or sandboxed contexts.

This combination maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command ("OS Command Injection"), because untrusted modeline content can indirectly influence OS-level command execution through insufficiently guarded editor functionality.

Potential impact

  • Execution of arbitrary OS commands with the privileges of the user running Vim.
  • Installation of malware or backdoors on the user's system via crafted files.
  • Exfiltration or modification of local files accessible to the victim.
  • Lateral movement within the user's environment if additional credentials or access tokens are present.
  • Compromise of automated workflows or tooling that rely on Vim to process untrusted files.

General mitigation guidance

Effective mitigation focuses on restricting untrusted file influence over editor behavior and enforcing secure defaults around modelines and sandboxed operations:

  • Limit or disable modelines for untrusted content:
  • Configure Vim to ignore modelines entirely in environments where files may be untrusted.
  • Alternatively, restrict modeline functionality to a minimal, vetted subset of options.
  • Harden secure/sandbox modes:
  • Ensure that sensitive operations (e.g., mapping changes, shell commands, command execution helpers) are always gated by security checks similar to check_secure().
  • Design sandboxed execution paths so they cannot indirectly call functions capable of changing mappings or invoking commands.
  • Constrain OS command invocation:
  • Reduce reliance on shell escapes and external command execution from within the editor, especially for automatic or file-driven workflows.
  • Use explicit user interaction for any action that would run OS commands derived from file content.
  • Apply least privilege on the host system:
  • Run everyday editing under non-administrative accounts with limited permissions.
  • Separate sensitive data and credentials to reduce what a compromised editor session can access.
  • Standard secure configuration practices:
  • Maintain a hardened, shared Vim configuration in multi-user environments that sets conservative defaults for modelines and external command usage.
  • Document policies for opening untrusted files and consider alternative tools for quick inspection where scripting and modelines are disabled.

How teams detect issues like this

Detection efforts can aim both at identifying vulnerable patterns in the editor configuration and spotting potentially malicious files:

  • Configuration and source inspection:
  • Review code or configuration for options that can be modified via modelines and verify they are appropriately flagged or restricted.
  • Examine functions that alter mappings, options, or invoke external commands to ensure they are always wrapped in secure-mode checks.
  • Static analysis of editor source or scripts:
  • Use static analysis rules to detect functions related to command execution, mappings, or sandboxing that lack security checks.
  • Flag changes to modeline parsing logic or sandbox-related code paths for security review.
  • Policy enforcement and hardening checks:
  • Implement configuration policies that disable or restrict modelines and external commands for users dealing with untrusted input.
  • Periodically audit system- or organization-wide Vim configurations for risky options, autocmds, or scripting that may broaden the impact of a sandbox bypass.
  • File-level threat hunting:
  • Scan repositories and shared directories for suspicious modelines or editor directives that modify mappings, run commands, or adjust shell-related settings.
  • Integrate such checks into pre-commit hooks or CI workflows for projects where Vim configuration is commonly embedded in files.

Sources

SourceLink
github.comgithub.com/vim/vim/commit/75661a66a1db1e1f3f1245c615
github.comgithub.com/vim/vim/releases/tag/v9.2.0276
github.comgithub.com/vim/vim/security/advisories/GHSA-8h6p-m6gr-mpw9
openwall.comopenwall.com/lists/oss-security/2026/04/01/1
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11389
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11509
access.redhat.comaccess.redhat.com/errata/RHSA-2026:11510
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19073
access.redhat.comaccess.redhat.com/errata/RHSA-2026:19224
access.redhat.comaccess.redhat.com/errata/RHSA-2026:21275
access.redhat.comaccess.redhat.com/errata/RHSA-2026:22634
access.redhat.comaccess.redhat.com/errata/RHSA-2026:28049
access.redhat.comaccess.redhat.com/errata/RHSA-2026:28050
access.redhat.comaccess.redhat.com/errata/RHSA-2026:28133
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30078
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30087
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30088
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30089
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30900
access.redhat.comaccess.redhat.com/errata/RHSA-2026:33453
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34476
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34477
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36004
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36005
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36006
access.redhat.comaccess.redhat.com/errata/RHSA-2026:56786
access.redhat.comaccess.redhat.com/errata/RHSA-2026:56853
access.redhat.comaccess.redhat.com/errata/RHSA-2026:56911
access.redhat.comaccess.redhat.com/errata/RHSA-2026:57402
access.redhat.comaccess.redhat.com/errata/RHSA-2026:57483
access.redhat.comaccess.redhat.com/errata/RHSA-2026:58981
access.redhat.comaccess.redhat.com/errata/RHSA-2026:59831
access.redhat.comaccess.redhat.com/errata/RHSA-2026:60019
access.redhat.comaccess.redhat.com/errata/RHSA-2026:65839
access.redhat.comaccess.redhat.com/errata/RHSA-2026:68711
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-34982
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2455400
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-34982.json

Frequently asked

questions

It is indirectly exploitable: an attacker must convince a victim to open a crafted file in Vim. There is no remote network exploit in Vim itself, but any channel that delivers files—such as email, version control, or downloads—can become a delivery vector.

The attacker only needs the ability to provide or modify a file the victim will open with Vim; no local shell on the victim's machine is required. Once the victim opens the file, the embedded modelines and expressions can trigger the exploit.

The safest approach is to ensure that features allowing files to influence editor behavior—like modelines, mappings, and embedded expressions—are tightly constrained or disabled for untrusted content. All code paths that change mappings, run commands, or interact with the OS should be guarded by explicit security checks that are enforced in secure or sandboxed modes.

Prevention involves designing editor and scripting features with strict trust boundaries: treat file-controlled configuration as untrusted input, apply a default-deny stance to operations that can execute commands or alter global state, and centralize secure-mode checks so new features cannot bypass them. Regular security reviews and static analysis focused on sandbox, modeline, and command-execution paths also help catch regressions early.

Find out what's already
exploitable in your codebase.