Summary
OpenClaw versions prior to 2026.2.2 contain a command injection vulnerability in the exec approvals allowlist feature, where shell command substitution within double-quoted strings is not safely handled.
By embedding unescaped $() or backtick syntax in approved commands, an attacker can bypass the allowlist and execute arbitrary, unauthorized commands on the underlying system.
Affected context
This vulnerability arises in OpenClaw deployments that:
- Have the exec approvals feature enabled
- Rely on an allowlist to restrict which commands can be executed
- Build or pass commands through a shell where command substitution (
$()or backticks) is interpreted
The issue typically manifests where user-controlled input is interpolated into shell commands or command templates and only the outer command is validated, while embedded substitutions are not constrained or sanitized.
Exploit preconditions
- Attack surface: Interfaces that trigger command execution through OpenClaw's exec approvals mechanism (e.g., web UI actions, APIs, or automation hooks that end up invoking shell commands).
- Required access: Ability to submit or influence command strings that are subject to the exec allowlist check (such as specifying parameters, command arguments, or templates).
- Trigger point: Execution of an "approved" command that contains double-quoted segments with embedded
$()or backtick expressions. - Why exploitation is possible: The allowlist validation focuses on the top-level command string and does not neutralize or block shell command substitution operators. When executed in a shell context, these operators are evaluated, allowing attacker-controlled subcommands to run despite the apparent allowlist restrictions.
Why this happens
The underlying issue is improper neutralization of special elements in command strings, aligning with CWE-78 (Improper Neutralization of Special Elements used in an OS Command) and CWE-88 (Argument Injection or Modification).
OpenClaw's exec approvals allowlist appears to validate only the high-level command or its leading tokens, without accounting for nested shell syntax that can introduce additional commands.
By placing $() or backticks inside double-quoted strings, an attacker can inject additional OS commands that the shell evaluates at runtime, effectively bypassing the allowlist and resulting in arbitrary command execution under the privileges of the OpenClaw process or associated service account.
Potential impact
- Execution of arbitrary OS commands under the OpenClaw runtime user, which can lead to full system compromise.
- Reading, modifying, or deleting sensitive data accessible to the OpenClaw host or connected systems.
- Installing backdoors, cryptocurrency miners, or other persistent malware on the affected host.
- Moving laterally to other systems or services reachable from the compromised environment.
- Tampering with build, deployment, or operational pipelines that depend on OpenClaw, enabling further supply-chain impacts.
General mitigation guidance
Effective mitigation focuses on removing shell interpretation from user-controlled input and constraining command execution:
- Prefer APIs or libraries that execute commands without involving a generic shell (e.g., using direct system calls or parameterized process execution APIs that accept argument arrays rather than raw command strings).
- If a shell must be used, rigorously neutralize or disallow command substitution operators (
$(), backticks) and other metacharacters in any user-controlled segments, and enforce strict patterns for allowed arguments. - Design allowlists around structured operations rather than raw command strings; map high-level actions to fixed, server-side command templates with no direct interpolation of attacker-controlled data into shell-executed segments.
- Apply least-privilege principles to the OpenClaw runtime environment so that the executing process has minimal system access, reducing the blast radius of any injection that does occur.
- Consider sandboxing or containerizing the execution environment with restricted capabilities to limit file system and network access.
How teams detect issues like this
Detection typically combines code-level analysis with runtime monitoring:
- Use static analysis or manual code review to identify places where OpenClaw constructs shell commands from user-controlled input, particularly where exec approvals or allowlists are implemented via string matching rather than structured execution.
- Look for patterns such as:
- Passing concatenated strings to generic shell interpreters (e.g.,
/bin/sh -c,system,popen, or similar APIs). - Allowlist checks that only inspect the prefix or a subset of a command, without parsing or validating nested syntax.
- Absence of explicit handling or rejection of
$(), backticks, or other metacharacters in user input. - Implement runtime logging and monitoring around all exec approvals to detect unusual command patterns, especially commands containing
$(,`, semicolons, or other chaining operators. - Integrate security scanning tools that include rules for OS command injection and shell metacharacter misuse into CI/CD pipelines to prevent reintroduction of similar patterns.

