fix(core): block $VAR and ${VAR} variable expansion bypass (GHSA-wpqr-6v78-jr5g) - #28902
fix(core): block $VAR and ${VAR} variable expansion bypass (GHSA-wpqr-6v78-jr5g)#28902thalha-a9 wants to merge 4 commits into
Conversation
…-6v78-jr5g) The existing detectBashSubstitution() and detectPowerShellSubstitution() only blocked $() command substitution and backticks, but allowed $VAR and ${VAR} variable expansion to pass through undetected. This is a bypass of the fix for GHSA-wpqr-6v78-jr5g. An attacker-controlled prompt could instruct the model to run commands like: echo $GITHUB_TOKEN, echo ${GEMINI_API_KEY}, or write env vars to GITHUB_ENV — exfiltrating secrets from CI environments without triggering any security gate. Changes: - shell-utils.ts: Extend both bash and PowerShell detection to block ${...} (brace expansion) and $IDENTIFIER (bare variable names). Safe automatic variables ($_, $true, $false, $null, $args) are allowlisted. Uses sticky regex for O(N) performance. - shell-utils.test.ts: 120 test cases — dual-platform coverage, safe variable allowlist, edge cases, mixed-case PowerShell variants. - gemini-automated-issue-dedup.yml: Defense-in-depth hardening — author_association guard + clear GITHUB_TOKEN in sandboxed env. Fixes google-gemini#28418
Summary of ChangesHello, 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 a security vulnerability related to incomplete shell command substitution checks. By expanding the detection logic to explicitly block variable expansion patterns that were previously overlooked, the changes prevent potential command injection vectors. The implementation includes carefully curated allowlists for legitimate system variables and is supported by an extensive suite of cross-platform tests to ensure security without breaking expected behavior. Highlights
Ignored Files
Using Gemini Code AssistThe 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
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 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
|
|
📊 PR Size: size/L
|
There was a problem hiding this comment.
Code Review
This pull request enhances shell utility security by updating detectCommandSubstitution to block variable expansions (such as ${VAR} and $VAR) in both Bash and PowerShell, while permitting safe automatic variables like $_ in Bash and $true, $false, $null, $args in PowerShell. Comprehensive unit tests are also added to verify these changes. The review feedback highlights a critical security gap where special and positional parameters (e.g., $*, $@, $1) are not blocked, potentially allowing information disclosure or argument injection, and provides a code suggestion to address this issue.
…etc.) per Gemini Code Assist review
|
/gemini review and see if everything is ready. |
There was a problem hiding this comment.
Code Review
This pull request enhances the detectCommandSubstitution utility in packages/core/src/utils/shell-utils.ts to block variable expansions, braced variable expansions, and special/positional parameters for both Bash and PowerShell environments, while safely allowing a whitelist of automatic variables (such as $_, $true, $false, $null, and $args). Comprehensive unit tests have been added in packages/core/src/utils/shell-utils.test.ts to verify these security boundaries across different platforms. There are no review comments provided, and I have no additional feedback to offer on these changes.
|
@DavidAPierce @amelidev @luisfelipe-alt |
|
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. |
Summary
detectBashSubstitution()anddetectPowerShellSubstitution()that allowed variable expansion patterns to bypass the security gate added for GHSA-wpqr-6v78-jr5ggemini-automated-issue-dedup.ymlworkflowFixes #28418
Changes
packages/core/src/utils/shell-utils.ts${VAR}and$VARin both bash and PowerShell detection, with allowlist for safe automatic variablespackages/core/src/utils/shell-utils.test.ts.github/workflows/gemini-automated-issue-dedup.ymlauthor_associationguard + clearGITHUB_TOKENin sandboxed envTest plan