security: implement hard blocklist for workspace environment variables to prevent RCE - #33
security: implement hard blocklist for workspace environment variables to prevent RCE#33galdawave wants to merge 2 commits into
Conversation
galdawave
left a comment
There was a problem hiding this comment.
Code Review
Scope: Pull Request #33
This PR implements a hard blocklist for workspace-level .env files to prevent Remote Code Execution (RCE) vulnerabilities. It correctly identifies high-risk environment variables like NODE_OPTIONS, SHELL, and LD_PRELOAD, blocking them from being overridden by untrusted or malicious local .env files, even in trusted workspaces. The implementation includes proactive user feedback via security warnings and a regression test suite.
Metadata Review
- PR Title: Follows the established
security:prefix convention used in the repository (e.g., google-gemini#19288, google-gemini#19026). It is clear and descriptive. - PR Description: Excellent detail. It clearly maps the changes to the security requirement (issue 25021), lists the affected variables, and provides a clear verification plan.
Concerns (Action Required)
-
[packages/cli/src/config/settings.ts]: Case-Sensitivity Bypass
The checkRESTRICTED_WORKSPACE_ENV_VARS.has(key)is case-sensitive. On case-insensitive operating systems (like Windows) or for processes that normalize environment variables, a malicious user could bypass this blocklist by using lowercase or mixed-case keys (e.g.,node_options=--inspectorPager=evil-script).- Suggestion: Normalize the
keyto uppercase before checking the set, and ensure the set contains only uppercase strings.
if (RESTRICTED_WORKSPACE_ENV_VARS.has(key.toUpperCase())) { ... }
- Suggestion: Normalize the
-
[packages/cli/src/config/settings.ts]: Fragile Workspace Detection
The logicconst isProjectEnvFile = !envFilePath.includes(GEMINI_DIR);(whereGEMINI_DIRis".gemini") is fragile. A user could inadvertently bypass security protections by naming their project directory or any parent directory.gemini(e.g.,~/projects/my.gemini.tools/.env). This would causeisProjectEnvFileto befalse, skipping the blocklist entirely.- Suggestion: Use a more robust check, such as comparing the resolved
envFilePathagainst the resolvedGEMINI_DIRpath segment, or checking if the file resides within the user's home configuration directory.
- Suggestion: Use a more robust check, such as comparing the resolved
-
[packages/cli/src/config/settings.ts]: Missing Dangerous Variables
The current blocklist is a great start, but several other critical variables commonly used for hijacking or RCE are missing:LD_LIBRARY_PATHandDYLD_LIBRARY_PATH: Can be used to hijack shared library loading.PATH: Shadowing system binaries (likegitorls) is a primary RCE vector. While blockingPATHmay impact some legitimate use cases (e.g., addingnode_modules/.bin), the security risk of allowing a workspace to redefine the CLI's own execution path is significant.- Suggestion: Add
LD_LIBRARY_PATHandDYLD_LIBRARY_PATHto the blocklist. Consider addingPATHor at least auditing how it is used after environment loading.
-
[package-lock.json]: Lockfile Noise/Artifacts
The PR includes changes topackage-lock.jsonthat add"peer": trueto various telemetry and gRPC packages. Sincepackage.jsonwas not modified, these appear to be artifacts of the developer's environment (e.g., using a different npm version or flags).- Suggestion: Revert these unrelated lockfile changes unless they are a required part of a dependency resolution fix.
Nits (Suggestions)
-
[packages/cli/src/config/settings.ts]: Normalization of Blocklist
Since the blocklist is intended to be static and performant, consider defining it as aSet<string>of uppercase strings and using a small helper function to check it, reducing boilerplate inloadEnvironment. -
[packages/cli/src/config/settings.test.ts]: Test Case Coverage
The added test is good, but it should also verify the case-sensitivity concern mentioned above (e.g., ensuringnode_optionsis also blocked).
|
🤖 Automated Fix Applied I've processed the latest review and implemented the requested changes in an isolated worktree.
|
|
Closing PR as requested. Branch will be preserved. |
This PR addresses a critical security vulnerability where malicious
.envfiles in a workspace could override sensitive CLI and IDE environment variables, potentially leading to Remote Code Execution (RCE), addressing issue 25021.Key Changes:
RESTRICTED_WORKSPACE_ENV_VARShard blocklist insettings.tscontaining critical variables such asGEMINI_CLI_IDE_SERVER_STDIO_COMMAND,NODE_OPTIONS,PAGER,SHELL, etc.loadEnvironmentto strictly filter out these restricted variables when loading from workspace-level.envfiles, regardless of workspace trust or user settings.settings.test.tsto verify that malicious overrides are correctly blocked even in trusted workspaces.Verification:
GEMINI_CLI_IDE_SERVER_STDIO_COMMANDin a local.envfile results in a security warning and no environment modification.