fix(dotenv): block Windows shell trust-root vars from workspace .env [AI-assisted]#74460
fix(dotenv): block Windows shell trust-root vars from workspace .env [AI-assisted]#74460drobison00 merged 3 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR adds four Windows shell path-resolution variables ( Confidence Score: 4/5Safe to merge — the blocking logic is correct and the security fix is sound; only minor test completeness suggestions remain. The production change in dotenv.ts is straightforward and correct. The only findings are P2: the test doesn't write uppercase variants of three of the four variable families to the .env file (so those assertions pass trivially), and COMSPEC is a related Windows shell-redirect variable not yet covered. Neither represents a defect in the actual fix. No files require special attention; both findings are minor test/coverage suggestions. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/dotenv.test.ts
Line: 302-309
Comment:
**Uppercase variants not written to .env in test**
The .env content only includes mixed-case entries for `ProgramW6432`, `SystemRoot`, and `windir` — their all-uppercase counterparts (`PROGRAMW6432`, `SYSTEMROOT`, `WINDIR`) are never written to the file. After `clearEnv` deletes all 8 keys, the assertions for those three uppercase variants pass trivially (they were deleted and never loaded), so the test doesn't actually exercise blocking of those specific inputs. Adding the uppercase variants to the .env content would make the coverage complete.
```suggestion
"ProgramFiles=.\\evil-pfiles",
"PROGRAMFILES=.\\evil-pfiles-upper",
"ProgramW6432=.\\evil-pw6432",
"PROGRAMW6432=.\\evil-pw6432-upper",
"SystemRoot=.\\fake-root",
"SYSTEMROOT=.\\fake-root-upper",
"windir=.\\fake-windir",
"WINDIR=.\\fake-windir-upper",
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/infra/dotenv.ts
Line: 73-79
Comment:
**`COMSPEC` not blocked**
`COMSPEC` is the Windows variable that tells the OS where to find `cmd.exe`. If a workspace `.env` sets `COMSPEC=.\evil.exe`, any code path that spawns a shell via `cmd /c …` (directly or through Node's `spawn`/`exec` with `shell: true`) would resolve to the attacker-supplied binary. Since the PR's stated goal is to block Windows shell trust-root variables, `COMSPEC` fits the same threat model as `WINDIR`/`SYSTEMROOT` and is worth adding to the blocklist for completeness.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: address review feedback" | Re-trigger Greptile |
|
Codex review: needs maintainer review before merge. What this changes: The branch adds Maintainer follow-up before merge: This is security-sensitive Windows command-resolution hardening with no discrete automated repair finding; the remaining action is maintainer/security review, validation, and reconciliation with related Windows hardening PRs. Security review: Security review cleared: The diff narrows untrusted workspace dotenv influence over Windows command resolution and adds tests/changelog only; it introduces no new dependency, workflow, script, permission, publishing, generated-code, or secret-handling risk. Review detailsBest possible solution: Land or fold this narrow Do we have a high-confidence way to reproduce the issue? Yes. A source-level reproduction exists on current main: load a workspace Is this the best way to solve the issue? Yes for the narrow remaining gap. Adding Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 217273037b26. |
|
Addressed in Quoted comment from @clawsweeper:
|
…[AI-assisted] (openclaw#74460) * fix: address issue * fix: address PR review feedback * changelog: PR openclaw#74460 --------- Co-authored-by: Devin Robison <[email protected]>
Summary
.envfiles could set Windows path-resolution variables (ProgramFiles,ProgramW6432,SystemRoot,windir) that control where OpenClaw locatespwsh.exe/powershell.exe, enabling a malicious repository to redirect shell execution to an attacker-controlled binary.PROGRAMFILES,PROGRAMW6432,SYSTEMROOT, andWINDIRtoBLOCKED_WORKSPACE_DOTENV_KEYSinsrc/infra/dotenv.ts. Added a targeted test case insrc/infra/dotenv.test.tsthat writes mixed-case and uppercase variants of all four keys into a workspace.envand asserts none are loaded.~/.openclaw/.env(trusted operator surface), thehost-env-security-policy.jsonexec-env sanitization layer, and all non-Windows code paths are unaffected.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
BLOCKED_WORKSPACE_DOTENV_KEYSdid not enumerate Windows shell trust-root variables, so the existingshouldBlockWorkspaceDotEnvKeyguard passed them through..envloading..envsecurity layer was first built.Regression Test Plan (if applicable)
src/infra/dotenv.test.ts— "blocks Windows shell trust-root vars from workspace .env".envmust remain unset inprocess.envafterloadWorkspaceDotEnvFile.loadWorkspaceDotEnvFiledirectly is both fast and sufficient.User-visible / Behavior Changes
Windows users whose workspace
.envpreviously setProgramFiles,ProgramW6432,SystemRoot, orwindirwill no longer have those values applied. This was always unintended and unsafe; no legitimate workspace.envshould set these variables.Diagram (if applicable)
Security Impact (required)
.envpwsh.exe/powershell.exeresolution. No legitimate use case for setting these from an untrusted workspace.env.Repro + Verification
Environment
Steps
.envcontainingProgramFiles=.\evil-pfiles.loadWorkspaceDotEnvFileon that file.process.env.ProgramFilesandprocess.env.PROGRAMFILESremain undefined.Expected
Actual
process.env.Evidence
"blocks Windows shell trust-root vars from workspace .env"insrc/infra/dotenv.test.tsprovides direct before/after proof.Human Verification (required)
shouldBlockWorkspaceDotEnvKey(line 113) correctly handlesProgramFiles→PROGRAMFILES; alphabetical ordering of new entries verified (PROGRAMFILES,PROGRAMW6432beforeSYNOLOGY_*;SYSTEMROOTafterSYNOLOGY_NAS_HOST;WINDIRafterUV_PYTHON).ProgramFiles,ProgramW6432,SystemRoot,windir) all normalize to the blocked uppercase keys.Review Conversations
Compatibility / Migration
.envkeys that were previously (incorrectly) accepted are now blocked.Risks and Mitigations
.envto set these variables loses that capability..envto override them. The global~/.openclaw/.env(trusted operator surface) is unaffected and can still set these if needed.