#8139: fix(config): block dangerous environment variables from config.env
stale
## Summary
Block dangerous environment variables from being set via `config.env.vars` to prevent code injection attacks.
## The Problem
The `applyConfigEnv()` function sets user-controlled config `env.vars` directly into the global `process.env` without filtering dangerous variables like `NODE_OPTIONS`, `LD_PRELOAD`, or `DYLD_INSERT_LIBRARIES`. All subsequent child process spawns (npm install, Chrome browser, shell commands, Docker containers) inherit these environment variables, enabling arbitrary code execution.
An attacker could distribute a malicious `openclaw.json5` config file with:
```json
{
"env": {
"vars": {
"NODE_OPTIONS": "--require=/tmp/malicious.js"
}
}
}
```
Any Node.js child process would then load the malicious code.
## Changes
- `src/config/io.ts`: Added blocklist for dangerous environment variables and pattern matching for `LD_*` and `DYLD_*` prefixes
- `src/config/config.dangerous-env-vars.test.ts`: Added tests verifying blocked variables and allowing safe variables
### Blocked Variables
- **Node.js injection**: `NODE_OPTIONS`, `NODE_PATH`, `NODE_REPL_HISTORY`
- **Linux library injection**: `LD_PRELOAD`, `LD_LIBRARY_PATH`, `LD_AUDIT`, and all `LD_*`
- **macOS library injection**: `DYLD_INSERT_LIBRARIES`, `DYLD_LIBRARY_PATH`, and all `DYLD_*`
- **Python injection**: `PYTHONPATH`, `PYTHONSTARTUP`, `PYTHONHOME`
- **Perl injection**: `PERL5LIB`, `PERLLIB`, `PERL5OPT`
- **Ruby injection**: `RUBYLIB`, `RUBYOPT`
- **Shell injection**: `BASH_ENV`, `ENV`
## Test Plan
- [x] `pnpm build && pnpm check && pnpm test` passes
- [x] New test `describe('config dangerous env var blocking')` validates the fix
- [x] Verified dangerous variables are silently blocked
- [x] Verified safe variables (API keys, custom vars) still work
## Related
- [CWE-94](https://cwe.mitre.org/data/definitions/94.html) - Improper Control of Generation of Code
- Internal audit ref: VULN-159
---
*Built with [bitsec-ai](https://github.com/bitsec-ai). AI-assisted: Yes. Testing: fully tested (test written before fix). Code reviewed and understood.*
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens config loading by preventing `config.env.vars` from setting environment variables commonly used for interpreter/dynamic loader injection (e.g., `NODE_OPTIONS`, `LD_*`, `DYLD_*`, `PYTHONPATH`, `BASH_ENV`) before those vars get merged into `process.env`. It adds a blocklist/prefix-based filter in `src/config/io.ts` and introduces a focused Vitest suite to validate that dangerous variables are not applied while typical “safe” variables still are.
<h3>Confidence Score: 4/5</h3>
- This PR is generally safe to merge and improves security, with one notable edge-case bypass to address.
- The change is localized (only filters env var application) and has targeted tests, but the current dangerous-var check is case-sensitive for exact-match entries, which may allow bypasses if config keys aren’t normalized upstream.
- src/config/io.ts (case-insensitive matching); src/config/config.dangerous-env-vars.test.ts (add mixed/lowercase coverage)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21668: fix(config): block dangerous environment variable keys from config ...
by AI-Reviewer-QS · 2026-02-20
90.7%
#8161: fix(sandbox): block dangerous environment variables from Docker con...
by yubrew · 2026-02-03
87.5%
#8150: fix(skills): block dangerous environment variables from skill config
by yubrew · 2026-02-03
84.6%
#22713: Security: extend env var blocklist — add GLIBC_TUNABLES, JAVA_TOOL_...
by Fratua · 2026-02-21
80.3%
#8078: fix(config): add prototype pollution protection to deepMerge
by yubrew · 2026-02-03
80.2%
#22756: fix(security): add missing entries to environment variable blocklist
by miloudbelarebia · 2026-02-21
80.0%
#21164: feat(config): add lenient mode to resolveConfigEnvVars — preserve g...
by Mellowambience · 2026-02-19
78.4%
#9200: Fix: Strip dangerous env vars from baseEnv in host execution
by vishaltandale00 · 2026-02-05
78.1%
#10258: fix(config): preserve ${ENV_VAR} references when writing config (#9...
by nu-gui · 2026-02-06
75.5%
#8228: fix(link-understanding): block private IPs and internal hostnames i...
by yubrew · 2026-02-03
75.5%