Summary
OpenClaw versions prior to 2026.1.29 contain an OS command injection issue in the sshNodeCommand helper and SSH target parsing logic, where user-controlled values are embedded into shell commands and SSH arguments without proper escaping or validation.
An attacker who can influence the Project Root Path or SSH target string can cause arbitrary commands to execute either on the remote SSH host or on the local machine where OpenClaw runs.
Affected context
This vulnerability appears in OpenClaw's SSH integration layer, specifically where it:
- Builds shell scripts to run on remote nodes via SSH (
sshNodeCommand) - Parses user-supplied or configuration-supplied SSH target strings (
parseSSHTarget)
Risk is present when:
- Project root paths are derived from user input, environment values, or untrusted configuration
- SSH targets can be specified or influenced by users, automation scripts, or external systems
In those situations, the tool may treat attacker-controlled strings as shell content or SSH options instead of opaque data.
Exploit preconditions
- Attack surface (remote host path injection):
- OpenClaw must be configured to connect to a remote SSH node.
- The Project Root Path used by
sshNodeCommandmust be controllable or influenceable by an attacker (direct input, config, or environment). - The generated shell script must hit the error path where
cdfails, triggering the echo of the path. - Because the path is interpolated unescaped into a shell
echostatement, embedded shell metacharacters can break out and run arbitrary commands on the remote host. - Attack surface (local SSH target injection):
- The parseSSHTarget function must accept SSH targets from an attacker-controlled source.
- The implementation must allow targets starting with
-, which SSH interprets as flags rather than hostnames. - A target such as
-oProxyCommand=...will be passed directly to the localsshbinary, causing execution of attacker-controlled commands via SSH configuration mechanisms. - Why exploitation is possible:
- Shell commands are composed via string concatenation without robust quoting/escaping of user-controlled fields.
- SSH target arguments are not validated to distinguish between hostnames and option-style arguments, enabling abuse of SSH's option parsing.
Why this happens
The core defect maps to CWE-78: OS Command Injection and stems from treating user-influenced strings as if they were safe to embed directly into command lines.
In sshNodeCommand, the project root path is included in a shell script without proper quoting, particularly in the error-handling branch where a failed cd results in an echo that interpolates the raw path. Shell metacharacters and control operators inside the path can therefore terminate the echo and introduce additional commands.
In parseSSHTarget, the lack of validation that SSH target strings must not begin with a dash allows attacker-controlled targets to be interpreted as SSH flags. When passed straight to the ssh client, these option-style arguments (e.g., -oProxyCommand=...) can invoke arbitrary commands on the local machine. In both cases, command construction fails to enforce strict separation between data and executable shell/SSH syntax.
Potential impact
- Execution of arbitrary commands on remote SSH hosts reachable by OpenClaw
- Execution of arbitrary commands on the local system running OpenClaw via malicious SSH options
- Unauthorized access to files, credentials, or other sensitive resources on affected systems
- Lateral movement to other infrastructure accessible from compromised machines
- Disruption of OpenClaw workflows, including data tampering or denial of service
General mitigation guidance
Effective mitigation focuses on eliminating untrusted data from command syntax and tightening argument validation:
- Use structured process invocation APIs (e.g., direct argument lists) instead of building raw shell strings when invoking
sshor remote commands. - Apply strict, context-appropriate quoting and escaping to any user-controlled values that must appear in shell scripts, and avoid interpolating them into command positions.
- Validate SSH targets so they conform to expected patterns (e.g., hostname or
[user@]host[:port]) and explicitly reject values starting with-or containing disallowed characters. - Separate error messages from command execution paths; avoid echoing raw untrusted input in a way the shell can interpret.
- Run OpenClaw and its SSH-related components with least-privilege accounts and constrained environments to limit blast radius if an injection occurs.
How teams detect issues like this
Detection typically combines code-level analysis and runtime monitoring:
- Static analysis and code review:
- Search for string concatenation or interpolation used to build shell commands, especially where project paths, SSH targets, or other external inputs are involved.
- Flag any usage where untrusted data is placed into command lines without explicit quoting, or where it appears before the first literal command token.
- Identify parsing routines (like
parseSSHTarget) that do not enforce strict schemas and allow leading dashes or control characters. - Policy and tooling:
- Enforce secure coding guidelines that prohibit raw shell construction with user input, using automated linters or SAST tools to detect violations.
- Add unit and integration tests that feed malformed project paths and SSH targets (e.g., with
;,&&, or-oprefixes) to confirm they are rejected or safely handled. - Runtime monitoring:
- Monitor command execution logs for suspicious SSH invocations containing unexpected options or unusual characters in remote paths.

