Skip to content

fix(extensions): prompt for consent on environment changes and sanitize runtime-altering environment variables - #28863

Open
amelidev wants to merge 4 commits into
google-gemini:mainfrom
amelidev:b_469352991
Open

fix(extensions): prompt for consent on environment changes and sanitize runtime-altering environment variables#28863
amelidev wants to merge 4 commits into
google-gemini:mainfrom
amelidev:b_469352991

Conversation

@amelidev

Copy link
Copy Markdown
Contributor

Summary

This PR addresses an issue where extension updates could bypass user consent checks and inject unauthorized environment variables into spawned MCP server processes.

By incorporating MCP server environment configurations into the generated consent strings and sanitizing custom environment variables, we ensure that:

  1. Any modification of extension environment configurations triggers a mandatory user consent confirmation prompt.
  2. Dangerous runtime-altering environment variables are filtered out before subprocesses are spawned, blocking potential execution preloads (such as through NODE_OPTIONS).

Details

  1. Consent Change Detection: In packages/cli/src/config/extensions/consent.ts, custom environment variables defined in the extension manifest are now included in the string output generated by extensionConsentString. Because the update system compares the previous version's consent string to the new version's consent string to decide whether to prompt the user, modifying env keys now correctly forces a consent verification dialog.
  2. Subprocess Sanitization: In packages/core/src/tools/mcp-client.ts, we introduced a set of blocked execution-altering environment variables (including NODE_OPTIONS, PYTHONPATH, RUBYOPT, and PERL5OPT). During MCP server environment merging, any key matching the blocked set is ignored and logged as a warning.
  3. Automated Verification:
    • Added a new unit test in packages/cli/src/config/extensions/consent.test.ts to verify that modifying an MCP server's environment configuration correctly triggers a consent prompt.
    • Added a new unit test in packages/core/src/tools/mcp-client.test.ts to verify that dangerous environment variables are stripped from the environment dictionary before spawning the child transport.

Related Issues

Resolves the reported extension consent bypass and unauthorized environment preload injection issues.

How to Validate

  1. Run the consent test suite:
    npm test -w @google/gemini-cli -- src/config/extensions/consent.test.ts --run
  2. Run the MCP client test suite:
    npm test -w @google/gemini-cli-core -- src/tools/mcp-client.test.ts --run
  3. Run project-wide linting, formatting, and typing validation:
    npm run lint && npm run typecheck

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

…ze runtime-altering environment variables

This change prevents silent injection of execution environments during extension updates by:
1. Printing custom environment variables in the extension installation/update consent string, which triggers a consent confirmation prompt if any environment variables are modified or added.
2. Sanitizing custom environment variables passed to stdio/local MCP servers, explicitly blocking execution-altering keys (e.g. NODE_OPTIONS, PYTHONPATH) to ensure child processes are launched safely.
@amelidev
amelidev requested review from a team as code owners August 17, 2026 22:55
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request strengthens the security posture of extension management by ensuring that modifications to environment variables are subject to user consent and by preventing the injection of potentially malicious execution-altering environment variables into spawned MCP server processes.

Highlights

  • Enhanced Consent Verification: Updated the extension consent mechanism to include environment variable configurations in the consent string, ensuring that any changes to environment settings trigger a mandatory user confirmation prompt.
  • Subprocess Environment Sanitization: Implemented a blocklist for dangerous, runtime-altering environment variables (such as NODE_OPTIONS, PYTHONPATH, etc.) to prevent unauthorized injection when spawning MCP server processes.
  • Automated Testing: Added unit tests in both the CLI and core packages to verify that environment modifications trigger consent prompts and that dangerous environment variables are correctly stripped.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/m A medium sized PR label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 202
  • Additions: +201
  • Deletions: -1
  • Files changed: 6

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances security by blocking dangerous environment variables (such as NODE_OPTIONS and PYTHONPATH) from being passed to MCP servers, and updates the consent flow to display configured environment variables. The review feedback recommends expanding the blocked environment variables list to include critical dynamic linker variables (e.g., LD_PRELOAD, LD_LIBRARY_PATH) and shell preloads (e.g., BASH_ENV) to prevent potential arbitrary code execution (RCE) bypasses.

Comment thread packages/core/src/tools/mcp-client.ts Outdated
@amelidev

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces environment variable filtering for MCP server configurations to block dangerous variables (such as NODE_OPTIONS and PYTHONPATH) and updates the consent flow and tests accordingly. The feedback highlights that the blocklist is incomplete and misses critical system-level variables like LD_PRELOAD and DYLD_LIBRARY_PATH which could lead to remote code execution. It is recommended to expand this blocklist, centralize the sanitization logic, and update the corresponding unit tests to verify these additional blocked variables.

Comment thread packages/core/src/tools/mcp-client.ts Outdated
Comment thread packages/core/src/tools/mcp-client.test.ts
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Aug 17, 2026
This change addresses PR review feedback by:
1. Centralizing the environment variable blocklist and helper inside environmentSanitization.ts.
2. Expanding the blocked list to cover critical OS-level dynamic preloads and execution-altering variables (e.g., LD_PRELOAD, DYLD_LIBRARY_PATH, BASH_ENV, ENV, PERL5DB).
3. Ensuring stdio-based MCP servers expand configurations using sanitizedEnv instead of raw process.env to prevent credential/secret leaks.
4. Adding robust unit tests to verify the expanded blocklist and secure variable expansion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant