Summary
OpenClaw's exec-approvals allowlist validates command arguments before shell expansion, but the actual execution occurs with real shell expansion semantics.
This mismatch allows authorized callers or prompt-injection driven requests to use seemingly safe commands (e.g., head, tail, grep) together with glob patterns or environment variables to read arbitrary local files accessible to the gateway or node process when host execution is enabled.
Affected context
The vulnerability appears in OpenClaw deployments that:
- Enable host execution behind the exec-approvals gateway
- Rely on an allowlist of "safe" binaries (e.g., head, tail, grep) for command execution
- Perform validation on pre-expansion argv tokens while ultimately invoking a real system shell that performs globbing and environment variable expansion
It primarily affects environments where untrusted or partially trusted inputs (including LLM or prompt-driven tools) can influence the arguments to these allowed commands.
Exploit preconditions
- Attack surface: Exec-approvals gateway or any interface that can trigger host command execution in allowlist mode.
- Required access:
- Ability to submit commands or arguments through an approved caller, API, or workflow; or
- Capability to influence prompts or tool instructions that the system converts into shell commands (prompt injection).
- Trigger point: Execution of an allowlisted binary through the gateway when its arguments include shell-metacharacters, glob patterns (*, ?, []), or environment variable references ($VAR, ${VAR}).
- Why exploitation is possible: The validation logic inspects the unexpanded argv tokens as though they will be used directly, but the underlying execution path invokes a real shell that performs expansion. As a result, malicious file patterns or variable references can bypass validation and cause the allowed command to operate on arbitrary local files.
Why this happens
This issue stems from a classic OS command injection pattern mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command.
The security model assumes that validating the raw argv tokens is sufficient to constrain behavior, but those tokens are later passed through a shell that performs additional processing (globbing, variable expansion). Because the validation does not reason about the post-expansion form and does not neutralize shell metacharacters, attackers can craft arguments that are benign in pre-expansion form yet expand to sensitive file paths or content sources at execution time. The core design flaw is mixing shell semantics with application-level access control while validating only a subset of the effective command behavior.
Potential impact
- Disclosure of arbitrary local files readable by the gateway or node process (e.g., application logs, config files, API keys, tokens).
- Exposure of secrets embedded in environment variables via expanded references.
- Leakage of system metadata (e.g., /proc, /etc) that can assist in further attacks or lateral movement.
- Violation of intended allowlist boundaries, where "safe" commands become powerful data exfiltration tools.
- Potential chaining with other vulnerabilities or misconfigurations to escalate impact beyond file disclosure.
General mitigation guidance
Effective mitigation focuses on removing shell semantics from the execution path and tightening the trust boundary around arguments:
- Prefer direct exec-style APIs (e.g., execve/posix_spawn, subprocess with shell disabled) that do not invoke a system shell or perform globbing or environment variable expansion.
- Treat all user-controlled and prompt-controlled arguments as untrusted; perform strict allowlisting of both commands and argument patterns, not just binary names.
- Normalize and validate arguments in the exact form they will be executed, avoiding any implicit transformations after validation.
- Limit the file system exposure of the gateway or node process by running with least privilege, constrained working directories, and restricted access to sensitive paths.
- Consider introducing an intermediate policy layer that only allows references to approved resources (e.g., specific directories or file types) instead of arbitrary paths.
- Reduce reliance on environment-variable derived secrets for processes that can be reached via exec-approvals, preferring separate, tightly scoped secret stores.
How teams detect issues like this
To detect and monitor for this class of issue:
- Use static analysis and code review to flag:
- Any execution paths that call out to a shell (e.g., system(), popen(), subprocess with shell=True) from within allowlist or approval logic.
- Validation routines that inspect argv but later pass values to shell-based runners without re-validation.
- Add explicit checks in CI/CD pipelines to prevent introduction of shell-based execution for security-sensitive gateways.
- Instrument logging around exec-approvals:
- Record the full, post-expansion command where feasible (with careful handling of sensitive data).
- Alert on suspicious patterns such as wildcards targeting sensitive directories (/etc, /var, ~/.).
- Apply policy-based scanners or security linters that enforce "no shell execution in control-plane components" as an organizational rule.

