Skip to content

fix(core): keep GIT_CONFIG_* environment triplets internally consistent - #28938

Closed
Shivansh1980 wants to merge 5 commits into
google-gemini:mainfrom
Shivansh1980:fix/git-config-env-consistency
Closed

Shivansh1980 wants to merge 5 commits into
google-gemini:mainfrom
Shivansh1980:fix/git-config-env-consistency

Conversation

@Shivansh1980

@Shivansh1980 Shivansh1980 commented Aug 20, 2026 •

Copy link
Copy Markdown

Summary

Prevents sanitized GIT_CONFIG_* environments from becoming unparsable by Git when redaction removes one half of a numbered key/value pair. It also ensures ShellExecutionService does not restore sensitive Git configuration values after sanitization.

Git treats incomplete numbered configuration as fatal:

error: missing config value GIT_CONFIG_VALUE_0
fatal: unable to parse command-line config

Details

Root cause

sanitizeEnvironment() performs value-first secret detection. If a credential-bearing GIT_CONFIG_VALUE_n is removed while GIT_CONFIG_KEY_n and GIT_CONFIG_COUNT remain, Git sees an incomplete slot and refuses to run.

A second path in ShellExecutionService parsed inherited GIT_CONFIG_COUNT values without strict validation. A non-numeric value produced GIT_CONFIG_KEY_NaN, GIT_CONFIG_VALUE_NaN, and GIT_CONFIG_COUNT=NaN, which Git rejects as a bogus count.

Finally, ShellExecutionService restored raw GIT_CONFIG_* variables from sourceEnv after sanitization. Built-in sandbox managers sanitize again, but relying on that left the ShellExecutionService -> SandboxManager boundary unsafe for pass-through or custom managers.

Fix

  • Rebuild numbered Git configuration slots from complete key/value pairs that survive redaction.
  • Preserve original slot order so Git's last-value-wins behavior is unchanged.
  • Renumber surviving slots contiguously and restate GIT_CONFIG_COUNT.
  • Treat non-numeric inherited counts as unusable before appending security overrides.
  • Do not restore raw Git configuration values after sanitization.
  • Leave non-numbered controls such as GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, and GIT_CONFIG_NOSYSTEM unchanged.

Security impact

This strengthens the sanitization boundary. Credential-bearing values remain removed before any sandbox manager receives the environment, while safe surviving pairs remain usable and contiguous.

Related Issues

How to Validate

npx vitest run \
  packages/core/src/services/environmentSanitization.test.ts \
  packages/core/src/services/shellExecutionService.test.ts
Test Files  2 passed (2)
Tests       112 passed (112)

Additional checks:

npx prettier --check \
  packages/core/src/services/shellExecutionService.ts \
  packages/core/src/services/shellExecutionService.test.ts

npx eslint \
  packages/core/src/services/shellExecutionService.ts \
  packages/core/src/services/shellExecutionService.test.ts \
  --max-warnings 0

npx tsc --noEmit -p packages/core/tsconfig.json

Regression coverage includes:

  • Redacted value or key removes the entire numbered pair.
  • Surviving pairs are renumbered contiguously without changing precedence.
  • Non-numeric and over-declared counts are repaired.
  • Slots beyond the declared count are discarded.
  • Strict GitHub sanitization preserves triplet consistency.
  • Intact and redaction-disabled environments retain their existing behavior.
  • A pass-through sandbox manager never receives a redacted credential.
  • Every declared numbered slot has both a key and a value.

Pre-Merge Checklist

  • Updated relevant documentation and README (not needed; internal environment-hardening fix)
  • Added/updated tests
  • Noted breaking changes (none)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Validated locally on Windows with the exact Vitest, Prettier, ESLint, and TypeScript commands above.

Redaction is value-first, so a GIT_CONFIG_VALUE_n holding a credential is dropped while its GIT_CONFIG_KEY_n and the declared GIT_CONFIG_COUNT survive. Git treats that gap as fatal -- 'error: missing config value GIT_CONFIG_VALUE_0' followed by 'fatal: unable to parse command-line config' -- and refuses to run at all, so every git invocation in the sanitized environment fails.

Separately, parseInt() on an inherited GIT_CONFIG_COUNT yields NaN for a non-numeric value, emitting GIT_CONFIG_COUNT=NaN, which git rejects with 'bogus count in GIT_CONFIG_COUNT'.

Rebuild the numbered slots from the pairs that survived redaction, renumbering them contiguously and restating the count, and ignore an unusable inherited count when appending the sandbox overrides. Value-first redaction is preserved: a secret-bearing value is still never emitted, the whole directive is dropped instead.
@Shivansh1980
Shivansh1980 requested a review from a team as a code owner August 20, 2026 21:31
@github-actions github-actions Bot added the size/l A large sized PR label Aug 20, 2026
@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 addresses issues where environment variable redaction caused Git configuration to become invalid. By ensuring that GIT_CONFIG_* triplets remain contiguous and that the GIT_CONFIG_COUNT is always a valid integer, the changes prevent Git from failing during execution in sanitized environments.

Highlights

  • GIT_CONFIG_ triplet consistency*: Implemented logic to renumber and rebuild GIT_CONFIG_* environment variables when redaction creates gaps, ensuring Git does not fail due to missing config values.
  • GIT_CONFIG_COUNT validation: Added robust validation for GIT_CONFIG_COUNT to prevent passing non-numeric values to Git, which previously caused 'bogus count' errors.
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 commented Aug 20, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 348
  • Additions: +340
  • Deletions: -8
  • Files changed: 4

@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 labels Aug 20, 2026

@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 logic to normalize GIT_CONFIG_* environment variable triplets during environment sanitization, ensuring that if a sensitive value is redacted, the corresponding key is also removed and the remaining variables are renumbered contiguously to prevent Git from failing. However, a critical security vulnerability was identified in shellExecutionService.ts where a loop explicitly copies unsanitized GIT_CONFIG_* variables from the source environment, completely bypassing the newly introduced value-first redaction. It is recommended to remove this restoration loop to ensure proper enforcement of the sanitization.

Note: Security Review is unavailable for this PR.

Comment thread packages/core/src/services/shellExecutionService.ts
Remove raw GIT_CONFIG_* restoration after sanitization and cover the pass-through sandbox boundary.
@gemini-cli

gemini-cli Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@gemini-cli

gemini-cli Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

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 priority/p1 Important and should be addressed in the near term. size/l A large sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant