Skip to content

fix: correct API key validation logic in handleApiKeySubmit#25453

Open
martin-hsu-test wants to merge 2 commits intogoogle-gemini:mainfrom
martin-hsu-test:fix/api-key-validation-logic
Open

fix: correct API key validation logic in handleApiKeySubmit#25453
martin-hsu-test wants to merge 2 commits intogoogle-gemini:mainfrom
martin-hsu-test:fix/api-key-validation-logic

Conversation

@martin-hsu-test
Copy link
Copy Markdown

@martin-hsu-test martin-hsu-test commented Apr 15, 2026

Summary

Fix a contradictory condition in handleApiKeySubmit that effectively disabled the API key validation guard.

Problem

The previous condition:

was logically contradictory:

  • apiKey.length > 1 requires 2+ characters

Combined with &&, this only matched strings of 2 or more whitespace characters. This means:

  • An empty string "" (length 0) → bypasses the guard → saved as API key
  • A single space " " (length 1) → bypasses the guard → saved as API key

The error message itself ("API key cannot be empty string with length greater than 1") hints at the confusion.

Fix

Replace with the straightforward check:

This correctly rejects any key that is empty or contains only whitespace characters, regardless of length.

Testing

  • No existing tests exercise this specific validation path with whitespace-only input.
  • The fix converts a dead-code guard into a functional one, so it is strictly an improvement with no regression risk for valid API keys.

Fixes #25456

@martin-hsu-test martin-hsu-test requested a review from a team as a code owner April 15, 2026 12:13
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 15, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 flaw in the API key validation logic within the application's authentication flow. By correcting the conditional check, the system now properly prevents invalid API keys from being accepted, ensuring better data integrity and security during the authentication process.

Highlights

  • Logic Correction: Replaced a contradictory validation condition that allowed empty or single-space API keys with a robust check that correctly identifies empty or whitespace-only inputs.
  • Error Messaging: Updated the user-facing error message to be more accurate and descriptive regarding the validation failure.
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.

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 simplifies the API key validation logic in AppContainer.tsx. The previous condition, which incorrectly required a length greater than one for empty trimmed strings, has been replaced with a standard check for empty or whitespace-only input. I have no feedback to provide.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Apr 15, 2026
contradictory: if trim() returns an empty string the key is all
whitespace, but the length check only matched 2+ whitespace characters.
This meant a single space or an empty string would bypass the guard and
be saved as a valid API key via saveApiKey().

empty or contains only whitespace characters.
@martin-hsu-test martin-hsu-test force-pushed the fix/api-key-validation-logic branch from 09372e4 to 6d66a09 Compare April 15, 2026 13:13
@gemini-cli gemini-cli bot added area/security Issues related to security and removed status/need-issue Pull requests that need to have an associated issue. labels Apr 15, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: API key validation guard is effectively dead code in handleApiKeySubmit

1 participant