Summary
Zed's terminal tool permission system allowed command execution policies to be bypassed by prepending environment variable assignments to otherwise allowlisted commands.
By hijacking environment-dependent behavior (such as PAGER), an attacker who can trigger terminal commands could coerce trusted tools into executing arbitrary code under the user's context.
Affected context
The issue arises in Zed's integrated terminal and "tool" mechanism, where specific commands are allowlisted or restricted by policy.
In affected versions, the permission system evaluated only the base command name and did not treat leading environment variable assignments as semantically significant.
As a result, contexts where Zed invokes terminal tools (e.g., pagers, editors, or helper utilities) and relies on allowlists for safety may be exposed to manipulated commands that still pass the permission checks.
Exploit preconditions
- Attack surface: Zed's integrated terminal and any feature that invokes allowlisted shell commands via the terminal tool system.
- Required access: Ability to influence or trigger command lines executed within Zed (for example, by supplying configuration, project files, or content that Zed uses to construct commands, or by social engineering a user to paste/run crafted commands).
- Trigger point: Execution of a nominally allowlisted command preceded by crafted environment variable assignments (e.g., modifying PAGER or similar variables).
- Why exploitation is possible: The permission system focuses on the allowlisted command token but does not robustly parse shell syntax or environment assignments, allowing attackers to change program behavior or wrap the allowed binary in a malicious execution path while still satisfying the allowlist check.
Why this happens
This vulnerability stems from incomplete command validation and inadequate handling of shell semantics before enforcement.
The tool permission logic effectively treats the command string as a simple token sequence and checks only that the main command appears in an allowlist, without parsing and normalizing the full invocation.
Environment variable assignments and shell features are therefore misclassified as harmless prefixes rather than execution modifiers, mapping to:
- CWE-78: Improper Neutralization of Special Elements used in an OS Command, because external input can influence OS command execution beyond what the allowlist intends.
- CWE-184: Incomplete List of Disallowed Inputs, because the permission system does not account for environment-variable-driven behavior or additional shell constructs that can change what actually runs.
At an abstract level, the bug class is "string-based command allowlisting without full parsing and environment isolation," which allows attackers to encode dangerous behavior in segments the filter fails to model.
Potential impact
- Execution of arbitrary code under the user's account through manipulated environment variables.
- Bypass of Zed's terminal tool permission policies that are expected to restrict what commands can run.
- Abuse of trusted tools (e.g., pagers, editors, or language tooling) to run attacker-controlled payloads.
- Lateral movement within the user's development environment by accessing other local files, SSH keys, or project secrets.
- Integrity compromise of source code or build artifacts by running unexpected scripts or commands.
General mitigation guidance
Effective mitigation focuses on robust command modeling, strict parsing, and minimizing reliance on shell interpretation:
- Treat command invocations as structured data: use argument arrays and explicit environment maps rather than raw shell command strings wherever possible.
- Normalize and validate the full execution context, including environment variables, working directory, and arguments, before applying allowlists or policy checks.
- Restrict or ignore environment-variable assignments in user-controlled command strings when enforcing allowlists, or confine which variables can be set and to what patterns.
- Apply a deny-by-default posture for terminal tools and explicitly allow only well-understood binaries with tightly constrained arguments and environment.
- Run invoked tools with least privilege and a minimized, sanitized environment to limit what a compromised tool can access.
- Clearly separate user-configurable shell behavior from security-critical permission logic so that user convenience features cannot undermine enforcement.
How teams detect issues like this
Detection typically combines review of command construction paths with policy-aware analysis:
- Static analysis and code review:
- Search for locations where Zed (or plugins) constructs shell commands via string concatenation or interpolation instead of structured command APIs.
- Identify permission checks that inspect only the command name or prefix rather than a fully parsed representation of the invocation.
- Flag patterns where user input can alter environment variables or prepend data to command lines before permission checks.
- Configuration and policy review:
- Evaluate terminal tool allowlists for assumptions that "command name equals behavior" without considering environment-driven changes.
- Review documentation and plugin interfaces for any capability that lets workspace content or configuration control environment variables for tools.
- Runtime and behavioral monitoring:
- Instrument logging around terminal tool execution, capturing the full command and environment differences when invoked via Zed.
- Look for executions where environment variables like PAGER, EDITOR, or similar are overridden in close proximity to security-sensitive tools.
- Automated SAST or policy-as-code tools can be configured to flag occurrences of raw shell execution and incomplete allowlist enforcement in editor extensions or core code.

