OpenClaw Arbitrary Code Execution via Environment Variable Override (CVE-2026-41336)
OpenClaw before 2026.3.31 allows attackers to execute arbitrary code by overriding the OPENCLAW_BUNDLED_HOOKS_DIR environment variable using a workspace .env file, enabling the loading of attacker-controlled hook code.
OpenClaw versions prior to 2026.3.31 are susceptible to an arbitrary code execution vulnerability, tracked as CVE-2026-41336. This flaw stems from the application’s insecure handling of environment variables. Specifically, the OPENCLAW_BUNDLED_HOOKS_DIR environment variable, which dictates the directory from which OpenClaw loads bundled hooks, can be overridden by a workspace-specific .env file. This allows a malicious actor to craft a .env file within an untrusted workspace that points to a directory containing attacker-controlled hook code. Upon loading the workspace, OpenClaw will execute the malicious code, effectively granting the attacker arbitrary code execution within the application’s context. This vulnerability poses a significant risk to systems utilizing OpenClaw, as it can lead to complete system compromise.
Attack Chain
- The attacker creates a malicious hook code file (e.g.,
evil_hook.py) containing arbitrary code to be executed. - The attacker creates a directory (e.g.,
/tmp/evil_hooks) and places the malicious hook code file within it. - The attacker crafts a
.envfile containing the lineOPENCLAW_BUNDLED_HOOKS_DIR=/tmp/evil_hooks. - The attacker places the malicious
.envfile into a workspace that a victim user is likely to open within OpenClaw. - The victim user opens the workspace within OpenClaw.
- OpenClaw reads the
.envfile and overrides the defaultOPENCLAW_BUNDLED_HOOKS_DIRwith the attacker-controlled path/tmp/evil_hooks. - OpenClaw loads and executes the malicious hook code from
evil_hook.py, granting the attacker arbitrary code execution. - The attacker gains control of the OpenClaw process and potentially the underlying system.
Impact
Successful exploitation of CVE-2026-41336 allows an attacker to execute arbitrary code within the context of the OpenClaw application. This could lead to the complete compromise of the affected system, including data theft, modification, or destruction. Given the nature of the vulnerability, any system running a vulnerable version of OpenClaw is at risk if it processes untrusted workspaces. The CVSS v3.1 base score of 7.8 reflects the high potential impact of this vulnerability.
Recommendation
- Upgrade OpenClaw to version 2026.3.31 or later to patch CVE-2026-41336.
- Implement strict workspace validation to prevent the loading of malicious
.envfiles. - Monitor process creations originating from the OpenClaw process for suspicious activity using the
OpenClaw Suspicious Process CreationSigma rule. - Deploy the
OpenClaw Environment Variable OverrideSigma rule to detect attempts to override the OPENCLAW_BUNDLED_HOOKS_DIR variable.
Detection coverage 2
OpenClaw Suspicious Process Creation
highDetects suspicious processes spawned by OpenClaw, indicating potential code execution.
OpenClaw Environment Variable Override
mediumDetects attempts to override the OPENCLAW_BUNDLED_HOOKS_DIR environment variable, potentially leading to code execution.
Detection queries are kept inside the platform. Get full rules →