Summary
Zed's SSH/WSL remote command handling previously constructed shell command strings using unquoted environment variable keys, allowing shell expansions embedded in those keys to be interpreted by the remote shell.
If an attacker can influence an environment variable key (for example through project terminal settings), they may trigger arbitrary command execution on the remote host under the victim user's account when a terminal is opened.
Affected context
The vulnerability manifests when Zed is used to open SSH or WSL terminals and constructs remote startup commands as a single shell command string.
In affected versions, environment variable keys are interpolated directly into a command that begins with exec env ... without quoting or validation.
This becomes risky in setups where environment variables or project terminal configuration can be partially controlled by less-trusted sources (such as shared project settings, templates, or synchronized workspace configs).
Exploit preconditions
- Attack surface: Zed's SSH/WSL remote command invocation flow.
- Required access: Ability to influence or set environment variable keys used by Zed for remote terminals (e.g., via project terminal settings or configuration files).
- Trigger point: Opening a remote terminal session in Zed, which constructs and executes an
exec env ...shell command on the remote host. - Why exploitation is possible: Environment variable keys are concatenated into a shell command without quoting or validation, so shell metacharacters and expansions (e.g.,
$(...), backticks) in the key are executed by the remote shell rather than treated as literal text.
Why this happens
The core issue is improper construction of shell commands with untrusted input, mapping directly to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Instead of treating environment variable keys as data, the implementation embeds them into a shell command string without quoting or escaping, effectively allowing shell syntax within the keys to alter the behavior of the command.
Because shells interpret constructs like command substitution, backticks, and other metacharacters before launching the target process, any attacker-controlled key that includes such syntax can cause arbitrary commands to run under the victim user's context.
Potential impact
- Execution of arbitrary commands on the remote host under the victim user's account.
- Unauthorized access to files and data reachable by the victim user on the remote system.
- Installation of backdoors or persistence mechanisms on the remote host.
- Lateral movement to other systems reachable from the compromised remote environment.
- Exfiltration or tampering with source code, credentials, or build artifacts stored on the remote machine.
General mitigation guidance
Since this vulnerability stems from command construction patterns, mitigations focus on treating all shell-adjacent data as untrusted by default:
- Prefer APIs that bypass the shell and pass arguments as structured arrays rather than raw command strings whenever starting remote commands.
- If shell usage is unavoidable, rigorously quote and escape all interpolated values, including environment variable keys and values, ensuring they are treated strictly as literals.
- Validate environment variable keys against a conservative allowlist (e.g., alphanumeric plus underscore) and reject or sanitize keys containing shell metacharacters.
- Limit where environment variables and terminal settings can be configured, particularly in shared project configurations, and clearly separate trusted from untrusted configuration sources.
- Apply least-privilege principles on remote accounts so that even if a terminal initialization command is abused, its ability to damage the system is constrained.
How teams detect issues like this
Effective detection generally combines code-level review with configuration scrutiny:
- Use static analysis or linters to flag string-built shell commands that interpolate configuration values, environment variables, or user-supplied data without quoting or escaping.
- In code review, treat any occurrence of
sh -c, backticks, or command substitution as a high-risk pattern and verify that every interpolated value is validated and safely encoded. - Introduce internal policies that prefer process-spawning APIs with explicit argument lists over shell-based invocation for internal tooling and developer workflows.
- Periodically audit project and workspace configuration files (including terminal or environment settings) for unexpected shell syntax in environment variable names or related fields, especially in shared or synchronized configurations.

