Summary
OpenClaw versions prior to 2026.2.22 contain an OS command injection vulnerability in system.run, where the shell command allowlist can be bypassed using crafted line-continuation sequences.
By injecting $\\ followed by a newline and an opening parenthesis inside double quotes, an attacker can transform benign-looking input into executable command substitution, enabling non-allowlisted commands to run despite security checks.
Affected context
This vulnerability manifests in environments where OpenClaw:
- Invokes shell commands via
system.rununder an allowlist-based security model - Passes user-controlled or indirectly influenced input into shell command strings
- Relies on static or naive parsing of command text to enforce which commands are permitted
The issue is specifically triggered when double-quoted segments of a command can contain shell metacharacters, including $, backslash, and newline, which are later interpreted by the shell in a way not reflected in the allowlist analysis.
Exploit preconditions
- Attack surface: Any OpenClaw feature, plugin, or integration that calls
system.runwith attacker-controlled or attacker-influenced command arguments. - Required access: Ability to supply or modify strings that are passed into
system.run(e.g., configuration fields, project definitions, scripts, or workflow parameters). - Trigger point: Execution of
system.runwhere: - The application performs allowlist checks on the static command text, and
- The shell eventually interprets the final command line, including line continuations and command substitution.
- Why exploitation is possible: The allowlist logic analyzes the "visible" command string but does not model how the shell normalizes
$\\+ newline +(inside double quotes. The shell folds this into active command substitution syntax at runtime, effectively injecting a new command path that was never evaluated against the allowlist.
Why this happens
The root cause is an OS command injection pattern (CWE-78) combined with incomplete modeling of shell parsing semantics in the security allowlist.
system.run relies on textual allowlist checks to decide which commands are permissible, assuming that the checked string will be executed as-is. However, POSIX-like shells perform multiple transformations—such as line continuation processing, quote handling, and command substitution—after the allowlist decision. Attackers exploit this gap by embedding $\\ followed by a newline and ( inside double quotes, producing input that looks harmless during static analysis but is interpreted as command substitution by the shell.
Conceptually, this is a mismatch between security validation on a pre-processed representation and actual interpretation by the execution environment, allowing untrusted data to cross trust boundaries and influence which commands are ultimately executed.
Potential impact
- Execution of non-allowlisted commands that would ordinarily be blocked by security policies
- Escalation of attacker capabilities within the OpenClaw runtime environment
- Unauthorized access to files, environment variables, or network resources reachable from the OpenClaw host
- Tampering with build, test, or deployment pipelines that depend on OpenClaw automation
- Lateral movement to other systems if the compromised environment has additional credentials or network trust
General mitigation guidance
Effective mitigation focuses on eliminating direct shell interpretation of untrusted strings and aligning validation with the true execution semantics:
- Prefer APIs that bypass the shell entirely (e.g., structured command execution where arguments are passed as arrays) instead of constructing shell command strings.
- Treat all user-controllable data as untrusted, even when wrapped in quotes, and avoid concatenating it into command text that will be parsed by a shell.
- When an allowlist is required:
- Implement checks on a structured representation of the command (e.g., parsed tokens or discrete arguments) rather than raw strings.
- Normalize or reject inputs that contain shell metacharacters (
$, backslash, backticks,(),|,&,;, newlines) in contexts where only simple arguments are expected. - Apply least privilege to any process spawned via
system.run, using restricted accounts and minimal file/system access to reduce the impact of misuse. - Centralize command execution logic so security checks and parsing rules are consistent, rather than duplicating them across the codebase.
How teams detect issues like this
Detection generally involves identifying unsafe command construction patterns and ensuring shell semantics are explicitly modeled:
- Static analysis:
- Flag any use of
system.run(or analogous wrappers) where raw strings are constructed via concatenation, interpolation, or templating with user input. - Detect presence of shell metacharacters and line-continuation sequences (
\followed by newline) within quoted segments that originate from untrusted sources. - Code review signals:
- Command allowlist logic that operates on raw strings without a formal parser.
- Reliance on quoting or escaping alone as a security control for untrusted input.
- Inconsistent handling of whitespace, newlines, or backslashes when building shell commands.
- Policy and tooling:
- Introduce coding standards that require argument-vector based command execution and prohibit dynamic shell string evaluation for untrusted data.
- Use automated review tools or custom linters to enforce safe command execution APIs and highlight deviations from the policy.

