Skip to content

fix(core): whitelist TERM and COLORTERM in environment sanitization#21473

Closed
sripasg wants to merge 1 commit intomainfrom
deadsman07_fix_20444
Closed

fix(core): whitelist TERM and COLORTERM in environment sanitization#21473
sripasg wants to merge 1 commit intomainfrom
deadsman07_fix_20444

Conversation

@sripasg
Copy link
Contributor

@sripasg sripasg commented Mar 6, 2026

[original author - @deadsmash07 - from PR - 20514]

Summary

  • Added TERM and COLORTERM to ALWAYS_ALLOWED_ENVIRONMENT_VARIABLES in the environment sanitization service
  • These variables describe terminal capabilities and are safe to pass through — they're needed by terminal editors (vim, emacs) and interactive commands (top)
  • The sandbox path already preserves these variables (see sandbox.ts), so this aligns the sanitization behavior

Details

Terminal-based editors fail to initialize ("Terminal type not defined") and interactive commands default to no-color mode because TERM and COLORTERM are stripped during environment sanitization. This change simply whitelists them so they pass through to spawned processes unchanged — no fallback values are introduced.

Related Issues

Fixes #20444

How to Validate

  1. Set EDITOR=vim or EDITOR=emacs
  2. Run Gemini CLI with environment variable redaction enabled
  3. Trigger an editor operation (e.g., edit a plan)
  4. Verify the editor starts correctly without "Terminal type not defined" errors
  5. Run top via shell command and verify color support works

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed) — N/A
  • Added/updated tests (if needed) — Two new tests covering normal and strict sanitization modes
  • Noted breaking changes (if any) — None
  • Validated on required platforms/methods:
    • Linux npm run

Terminal editors (vim, emacs) and interactive commands (top) fail when
these variables are redacted. They are safe to pass through as they
only describe terminal capabilities.

Fixes #20444
@sripasg sripasg requested a review from a team as a code owner March 6, 2026 22:20
@gemini-code-assist
Copy link
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 enhances the system's compatibility with terminal-based tools by ensuring essential environment variables are preserved during process execution. By allowing TERM and COLORTERM to pass through, it prevents functionality regressions for interactive applications and editors, leading to a more robust and predictable user experience when interacting with the CLI.

Highlights

  • Environment Variable Whitelisting: The TERM and COLORTERM environment variables have been added to the ALWAYS_ALLOWED_ENVIRONMENT_VARIABLES list in the environment sanitization service.
  • Terminal Compatibility Fix: This change resolves issues where terminal-based editors (like vim/emacs) and interactive commands (like top) failed to initialize or lost color support due to these variables being stripped.
  • Behavior Alignment: The update aligns the environment sanitization behavior with the existing sandbox.ts logic, which already preserves these variables, ensuring consistent handling.
Changelog
  • packages/core/src/services/environmentSanitization.test.ts
    • Added tests to confirm TERM and COLORTERM are allowed.
    • Added a test to ensure TERM and COLORTERM are preserved even in strict sanitization mode.
  • packages/core/src/services/environmentSanitization.ts
    • Included TERM and COLORTERM in the ALWAYS_ALLOWED_ENVIRONMENT_VARIABLES set.
Activity
  • No human activity has occurred on this pull request yet.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@sripasg sripasg self-assigned this Mar 6, 2026
Copy link
Contributor

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

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 correctly whitelists the TERM and COLORTERM environment variables, which is crucial for compatibility with terminal-based tools. The changes are straightforward and include corresponding tests. The suggested improvement to one of the new tests to make it more robust has been retained as it aligns with general good testing practices and is not contradicted by any specific rules.

@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Size Change: +146 B (0%)

Total Size: 26 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.5 MB +146 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 6, 2026
@sripasg
Copy link
Contributor Author

sripasg commented Mar 6, 2026

The original PR is by @deadsmash07 - here #20514

Thank you @deadsmash07 - but collaboration from maintainers a bit unwieldy with a PR request from a different cloned repo.

@sripasg
Copy link
Contributor Author

sripasg commented Mar 7, 2026

This is not required. I opened it assuming it would be weird to push via cloned repo. It isn't 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: terminal-based editors and interactive commands fail due to missing TERM/COLORTERM env vars

2 participants