Summary
A command injection vulnerability in tufantunc ssh-mcp up to version 1.5.0 allows crafted input passed to the shell.write function to be interpreted as part of a system command.
When a local attacker can influence the Description argument, they may execute arbitrary commands with the privileges of the ssh-mcp process.
Affected context
This vulnerability affects environments where ssh-mcp (up to 1.5.0) is installed and used to interact with a shell via the shell.write function in src/index.ts.
The issue arises when user-controllable data, specifically the Description argument, is incorporated into shell commands without proper sanitization or escaping.
It primarily impacts local workflows, scripts, or tools that expose shell.write to untrusted or semi-trusted input.
Exploit preconditions
- Attack surface: Local system where ssh-mcp is installed and executed.
- Required access: Ability to run ssh-mcp or to pass data into the
Descriptionargument that is ultimately used byshell.write. - Trigger point: Invocation of
shell.writewith unvalidatedDescriptioncontent that becomes part of a shell command or shell-interpreted string. - Why exploitation is possible: The application constructs or forwards shell commands using unsanitized input, allowing shell metacharacters and operators to alter command boundaries and inject additional commands.
Why this happens
The underlying issue maps to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') and CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.
In ssh-mcp, the shell.write function appears to directly interpolate or forward the Description argument into a shell execution context without carefully filtering, escaping, or separating data from executable command syntax.
This pattern treats user-controllable strings as part of the command line, enabling shell control characters (such as pipes, redirections, or command separators) to be interpreted as executable instructions instead of inert data.
Potential impact
- Execution of arbitrary OS commands with the privileges of the ssh-mcp process
- Reading or modification of local files accessible to the affected user account
- Installation or execution of additional malicious software or scripts
- Local privilege escalation when combined with other misconfigurations or vulnerabilities
- Tampering with local development, build, or deployment workflows that rely on ssh-mcp
General mitigation guidance
Effective mitigation focuses on eliminating direct command construction from untrusted data and constraining interactions with the shell:
- Use parameterized or API-based execution (e.g., spawn commands with argument arrays instead of concatenated strings) to clearly separate data from command syntax.
- Apply strict input validation and allowlist-based filtering on the
Descriptionargument, rejecting or encoding shell metacharacters rather than attempting ad-hoc sanitization. - Prefer higher-level abstractions over raw shell invocation, such as language-native libraries for file and process operations instead of shelling out.
- Run ssh-mcp with the least privileges required (non-root user, limited filesystem and environment access) to minimize damage if command injection occurs.
- Introduce defensive coding guidelines and code review checklists that flag any string concatenation used in command execution paths.
How teams detect issues like this
Identifying this class of issue typically combines static analysis, code review, and behavioral monitoring:
- Configure static analysis tools to detect command execution functions that receive concatenated or string-interpolated arguments containing user input (e.g., use of
exec,spawn, backticks, or shell wrappers). - During code review, look for patterns where shell commands are assembled using template literals, string concatenation, or unescaped variables, especially around
shell.writeand similar abstractions. - Implement secure coding policies that require argument-array APIs for process execution and forbid passing entire command lines as unstructured strings when user input is involved.
- Use runtime monitoring or audit logs to flag unusual command lines spawned by ssh-mcp, such as unexpected operators, chained commands, or access to sensitive paths.

