Skip to content

fix(core): block $VAR and ${VAR} variable expansion bypass (GHSA-wpqr-6v78-jr5g) - #28902

Open
thalha-a9 wants to merge 4 commits into
google-gemini:mainfrom
thalha-a9:fix/variable-expansion-bypass
Open

fix(core): block $VAR and ${VAR} variable expansion bypass (GHSA-wpqr-6v78-jr5g)#28902
thalha-a9 wants to merge 4 commits into
google-gemini:mainfrom
thalha-a9:fix/variable-expansion-bypass

Conversation

@thalha-a9

Copy link
Copy Markdown

Summary

  • Fixes an incomplete check in detectBashSubstitution() and detectPowerShellSubstitution() that allowed variable expansion patterns to bypass the security gate added for GHSA-wpqr-6v78-jr5g
  • Defense-in-depth hardening of gemini-automated-issue-dedup.yml workflow

Fixes #28418

Changes

File What
packages/core/src/utils/shell-utils.ts Block ${VAR} and $VAR in both bash and PowerShell detection, with allowlist for safe automatic variables
packages/core/src/utils/shell-utils.test.ts 120 test cases — dual-platform coverage, safe variable allowlist, edge cases
.github/workflows/gemini-automated-issue-dedup.yml author_association guard + clear GITHUB_TOKEN in sandboxed env

Test plan

  • 120 tests passing (vitest)
  • Pre-commit hooks pass (prettier, eslint)
  • All CI checks green
  • Gemini Code Assist review: "I have no feedback to provide"
  • Single call site (shell.ts:468) verified — no unintended side effects

…-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
@thalha-a9
thalha-a9 requested review from a team as code owners August 19, 2026 08:34
@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 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

  • Security Hardening: Updated shell command detection logic to block $VAR and ${VAR} variable expansion patterns in both Bash and PowerShell, closing a bypass vulnerability (GHSA-wpqr-6v78-jr5g).
  • Allowlist Implementation: Introduced specific allowlists for safe automatic variables in Bash and PowerShell to maintain functionality while preventing malicious expansion.
  • Comprehensive Testing: Added 120 new test cases covering various platforms, edge cases, and variable expansion scenarios to ensure robust detection.
  • Workflow Security: Hardened the gemini-automated-issue-dedup.yml workflow by adding an author_association guard and ensuring secure handling of GITHUB_TOKEN.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/gemini-automated-issue-dedup.yml
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/l A large sized PR label Aug 19, 2026
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 286
  • Additions: +279
  • Deletions: -7
  • Files changed: 3

@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 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.

Comment thread packages/core/src/utils/shell-utils.ts
@thalha-a9

Copy link
Copy Markdown
Author

/gemini review and see if everything is ready.

@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 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.

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/security Issues related to security labels Aug 19, 2026
@thalha-a9

Copy link
Copy Markdown
Author

@DavidAPierce @amelidev @luisfelipe-alt
This is a third submission of this fix. #28403 and #28691 were both auto-closed by the inactivity bot before any human reviewed them. This is an incomplete fix for an existing public advisory (GHSA-wpqr-6v78-jr5g), environment variable exfiltration via $VAR/${VAR} and special parameters is still possible on upstream. All CI green, GitHub Actions Scan passing, gemini-code-assist clean. Would appreciate a review before the bot closes this one too.

@gemini-cli

gemini-cli Bot commented Aug 27, 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.

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

Labels

area/security Issues related to security 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.

Security: $VAR/${VAR} variable expansion bypass in detectBashSubstitution and detectPowerShellSubstitution (GHSA-wpqr-6v78-jr5g)

1 participant