Summary
OpenClaw versions before 2026.3.13 contain an OS command injection vulnerability in the iMessage attachment staging flow, where untrusted remote attachment paths are passed directly into an SCP command.
When remote attachment staging is enabled, an attacker can craft attachment paths with shell metacharacters that result in arbitrary command execution on configured remote hosts.
Affected context
This vulnerability appears in OpenClaw deployments that use the iMessage attachment staging feature with remote hosts configured for SCP-based transfer.
It becomes relevant when:
- Remote attachment staging is enabled and actively used
- User-controlled or otherwise untrusted attachment paths are incorporated into shell commands
- The staging logic constructs SCP invocations by concatenating attachment paths into the remote operand without proper quoting or validation
Environments that do not rely on remote attachment staging or that strictly control the source of attachment paths are less exposed, but still warrant review.
Exploit preconditions
- Attack surface: iMessage attachment ingestion and staging pipeline within OpenClaw.
- Required access: Ability to supply or influence the remote attachment path used for staging (e.g., via crafted messages, attachments, or upstream integrations).
- Configuration requirement: Remote attachment staging must be enabled and configured to use SCP to one or more remote hosts.
- Trigger point: Execution of the SCP command that incorporates the attacker-controlled path as the remote operand.
- Why exploitation is possible: The code passes unsanitized attachment paths directly to a shell command line, allowing shell metacharacters (such as separators, redirection operators, or command substitution syntax) to be interpreted by the shell, leading to arbitrary command execution on the remote host.
Why this happens
The underlying issue is an OS command injection flaw corresponding to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Instead of treating the remote attachment path purely as data, the implementation appears to construct an SCP command string by concatenating the path into a shell-invoked command.
Because shell metacharacters in the remote operand are not validated, escaped, or otherwise neutralized, the shell parses them as part of the command language rather than as literal file path content.
This pattern—building command strings from untrusted input and executing them via a shell—creates a generic injection sink where attackers can append or inject additional commands to be executed on the target system.
Potential impact
- Remote attackers could execute arbitrary commands on configured remote hosts used for attachment staging.
- Attackers may gain a foothold on remote servers, potentially leading to full system compromise depending on the SCP account privileges.
- Malicious commands could alter, exfiltrate, or destroy staged attachments and related data.
- Compromised remote hosts might be leveraged for lateral movement within the broader infrastructure.
- Attackers could implant backdoors, modify application behavior, or interfere with monitoring and logging on affected hosts.
General mitigation guidance
Reducing the risk of this class of vulnerability typically involves eliminating direct shell interpretation of untrusted input and constraining how external commands are invoked.
Recommended defensive patterns include:
- Avoid shell invocation for SCP calls: Use APIs or libraries that perform SCP/SFTP transfers without invoking a shell (e.g., native SSH/SCP client libraries that accept parameters as structured arguments, not strings).
- Strictly separate data from commands: When external programs are unavoidable, construct argument lists (e.g., execve-style calls) and avoid passing concatenated command strings to a shell.
- Normalize and validate attachment paths: Enforce strict allowlists for allowed characters and path patterns (e.g., limit to alphanumeric plus a small set of safe delimiters), rejecting or sanitizing any input containing shell metacharacters or control characters.
- Constrain remote execution context: Run the SCP endpoint accounts with least privilege, minimal shell capabilities, and restricted access to the filesystem and network.
- Design for safe defaults: Make remote staging disabled by default or require explicit secure configuration, and document the security implications of enabling remote command-based features.
Applying these patterns generically to all command-invocation sites in the codebase helps prevent future instances of similar bugs.
How teams detect issues like this
Detection efforts can focus on both code-level patterns and runtime behavior:
- Static analysis: Configure static analysis rules to flag:
- Use of shell-based execution APIs (e.g., system, popen, exec with
shell=True, or similar) that incorporate variables derived from external input. - String concatenation or interpolation used to build command lines from user-controlled data.
- Code review cues:
- Look for code constructing SCP or SSH command strings with formatted remote operands containing user or message-derived paths.
- Identify any path handling logic that does not normalize or strictly validate characters before invoking external tools.
- Security policy enforcement:
- Enforce internal guidelines that prohibit shell-based command composition for network file transfers and require argument-array APIs or dedicated libraries.
- Integrate pre-commit or CI checks that scan for known dangerous command invocation patterns.
- Runtime monitoring:
- Monitor remote hosts for unusual command patterns originating from the OpenClaw staging process (e.g., unexpected shells, pipelines, or redirections in SCP-invoked sessions).
Automated code review tools and SAST products can help systematically surface OS command injection patterns across the codebase.

