Summary
A code injection vulnerability in the Oh My Zsh dotenv plugin can cause shell commands from a selected .env file to execute with the current user's privileges.
The issue becomes risky when the plugin changes into a directory containing a .env file and the configured dotenv path can be influenced, particularly when prompting is disabled or an empty response is accepted.
Affected context
The vulnerability occurs in Oh My Zsh deployments using the dotenv plugin before the fix released after 2026-05-28. It requires the plugin to process a .env file after changing into a directory and to pass the configured ZSH_DOTENV_FILE value to the shell's source mechanism. Risk is greater when untrusted or attacker-controlled directories can be entered and prompt-based confirmation is disabled or bypassed.
Exploit preconditions
- Attack surface: Local shell startup or directory-change handling through the dotenv plugin
- Required access: Ability to place or influence a syntactically valid
.envfile and cause the current user to enter the relevant directory - Trigger point: The plugin's directory-change processing and subsequent sourcing of the selected file
- Why exploitation is possible: Shell source operations interpret file contents as commands, and the plugin does not sufficiently constrain the file or command content before execution
Why this happens
The underlying issue is an unsafe code-loading pattern in which a path associated with dotenv configuration is passed to a shell source operation. Shell sourcing is executable interpretation rather than passive data parsing, so syntactically valid commands in the referenced file run with the invoking user's privileges.
This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because attacker-influenced file content crosses a trust boundary and is executed as shell code without an adequate safety control.
Potential impact
- An attacker could execute arbitrary commands as the affected user.
- The compromise could expose credentials, tokens, environment variables, or local files.
- The attacker could modify shell configuration, development files, or other user-owned data.
- The activity could provide a starting point for further local privilege escalation or lateral movement.
General mitigation guidance
Mitigation generally focuses on treating dotenv files as data rather than executable shell input and reducing the trust placed in directory-local configuration.
Common defensive patterns include:
- Avoiding direct shell sourcing of files that may be influenced by untrusted users or repositories.
- Parsing environment assignments with a restricted, data-only parser that rejects command syntax and substitutions.
- Restricting dotenv discovery to explicitly trusted directories and fixed configuration paths.
- Requiring clear, affirmative approval before loading directory-local configuration.
- Keeping prompt-disable settings from silently converting untrusted configuration into executable code.
- Running development and automation shells with least privilege and minimal sensitive environment variables.
How teams detect issues like this
Organizations can identify similar risks through:
- Static analysis searches for
source,.,eval, or equivalent shell execution applied to variable-controlled paths. - Code review checks for directory-change hooks that automatically load local configuration files.
- Rules requiring allowlisted paths, ownership checks, or data-only parsing for environment configuration.
- Policy enforcement that flags shell plugins which execute repository-local files during navigation or startup.
- Testing with files containing harmless invalid syntax and command-like constructs to verify that configuration handling does not execute arbitrary content.
- Automated security review tools that identify shell code-loading patterns and unchecked path influence.

