Repository navigation
Description
There are two gaps in the current system.run implementation that can allow a connected agent to bypass the intended exec approval policy or hijack execution of an otherwise approved command.
1. Environment variable injection
The request env dictionary is parsed in SystemCapability.cs:266 and passed to the runner at SystemCapability.cs:303. LocalCommandRunner then copies it directly into ProcessStartInfo.Environment at LocalCommandRunner.cs:52.
There is currently no denylist, allowlist, normalization, or blocking for sensitive variables such as PATH, PATHEXT, NODE_OPTIONS, GIT_SSH_COMMAND, LD_*, DYLD_*, BASH_ENV, PSModulePath, ComSpec, etc.
Example:
{
"command": ["git", "status"],
"env": {
"GIT_SSH_COMMAND": "evil.sh"
}
}The command can pass approval as git status, but execution behavior is silently altered by the injected environment. Similar risks apply to variables such as NODE_OPTIONS=--require=/tmp/payload.js, LD_PRELOAD=/evil.so, and BASH_ENV=/evil_script.
The current tests also assert that arbitrary env values are accepted as-is in SystemRunTests.cs:110.
2. Shell wrapper approval bypass
The policy evaluates fullCommand once in SystemCapability.cs:293, before execution. It does not parse or evaluate payloads inside shell wrappers such as bash -c, sh -c, cmd /c, powershell -Command, or pwsh -Command.
LocalCommandRunner then executes through cmd.exe, pwsh.exe, or powershell.exe depending on request.Shell (LocalCommandRunner.cs:177).
That means an inner wrapper payload can avoid rules intended to block the effective command. For example:
{
"command": ["powershell", "-Command", "Remove-Item -Recurse -Force C:\important"]
}If policy allows powershell *, or if defaultAction=allow, the outer command can be approved while the inner destructive payload is never evaluated against rules like Remove-Item *.
Existing tests cover direct argv evaluation, e.g. ["rm", "-rf", "/"] in ExecApprovalPolicyTests.cs:471, but there is no coverage for wrapper forms like:
["powershell", "-Command", "Remove-Item -Recurse -Force C:\important"]or:
["cmd", "/c", "del /s /q C:\important\*"]Proposed fix
I suggest two scoped PRs, both in OpenClaw.Shared:
-
ExecEnvSanitizer
- Block known execution-hook / loader / shell-influence variables such as
NODE_OPTIONS,LD_*,DYLD_*,GIT_SSH_COMMAND,BASH_ENV,ENV,PATH,PATHEXT,PSModulePath,ComSpec, etc. - Reject empty names and names containing invalid or suspicious characters.
- Compare names case-insensitively on Windows.
- Further restrict environment overrides when the command is detected as a shell wrapper, ideally allowing only low-risk variables such as locale/display settings.
- Block known execution-hook / loader / shell-influence variables such as
-
ExecShellWrapperParser
- Detect wrapper forms such as
bash -c,sh -c,cmd /c,cmd.exe /c,powershell -Command,powershell.exe -Command,powershell.exe -EncodedCommand, andpwsh -Command. - Unwrap bounded chains, e.g. up to depth 4.
- Evaluate the inner payload against the exec policy in addition to the outer command.
- For
-EncodedCommand, decode UTF-16LE and evaluate the decoded content, or deny if decoding fails.
- Detect wrapper forms such as
Happy to open separate PRs for each if the approach sounds right.
Activity
security: add ExecEnvSanitizer to block env-var injection in system.run
security: harden system.run approval checks
security: harden system.run approval checks