Skip to content

Conversation

@mustansir14
Copy link
Contributor

@mustansir14 mustansir14 commented Jan 8, 2026

Description:

This PR closes #4623 by introducing the Google Gemini API Key detector

All Google Gemini API Keys follow a strict pattern: A prefix AIzaSy followed by 33 characters.
Regex for the detector: \b(AIzaSy[A-Za-z0-9_-]{33})\b
I have verified this by generating 5-10 keys.

For verification, we're using Gemini's GET /v1/models endpoint. This is a safe endpoint that only lists the available models, which means no costs will be incurred. For non-gemini keys, this endpoint will return 403, which indicates that the key is active, just not scoped to Gemini. In this case, we will mark the key as unverified, but set "active_google_key": "true" in the ExtraData, so that the user can distinguish.

Added unit and integration tests as well.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@mustansir14 mustansir14 requested a review from a team January 8, 2026 08:19
@mustansir14 mustansir14 requested review from a team as code owners January 8, 2026 08:19
PhraseAccessToken = 1037;
Photoroom = 1038;
JWT = 1039;
GoogleGemini = 1040;
Copy link
Contributor

Choose a reason for hiding this comment

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

GoogleGemini is already quite specific, but are there different types of credentials available for Gemini (for example, API keys vs tokens)? If so, we might consider using a more explicit detector type like GoogleGeminiApiKey or GoogleGeminiToken instead of the generic GoogleGemini. Just a suggestion, not a blocker at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this. Yes, Google Gemini does have other ways of authenticating. I'll make the change.

_, _ = io.Copy(io.Discard, res.Body)
}()

switch res.StatusCode {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's common to receive a 403 response in a few situations:

  • the key is not scoped to Gemini, but still valid for other google services
  • the key is "restricted" either via IP address, referer, etc.

Might make sense add a case for 403s just so it's not throwing an error, when those cases are normal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this!

You are very much right. I just confirmed this by generating a Google Cloud API Key. I also realized it's not just about adding this case. Getting a 403 means that the key is live, it just does not have the Generative Language API scope enabled.

Now I'm wondering if it makes sense to create a GoogleGeminiAPIKey detector, or simply a GoogleAPIKey detector. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend keeping the original intent here and authoring a detector for only Gemini. If any other Google API services surface that are similarly risky, we can adapt then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with the approach of authoring a detector only for Gemini. My only concern here is that for 403 we'll mark the credential as inactive/rotated, but that's misleading, because the credential will be live, just not scoped to Gemini.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would endorse that we mark an API key "LIVE" if we're certain that a 403 Forbidden response implies the key is valid and capable of accessing Google services beyond just Gemini.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

I've gone ahead and made the changes to make this a GoogleCloudAPIKey detector. @joeleonjr let me know if you have concerns and we can discuss.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After internal discussion, it has been decided to make this a GoogleGeminiAPIKey detector as originally intended. For other Google Cloud API keys that have gemini disabled, we will mark them as disabled but set "active-google-key": "true" in the ExtraData field.

@mustansir14 mustansir14 changed the title [INS-246] Add Google Gemini API key detector [INS-246] Add Google Cloud API key detector Jan 12, 2026
@mustansir14 mustansir14 changed the title [INS-246] Add Google Cloud API key detector [INS-246] Add Google Gemini API key detector Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google Gemini API

5 participants