/

CVE-2026-25157

Severity:

HIGH RISK

(7.7)

OS Command Injection in OpenClaw sshNodeCommand and SSH

CVE-2026-25157

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote and Local Command Execution

Severity:

HIGH RISK

(7.7)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 sshNodeCommand must be controllable or influenceable by an attacker (direct input, config, or environment).
  • The generated shell script must hit the error path where cd fails, triggering the echo of the path.
  • Because the path is interpolated unescaped into a shell echo statement, 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 local ssh binary, 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 ssh or 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 -o prefixes) 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.

Sources

SourceLink
github.comgithub.com/openclaw/openclaw/security/advisories/GHSA-q284-4pvr-m585

Frequently asked

questions

Yes, if an attacker can supply or influence the Project Root Path or SSH target (for example through a user-facing configuration, API, or integration), they can potentially trigger command execution on either the remote or local system. If those values are not exposed to untrusted users, the risk is reduced but still present if upstream systems can be compromised.

The attacker must be able to control or inject values into the Project Root Path used by sshNodeCommand or the SSH target parsed by parseSSHTarget. This might be through direct user input, configuration files, environment variables, or orchestration tooling that OpenClaw trusts.

The safest pattern is to stop composing shell command strings with untrusted data entirely. Instead, call ssh and related commands using APIs that take argument arrays, validate and sanitize paths and hostnames according to strict schemas, and forbid inputs that could be interpreted as flags or shell metacharacters.

Adopt a defensive design approach where all external input is treated as hostile: define strict input formats, centralize validation, ban raw shell concatenation in code standards, and use static analysis or CI checks to enforce these rules. Complement this with security reviews of any component that builds command lines or interacts with SSH or other system utilities.

Find out what's already
exploitable in your codebase.