Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[KDM-TEST-FIX-298] fix(ai): pass Gemini API key via header and use v1beta endpoint (#265) - #298

Merged
utkarsh232005 merged 1 commit into
KDM-cli:mainfrom
DYNOSuprovo:fix/gemini-api-key-header-and-v1beta
Sep 11, 2026
Merged

utkarsh232005 merged 1 commit into
KDM-cli:mainfrom
DYNOSuprovo:fix/gemini-api-key-header-and-v1beta

Conversation

@DYNOSuprovo

Copy link
Copy Markdown
Contributor

Description

Fixes #265.

This PR addresses the security and compatibility issues in GoogleGeminiAIClient:

  1. API Key in Header (CWE-598 Prevention):
    • Replaced URL query parameter ?key=${this.apiKey} with HTTP header 'x-goog-api-key': this.apiKey.
    • Prevents leaking user API tokens into corporate proxy logs, network firewalls, and server access logs.
  2. Endpoint Modernization (v1 -> v1beta):
    • Updated the Google Gemini endpoint from /v1/models/... to /v1beta/models/....
    • Modern Gemini models (such as gemini-1.5-flash, gemini-1.5-pro, and gemini-2.0-flash) are deployed under /v1beta/ and previously resulted in 404 Model Not Found errors on /v1/.
  3. Required API Key Validation:
    • Validates config.password in configure(), throwing 'API key (password) is required for google-gemini provider' when missing or empty (matching OpenAI and Anthropic provider behavior).
  4. Custom Headers & Base URL Support:
    • Forwards config.customHeaders in the fetch request options.
    • Supports configurable config.baseUrl (defaulting to https://generativelanguage.googleapis.com).
  5. Testing & Verification:
    • Updated src/__tests__/auth.test.ts to assert header authorization (x-goog-api-key), /v1beta/ endpoint URL, and API key validation.
    • Added comprehensive test suite src/__tests__/google-gemini.test.ts with 100% coverage (9/9 passing tests) verifying validation, headers, endpoint URL, query parameter absence, custom headers forwarding, and error handling.

Testing

  • npm run build passed cleanly.
  • npx vitest run src/__tests__/auth.test.ts src/__tests__/google-gemini.test.ts passed (56/56 tests passing).
  • V8 coverage report confirms 100% branch, statement, function, and line coverage on src/ai/google-gemini.ts.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: QUIET

Plan: Advanced

Run ID: 5e4b4d48-b4ad-4c27-b9e6-ba7800240c42

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

Parsing errors (2)
Validation error: Invalid input: expected string, received undefined at "reviews.path_instructions[3].path"; Invalid input: expected string, received undefined at "reviews.path_instructions[3].instructions"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot changed the title fix(ai): pass Gemini API key via header and use v1beta endpoint (#265) [KDM-TEST-FIX-298] fix(ai): pass Gemini API key via header and use v1beta endpoint (#265) Sep 11, 2026

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates Passed
3 Quality Gates Passed

See analysis details in CodeScene

Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@utkarsh232005

Copy link
Copy Markdown
Member

@DYNOSuprovo The PR is clean and properly addresses the issue. Merging it as is—no further changes required. Thanks for the contribution, and looking forward to seeing more contributions from you!

@utkarsh232005
utkarsh232005 merged commit 86d2388 into KDM-cli:main Sep 11, 2026
9 of 11 checks passed
@utkarsh232005

Copy link
Copy Markdown
Member

@all-contributors please add @DYNOSuprovo for code

@allcontributors

Copy link
Copy Markdown
Contributor

@utkarsh232005

I've put up a pull request to add @DYNOSuprovo! 🎉

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GoogleGeminiAIClient leaks API key in query params & uses outdated v1 endpoint failing modern models

2 participants