Apr 3, 2026·7 min read·45 visits
Incomplete sanitization of compiler environment variables (such as CC and CXX) in OpenClaw allows an AI agent to hijack build tools and execute arbitrary code on the underlying host system.
OpenClaw versions prior to v2026.3.31 contain an environment variable injection vulnerability in the Host Environment Security Policy. An untrusted AI model can achieve arbitrary code execution on the host by supplying specific un-sanitized compiler environment variables during host-exec operations.
OpenClaw operates as a personal AI assistant capable of executing actions on the underlying operating system via its host-exec functionality. This feature relies on a defined trust boundary between the untrusted Large Language Model (LLM) agent and the host system. The application enforces a Host Environment Security Policy to sanitize environment variables before any shell commands requested by the model are executed.
The vulnerability exists in the implementation of this sanitization mechanism. OpenClaw utilizes a negative security model (a denylist) defined in src/infra/host-env-security-policy.json to filter out dangerous environment variables. Prior to version v2026.3.31, this list failed to account for several critical variables used by standard build tools to locate compiler binaries.
This flaw allows a malicious or compromised LLM to perform environment variable injection (CWE-454). By supplying unverified compiler environment variables during a host-exec task, the model can override the path to the executable invoked by tools like Make or CMake.
The successful exploitation of this vulnerability results in arbitrary code execution on the host OS. The malicious code runs with the same privileges as the OpenClaw process, entirely bypassing the intended sandbox restrictions placed on the AI model.
The fundamental root cause is the reliance on an incomplete negative security model for environment variable validation. When OpenClaw receives a command execution request from the LLM, it processes an accompanying set of environment variable overrides. The system checks these overrides against its denylist, discarding any key that matches a known dangerous variable (such as LD_PRELOAD or PATH).
Build automation tools, including Make, CMake, and Cargo, dynamically determine which compiler to invoke by inspecting specific environment variables. For example, Make uses the CC variable to locate the C compiler, while Cargo relies on CARGO_BUILD_RUSTC. The OpenClaw denylist did not include these specific variables.
This omission introduces an Uncontrolled Search Path Element (CWE-427) condition. When the build tool executes a compilation step, it spawns a child process using the binary specified by the injected environment variable. Because the input from the LLM passes through the sanitization check unmodified, the build tool implicitly trusts the malicious path.
Exploitation requires the model to have authorization to utilize the host-exec capability and necessitates the execution of a command that consumes the targeted toolchain variables. The vulnerability manifests at the exact moment the host system attempts to execute the expected toolchain binary.
The vulnerable implementation resided primarily within src/infra/host-env-security-policy.json. This configuration file defined the array of string keys that the runtime application would strip from any execution request originating from the LLM. The absence of CC and similar variables meant the input validation logic explicitly permitted them to pass to the OS layer.
The patch implemented in commit e277a37f896b5011a1df06e6490c6630074d0afa expanded this denylist. The update added several variables specific to C, C++, and Rust build toolchains.
// Added to src/infra/host-env-security-policy.json
[
"CC",
"CXX",
"CARGO_BUILD_RUSTC",
"CMAKE_C_COMPILER",
"CMAKE_CXX_COMPILER"
]Additionally, the patch synchronized these changes with the macOS native bridge located at apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift. This ensures that the native Swift validation logic, which executes commands on the macOS host, shares the exact same policy definitions as the TypeScript application layer.
While this fix successfully remediates the immediate attack vectors involving standard compiler overrides, the underlying architecture remains dependent on a denylist. This approach carries residual risk, as obscure build tools or specific language environments may utilize undocumented environment variables that are not present in the updated configuration file.
Exploitation begins with an attacker injecting a prompt that compels the OpenClaw agent to write a malicious payload to the host filesystem. This payload is typically a shell script containing the attacker's desired arbitrary commands. The script must be marked as executable by the host OS.
Once the payload is present on the disk, the agent initiates a legitimate build command via the host-exec interface. The command request includes an environment variable override that maps a compiler variable to the absolute path of the previously created malicious script.
The host system executes the build tool (e.g., make). When the tool reaches the compilation phase, it reads the injected CC variable. Instead of executing the system's standard C compiler, the tool executes the attacker's shell script. The script runs with the full system privileges of the parent OpenClaw process.
The regression test included in the fix commit demonstrates this precise proof-of-concept:
// Exploit scenario: Setting CC to a malicious script
const exploitPath = path.join(tempDir, "evil-cc");
fs.writeFileSync(exploitPath, `#!/bin/sh\ntouch /tmp/pwned\nexit 1\n`, "utf8");
fs.chmodSync(exploitPath, 0o755);
// The model triggers a command like 'make' with an environment override
await runMakeCommand(makePath, tempDir, {
...baseEnv,
CC: exploitPath,
});Successful exploitation of this vulnerability results in arbitrary code execution on the underlying host operating system. The attacker achieves complete control over the OpenClaw process, inheriting its user permissions, filesystem access, and network capabilities.
The estimated CVSS v3.1 vector for this vulnerability is CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H, yielding a score of 10.0. The Scope is marked as Changed (S:C) because the exploit allows an untrusted entity (the AI model operating within a restricted context) to compromise the underlying host environment.
This level of access severely compromises both confidentiality and integrity. An attacker can exfiltrate sensitive files, harvest local API keys, or establish persistent access mechanisms on the compromised machine. The availability of the system can also be degraded if the attacker chooses to terminate processes or consume system resources.
For agentic AI frameworks, vulnerabilities of this nature highlight the inherent risks of granting LLMs direct execution capabilities. Flaws in the sanitization boundary amplify the impact of standard prompt injection attacks, elevating them from isolated logical errors to full system compromise.
The primary remediation step is to update the OpenClaw installation to version v2026.3.31 or later. This release contains the updated HostEnvSecurityPolicy which blocks the known set of toolchain environment variables. Administrators must ensure that the update is applied across all active instances, particularly those running the macOS native bridge.
Organizations utilizing OpenClaw should implement robust logging to monitor host-exec requests. Security teams must configure alerts for any execution request originating from the LLM that attempts to supply overrides for variables like CC, CXX, CARGO_BUILD_RUSTC, or PATH. These logs provide essential telemetry for detecting ongoing prompt injection attempts.
To mitigate the risk of zero-day bypasses in the denylist, OpenClaw instances should be deployed within tightly restricted environments. Administrators should containerize the application or utilize robust OS-level sandboxing (such as AppArmor or macOS Sandbox). The host environment should grant the OpenClaw process only the minimum filesystem and network permissions necessary for its intended tasks.
From a development perspective, future iterations of OpenClaw should transition the Host Environment Security Policy from a denylist to a strict allowlist. By exclusively permitting a minimal set of known-safe environment variables, the system can systematically prevent injection attacks regardless of the specific build tools invoked by the model.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H| Product | Affected Versions | Fixed Version |
|---|---|---|
OpenClaw OpenClaw | < v2026.3.31 | v2026.3.31 |
| Attribute | Detail |
|---|---|
| CWE | CWE-454, CWE-427, CWE-78 |
| Attack Vector | Network (via AI Prompt/Agent execution) |
| CVSS Score | 10.0 |
| Impact | Arbitrary Code Execution on Host OS |
| Exploit Status | poc |
| Affected Component | HostEnvSecurityPolicy |
The product initializes critical internal variables or data stores using inputs that can be modified by untrusted actors.
CVE-2026-48861 is a client-side HTTP request-line CRLF (Carriage Return Line Feed) injection vulnerability in the popular Elixir HTTP client library, Mint. The vulnerability permits HTTP Request Splitting and HTTP Request Smuggling when an application forwards untrusted, attacker-controlled inputs to Mint's HTTP client requests as either the HTTP request method or target. By embedding CRLF characters within these parameters, an attacker can terminate the request line prematurely, inject malicious headers, or pipeline entirely independent requests. These smuggled requests are then processed by upstream or downstream proxy servers as separate HTTP queries on the same TCP connection. While Mint version 1.7.0 introduced target validation to secure the request target, the HTTP request method parameter remained completely unvalidated. This flaw allows attackers to bypass routing filters, access restricted internal APIs, or poison HTTP caches under default configurations.
An Inconsistent Interpretation of HTTP Requests (HTTP Request/Response Smuggling) vulnerability in the Elixir Mint HTTP client allows attacker-controlled HTTP/1 servers to desynchronize response framing on shared connections due to over-lenient parsing of sign-prefixed Content-Length headers.
An allocation of resources without limits or throttling vulnerability in Elixir Mint allows an attacker-controlled HTTP/2 server to exhaust memory in a Mint client. The vulnerability is exploited by sending a HEADERS frame without the END_HEADERS flag followed by an infinite stream of CONTINUATION frames. Because the client lacks limits on the incoming header-block accumulator, the client continuously consumes memory until an out-of-memory crash occurs.
CVE-2026-48596 is an Improper Neutralization of CRLF Sequences in HTTP Headers (HTTP Request/Response Splitting, CWE-113) in the Elixir Tesla HTTP client. The flaw resides in how multipart content-type parameters are joined and serialized, enabling attackers to inject arbitrary headers or split HTTP requests when applications pass untrusted inputs to the parameters of multipart uploads.
An improper handling of highly compressed data (decompression bomb) vulnerability exists in the Elixir Tesla HTTP client when utilizing response decompression middlewares. By serving highly compressed responses or stacked content-encoding headers, a malicious server can cause arbitrary heap exhaustion, leading to a denial of service (DoS) crash in the BEAM virtual machine.
A high-severity security vulnerability in Elixir's Tesla HTTP client library (CVE-2026-48595) allows unauthenticated remote attackers to harvest sensitive credentials, including Authorization headers and cookies. The flaw resides in the 'Tesla.Middleware.FollowRedirects' component, which performs case-sensitive lookups when stripping credentials during cross-origin redirects. Because HTTP headers are case-insensitive by RFC specifications, standard canonical casing (e.g., 'Authorization') bypasses the lowercase-only blocklist, leaking tokens to untrusted external redirect destinations.