#21668: fix(config): block dangerous environment variable keys from config injection
size: S
## Summary
- Add a denylist of dangerous environment variable keys (`NODE_OPTIONS`, `LD_PRELOAD`, `PATH`, `HOME`, etc.) that are blocked from being set via config env injection
- `collectConfigEnvVars` now skips blocked keys in both `env.vars` and top-level `env` blocks, logging a warning for each blocked key
- Add test verifying blocked keys are not written to `process.env`
## Test plan
- [x] Existing tests pass (5/5)
- [x] New test confirms `NODE_OPTIONS`, `LD_PRELOAD`, `PATH`, `HOME` are blocked from config injection
- [ ] Manual: verify warning log is emitted when a blocked key is encountered in config
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added a denylist of dangerous environment variables (`NODE_OPTIONS`, `LD_PRELOAD`, `PATH`, `HOME`, etc.) to prevent security vulnerabilities from config injection. The `collectConfigEnvVars` function now blocks these keys in both `env.vars` and top-level `env` blocks with warning logs.
- Blocks 10 dangerous environment variable keys that could enable code injection or system compromise
- Case-insensitive matching using `toUpperCase()` ensures variants are caught
- Consistent with existing security patterns in `src/node-host/invoke.ts` and `src/agents/sandbox/sanitize-env-vars.ts`
- Test verifies blocked keys are not written to `process.env`
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low risk - it adds security hardening without breaking changes
- Score reflects solid security implementation with proper testing. The denylist approach is effective and consistent with existing patterns in the codebase. Minor test coverage gap (top-level env block not tested) prevents a score of 5, but the implementation correctly handles both cases.
- No files require special attention - the implementation is straightforward and well-tested
<sub>Last reviewed commit: 9ecf366</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#8139: fix(config): block dangerous environment variables from config.env
by yubrew · 2026-02-03
90.7%
#8161: fix(sandbox): block dangerous environment variables from Docker con...
by yubrew · 2026-02-03
84.1%
#8150: fix(skills): block dangerous environment variables from skill config
by yubrew · 2026-02-03
80.9%
#8078: fix(config): add prototype pollution protection to deepMerge
by yubrew · 2026-02-03
77.9%
#22756: fix(security): add missing entries to environment variable blocklist
by miloudbelarebia · 2026-02-21
77.3%
#6486: feat(security): add exec command denylist for defense-in-depth
by nia-agent-cyber · 2026-02-01
76.9%
#22713: Security: extend env var blocklist — add GLIBC_TUNABLES, JAVA_TOOL_...
by Fratua · 2026-02-21
75.9%
#21660: fix(plugins): require explicit allowlist for non-bundled plugins
by AI-Reviewer-QS · 2026-02-20
75.8%
#21733: security(exec): platform-aware allowlist matching and restricted sa...
by Esubaalew · 2026-02-20
75.7%
#21164: feat(config): add lenient mode to resolveConfigEnvVars — preserve g...
by Mellowambience · 2026-02-19
75.2%