Summary
OpenClaw versions prior to 2026.1.20 contain a command injection vulnerability where an unauthenticated local client can abuse the Gateway WebSocket API to write configuration and set a malicious cliPath.
When this unsafe cliPath is later used for command discovery, attacker-controlled shell commands may be executed with the privileges of the gateway user.
Affected context
The issue arises in OpenClaw deployments where the Gateway WebSocket API is reachable by local processes and accepts unauthenticated requests.
Specifically, it affects instances that:
- Expose the Gateway WebSocket API on the local system
- Allow
config.applyoperations without robust authentication or authorization checks - Use the
cliPathconfiguration value for command discovery or execution without proper sanitization
In such environments, any local user or process capable of connecting to the WebSocket endpoint may influence how external commands are located and run.
Exploit preconditions
- Attack surface: Local machine, via the Gateway WebSocket API endpoint.
- Required access: Ability to open a WebSocket connection to the Gateway as a local client (no authentication required in the vulnerable configuration).
- Trigger point: Invocation of
config.applyto write configuration, including a craftedcliPathvalue that is later consumed by the command discovery logic. - Why exploitation is possible: The API trusts configuration updates from unauthenticated local clients (CWE-306) and later uses the attacker-controlled
cliPathdirectly in OS command contexts without robust validation or escaping (CWE-78).
Why this happens
The vulnerability stems from a combination of missing authentication for a sensitive configuration operation and unsafe handling of configuration data when invoking OS commands.
The Gateway WebSocket API allows config.apply calls without enforcing strong authentication or authorization, which aligns with CWE-306: Missing Authentication for Critical Function.
The cliPath configuration field, once set, is later used in command discovery or execution logic, effectively assembling shell or process invocation parameters from untrusted input.
Because this value is not constrained to safe paths or sanitized to prevent interpretation as arbitrary shell syntax, it falls under CWE-78: Improper Neutralization of Special Elements used in an OS Command, enabling command injection.
Potential impact
- Execution of arbitrary OS commands as the gateway user.
- Reading, modifying, or deleting data accessible to the gateway account.
- Installing or running additional malware or persistence mechanisms on the host.
- Pivoting to other processes or services reachable from the compromised gateway.
- Interference with or manipulation of OpenClaw assistant behavior via compromised environment or tooling.
General mitigation guidance
Effective mitigation relies on tightening both configuration trust boundaries and command execution patterns:
- Require authentication and, where appropriate, authorization checks for any configuration-modifying API, especially those that affect command paths or execution behavior.
- Treat all configuration values that influence execution (such as
cliPath) as untrusted until validated, even when they originate from local clients. - Constrain
cliPathand similar fields to a restricted set of allowed binaries or directories (allowlists) instead of accepting arbitrary strings. - Avoid passing configuration values through a shell; prefer direct execution of fixed binaries with explicit argument lists, and avoid string concatenation for building commands.
- Run the gateway service under a minimally privileged account and apply OS-level hardening (e.g., filesystem permissions, application sandboxing) to limit damage if a command is compromised.
How teams detect issues like this
Organizations can look for this class of issue using a mix of code-level and operational signals:
- Static analysis and code review:
- Flag APIs that modify configuration (e.g.,
config.apply) when they are callable without authentication or live on locally exposed ports. - Search for places where configuration values are used to construct command-line strings or passed into shell-executing functions (
exec,popen, or equivalent) without clear validation. - Review for any dynamic command discovery mechanisms that rely on user- or client-controlled paths.
- Policy and testing:
- Enforce security review for any feature that adjusts execution paths or tooling configuration.
- Include tests that attempt to inject shell metacharacters or unexpected paths via configuration channels and verify they are rejected or safely handled.
- Runtime monitoring:
- Monitor gateway processes for unusual child process trees, unexpected binaries executing, or anomalous command-line patterns.
- Correlate configuration changes over the WebSocket API with subsequent process launches to detect suspicious sequences.

