Summary
electerm's SFTP "open with system editor" and "edit with custom editor" features previously passed remote filenames directly into a local shell command without sanitization, allowing shell metacharacters in filenames to be interpreted as commands.
If an attacker controls the SSH server or can influence filenames on the user's system, they may craft a malicious filename that, when edited through electerm, leads to arbitrary code execution on the victim's machine with the user's privileges.
Affected context
This vulnerability occurs on client machines running electerm when users use the SFTP file browser to open or edit files with the system editor or a custom editor.
It is most relevant when:
- The user connects to an untrusted or compromised SSH/SFTP server, or
- The attacker can influence filenames on locations the user will browse with electerm.
The problem manifests at the point where electerm constructs and executes a local command line that embeds the remote filename without proper quoting or escaping.
Exploit preconditions
- Attack surface: electerm client on the end-user's machine, specifically the SFTP "open with system editor" or "edit with custom editor" feature.
- Required access: Ability to control or influence the target filename, typically by:
- Controlling the SSH/SFTP server and creating files with malicious names, or
- Having write access to directories the user will browse via SFTP.
- User interaction: The victim must choose to open/edit the attacker-controlled file using the vulnerable feature.
- Trigger point: electerm spawns a local system command that includes the filename unquoted or unsanitized.
- Why exploitation is possible: Shell metacharacters embedded in the filename are interpreted by the local command shell, turning parts of the filename into executable commands (CWE-78 / CWE-88).
Why this happens
The core issue is improper construction of command lines that include user-controllable data—in this case, filenames obtained over SFTP.
Instead of passing the filename as a separate, safely-escaped argument to the editor process, electerm interpolated the raw filename into a shell command string.
Shells interpret special characters (such as ;, &, |, backticks, or $()), so a filename containing these characters is not treated as inert data but as part of the command itself.
This aligns with CWE-78 (Improper Neutralization of Special Elements used in an OS Command) and CWE-88 (Argument Injection or Modification), where user input is directly embedded into commands without strict quoting or argument separation.
Potential impact
- Execution of arbitrary commands on the victim's workstation with the victim's user privileges.
- Installation of malware, backdoors, or credential stealers on the client system.
- Lateral movement within the victim's network using the compromised host.
- Exfiltration or destruction of local files accessible to the victim's account.
- Abuse of the victim's SSH keys or other secrets stored on the machine.
General mitigation guidance
Effective mitigation typically focuses on safe command construction and reducing trust in remote filenames:
- Invoke editors without going through a command shell; pass the filename as a discrete argument to the process API (e.g., spawn/exec with argument arrays).
- Apply strict quoting or escaping routines for any data that must cross a shell boundary, and avoid building commands via string concatenation.
- Normalize and validate filenames received from remote servers, rejecting or safely handling names containing dangerous metacharacters.
- Provide security-conscious defaults for external tool integration, limiting how much of the command line is user-configurable and disallowing uncontrolled substitution of remote values.
- Run the client application with least privilege and avoid granting it elevated OS permissions, so that a compromise has limited blast radius.
How teams detect issues like this
Detection can rely on a combination of code-level analysis and behavioral review:
- Static analysis: Search for command execution APIs (e.g.,
exec,spawn,child_process.execin Node.js or equivalents) where arguments are constructed using string concatenation with values derived from remote filenames or SFTP listings. - Code review cues: Identify flows where remote or user-controlled filenames are:
- Interpolated into command strings, or
- Passed through to shells instead of safe process APIs.
- Policy enforcement: Establish coding guidelines that ban direct shell invocation with untrusted data and require the use of argument-array-based process spawning.
- Automated tooling: Use SAST tools and linters configured with rules specific to command injection to flag unsafe command construction patterns in pull requests.

