Skip to content

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

@martin-hsu-test

Description

@martin-hsu-test

Description

The validation condition in handleApiKeySubmit (packages/cli/src/ui/AppContainer.tsx) is logically contradictory and never triggers, allowing empty or whitespace-only strings to be saved as valid API keys.

Current Behavior

The current condition:

  onAuthError('API key cannot be empty string with length greater than 1.');
  return;
}
  • apiKey.length > 1 requires 2 or more characters

Combined with &&, this only matches strings of 2 or more whitespace characters. The following invalid inputs all bypass the guard:

  • Empty string "" (length 0) → saved as API key ✅ (should be rejected)
  • Single space " " (length 1) → saved as API key ✅ (should be rejected)

Expected Behavior

Any API key that is empty or contains only whitespace should be rejected with an error message before calling saveApiKey().

Steps to Reproduce

  1. Launch gemini-cli and reach the API key input prompt
  2. Enter a single space or leave the field empty
  3. Submit — the empty/whitespace value is accepted and saved

Proposed Fix

  onAuthError('API key cannot be empty or whitespace only.');
  return;
}

File: packages/cli/src/ui/AppContainer.tsx line 877

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/securityIssues related to securityhelp wantedWe will accept PRs from all issues marked as "help wanted". Thanks for your support!type/bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions