Summary
Zed's terminal tool permission system can be bypassed by abusing Bash arithmetic expansion ($((...))) inside commands that appear to be allowlisted, such as echo.
An attacker who can supply terminal commands within Zed may execute arbitrary shell commands nested inside otherwise permitted commands, undermining the intended command restrictions.
Affected context
The vulnerability affects Zed installations that:
- Use the built-in terminal or terminal-based tools with a permission or allowlist mechanism, and
- Rely on command string patterns (e.g.,
echo) to restrict what can be executed.
In this context, Zed invokes the user's shell, and the shell's features (including arithmetic expansion) remain available, even when Zed believes it is enforcing a restricted set of terminal commands.
Exploit preconditions
- Attack surface: Zed terminal or any feature that accepts shell commands and uses the terminal tool permission system.
- Required access: Ability to enter or influence terminal commands in Zed (e.g., local user, plugin, or integration that injects commands).
- Trigger point: Execution of an allowlisted command that includes Bash arithmetic expansion syntax, such as
echo $((...)). - Why exploitation is possible: The permission system validates only the outer command pattern (e.g.,
echo) and does not account for shell-level expansions, allowing arbitrary commands to be evaluated inside$((...))despite the apparent restriction.
Why this happens
This issue stems from relying on string-based allowlisting of shell commands without accounting for the shell's full parsing and expansion rules.
When Zed launches a shell with an allowlisted command like echo, the shell still interprets arithmetic expansion ($((...))), which can reference commands or expressions that lead to arbitrary command execution.
Conceptually, this maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, where user-controllable input is passed to a command interpreter without correctly neutralizing or constraining meta-characters and expansion features.
Potential impact
- Execution of arbitrary shell commands within the user's environment.
- Reading, modifying, or deleting files accessible to the user account running Zed.
- Exfiltration of local project files, SSH keys, API tokens, or configuration secrets.
- Use of the compromised environment as a stepping stone for further attacks (e.g., installing malware, backdoors, or persistence mechanisms).
General mitigation guidance
Effective mitigation focuses on eliminating shell interpretation of untrusted data and avoiding partial command allowlists:
- Prefer executing tools via direct process invocation (e.g.,
execve-style APIs) with argument arrays instead of passing a composed string to a shell. - If a shell must be used, disable or strictly constrain expansion features (arithmetic, command, and parameter expansion) for restricted contexts.
- Replace pattern-based allowlists (e.g., "only allow commands starting with
echo") with structured policies that validate discrete arguments and forbid embedded shell syntax. - Apply a denylist for known shell metacharacters and expansions, in addition to allowlists, while recognizing that denylisting alone is not sufficient.
- Run terminal-related processes with the least privileges needed and limit access to sensitive files where possible, so that impact is reduced even if a bypass occurs.
How teams detect issues like this
Potential detection and assurance strategies include:
- Static analysis and code review: Look for any use of shells (
/bin/sh,bash,sh -c) with user-influenced command strings, especially when combined with custom permission or allowlist logic. - Policy checks: Enforce development policies disallowing string-based shell execution in security-sensitive components; require use of structured process execution APIs instead.
- Automated scanning: Use SAST tools or linters configured to flag OS command execution patterns that interpolate user input or rely on partial command validation.
- Runtime monitoring: Where feasible, monitor spawned child processes and shell invocations from the editor to detect anomalous commands that deviate from expected tool use.

