Skip to content

feat(vertex): add vertexLocation config setting for Vertex AI region override#25362

Open
Famous077 wants to merge 26 commits intogoogle-gemini:mainfrom
Famous077:feat/vertex-ai-location-override
Open

feat(vertex): add vertexLocation config setting for Vertex AI region override#25362
Famous077 wants to merge 26 commits intogoogle-gemini:mainfrom
Famous077:feat/vertex-ai-location-override

Conversation

@Famous077
Copy link
Copy Markdown
Contributor

Summary

When using Gemini CLI with Vertex AI, requests are routed to us-central1 by
default. The problem is that preview/experimental models like
gemini-3.1-pro-preview are only released to the global region first, so
anyone trying to use them gets an immediate 404 error with no clear explanation
of why.

This PR adds a vertexLocation setting to settings.json so users can
override the region without having to set environment variables every session.

Details

The root cause was twofold:

  1. googleCloudLocation was being read from the GOOGLE_CLOUD_LOCATION env
    var but never actually stored into ContentGeneratorConfig — so even if
    users set the env var correctly, it wasn't always being honored in the Vertex
    AI auth path.

  2. There was no persistent way to set the location. Users had to remember to
    export GOOGLE_CLOUD_LOCATION in every terminal session.

The fix wires vertexLocation from settings.json through the full config
pipeline — ConfigParametersConfig class getter →
createContentGeneratorConfigGoogleGenAI client. Settings take priority
over the env var, but the env var still works as a fallback so nothing is
broken for existing users.

Also fixed 15 pre-existing TypeScript errors in shell.test.ts where
invocation.execute() was being called with a raw AbortSignal instead of
the expected ExecuteOptions object — this was breaking the build on a clean
checkout.

Related Issues

Fixes #20761

How to Validate

Option 1 — via settings.json (new behavior):

// Add to ~/.gemini/settings.json
{
  "vertexLocation": "global"
}

Then run with a preview model:

export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT=your-project-id
gemini -m gemini-3.1-pro-preview

Expected: Request succeeds instead of returning a 404.

Option 2 — env var (existing behavior, should still work):

export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT=your-project-id
gemini -m gemini-3.1-pro-preview

Option 3 — verify priority (settings wins over env var):
Set GOOGLE_CLOUD_LOCATION=us-central1 in env and "vertexLocation": "global"
in settings. The request should go to global.

Run the tests:

npx vitest run packages/core/src/core/contentGenerator.test.ts

All 27 tests should pass including the new one:
should prefer vertexLocation from config over GOOGLE_CLOUD_LOCATION env var

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any) — no breaking changes, fully backwards compatible
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
    • Windows
      • npm run
    • Linux
      • npm run
      • npx

Famous077 and others added 25 commits March 1, 2026 16:28
@Famous077 Famous077 requested review from a team as code owners April 14, 2026 07:05
@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 introduces a persistent configuration option for Vertex AI region overrides, improving usability for users accessing experimental models. Additionally, it significantly enhances the security of the shell tool by implementing robust detection for command injection vulnerabilities, alongside necessary maintenance fixes for test suites.

Highlights

  • Vertex AI Configuration: Added a vertexLocation setting to settings.json to allow users to override the default Vertex AI region, resolving 404 errors when accessing preview models.
  • Security Enhancement: Implemented command injection detection for shell commands to block dangerous command substitution syntax like $(), backticks, and process substitution.
  • Bug Fixes: Resolved 15 TypeScript errors in shell.test.ts related to incorrect invocation.execute() arguments and updated UI snapshot tests.
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.

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
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

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

Copy link
Copy Markdown
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 introduces command injection detection for the shell tool, blocking command substitution syntax such as $(), backticks, and process substitution in both Bash and PowerShell. It also adds a vertexLocation configuration parameter to the core package to allow overriding the default Google Cloud location for Vertex AI. A critical security flaw was identified in the PowerShell substitution detection logic where incorrect backtick escaping inside double-quoted strings could lead to command injection bypasses.

Comment on lines +1082 to +1115
function detectPowerShellSubstitution(command: string): boolean {
let inSingleQuote = false;
let inDoubleQuote = false;
let i = 0;
while (i < command.length) {
const char = command[i];
if (char === "'" && !inDoubleQuote) {
inSingleQuote = !inSingleQuote;
i++;
continue;
}
if (char === '"' && !inSingleQuote) {
inDoubleQuote = !inDoubleQuote;
i++;
continue;
}
if (inSingleQuote) {
i++;
continue;
}
if (char === '`' && !inSingleQuote && i + 1 < command.length) {
i += 2;
continue;
}
if (char === '$' && command[i + 1] === '(') {
return true;
}
if (char === '@' && command[i + 1] === '(') {
return true;
}
i++;
}
return false;
}
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.

security-critical critical

The command substitution detection for PowerShell is flawed and can be bypassed, leading to a potential command injection vulnerability. The current implementation incorrectly assumes that a backtick always escapes the following character, both inside and outside of double quotes. In PowerShell, when inside a double-quoted string, a backtick is treated as a literal character unless it is followed by $, ", or another backtick (or forms a special character escape sequence like backtick-n).

This means a command like echo "x$(whoami)" would be incorrectly considered safe by the current parser, as it would treat the backtick as escaping the $. However, PowerShell would treat the backtick as a literal and execute the whoami command.

To fix this, the escape logic should be more precise, similar to the detectBashSubstitution implementation, only treating the backtick as an escape character for specific characters when inside a double-quoted string.

function detectPowerShellSubstitution(command: string): boolean {
  let inSingleQuote = false;
  let inDoubleQuote = false;
  let i = 0;
  while (i < command.length) {
    const char = command[i];
    if (char === "'" && !inDoubleQuote) {
      inSingleQuote = !inSingleQuote;
      i++;
      continue;
    }
    if (char === "\"" && !inSingleQuote) {
      inDoubleQuote = !inDoubleQuote;
      i++;
      continue;
    }
    if (inSingleQuote) {
      i++;
      continue;
    }

    if (char === "\x60" && i + 1 < command.length) {
      if (inDoubleQuote) {
        const next = command[i + 1];
        if (["$", "\x60", "\""].includes(next)) {
          i += 2;
          continue;
        }
      } else {
        i += 2;
        continue;
      }
    }

    if (char === "$" && command[i + 1] === "(") {
      return true;
    }
    if (char === "@" && command[i + 1] === "(") {
      return true;
    }
    i++;
  }
  return false;
}

@gemini-cli gemini-cli bot added 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 Apr 14, 2026
@Famous077
Copy link
Copy Markdown
Contributor Author

/gemini-review

@gemini-cli gemini-cli bot added the area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt label Apr 17, 2026
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 area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add Vertex AI region override to support preview models

2 participants