Google Cloud / Firebase API Key Hardcoded
Flags hardcoded Google Cloud Platform, Google Maps, Gemini, YouTube, and Firebase API keys matching the 39-character AIza signature.
- Rule Slug
- google-cloud-firebase-api-key
- Affected Files
- *
- Detection Method
- Regex + Entropy (>= 3.4)
Vulnerable Pattern vs. Hardened Fix
// services/geocode.ts
const GOOGLE_MAPS_KEY = 'AIzaSyD4k9xL2mP7qR8sT1uV3wX5yZ6aB8cD0eF2';
export async function geocode(address: string) {
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${GOOGLE_MAPS_KEY}`);
}// services/geocode.ts (server-side proxy)
const GOOGLE_MAPS_KEY = process.env.GOOGLE_MAPS_SERVER_KEY;
if (!GOOGLE_MAPS_KEY) {
throw new Error('Missing GOOGLE_MAPS_SERVER_KEY');
}
export async function geocode(address: string) {
return fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address)}&key=${GOOGLE_MAPS_KEY}`);
}Why This Fails in Production
Google Cloud API keys share a distinctive 39-character signature starting with AIza. While Firebase client SDK keys are technically meant to identify a project in web or mobile apps, developers frequently confuse Firebase client config keys with unrestricted Google Cloud API keys used for Google Maps Platform, Gemini AI (Generative Language API), Cloud Vision, Places, or Translation APIs. When an unrestricted AIza key is committed to a public repository, attackers immediately test it against dozens of billable GCP endpoints.
An unrestricted Google Cloud API key can incur thousands of dollars in unexpected quota charges on Google Maps Geocoding, Directions, or Gemini APIs within a single billing cycle. In Firebase projects, an exposed AIza key combined with overly permissive Firestore, Realtime Database, or Cloud Storage security rules enables attackers to read or overwrite entire collections, invoke open Identity Toolkit signup endpoints, and abuse email verification quotas.
Even when an API key is intentionally used on the frontend (such as Google Maps JavaScript API or Firebase Auth), hardcoding it across multiple source files makes key rotation slow and error-prone and prevents per-environment separation between staging and production GCP projects. Furthermore, server-side GCP keys (like Gemini or YouTube Data API keys) should never appear in source control or frontend code at all.
Every AIza key detected before a push should be verified in the Google Cloud Console: restrict frontend keys by HTTP referrer or app package signature plus explicit API allowlists, and move all server-side API keys into environment variables.
Remediation Steps
- 1Open Google Cloud Console -> APIs & Services -> Credentials and inspect the exposed key’s Application Restrictions and API Restrictions.
- 2If the key is used server-side (e.g., Gemini, Places server API, Cloud Vision), rotate it immediately and load it exclusively from server environment variables.
- 3If the key is a legitimate browser-side Firebase or Maps key, lock it down with strict HTTP referrer restrictions (e.g., https://yourdomain.com/*) and enable only the minimum required APIs.
- 4Verify Firebase Firestore and Storage Security Rules to ensure authentication and authorization never rely on secrecy of the API key.
Frequently Asked Questions
- Is a Firebase Web API Key actually a secret?
- Firebase client apiKey values are public project identifiers, not authentication secrets; security comes from Firebase Security Rules and App Check. However, the same AIza prefix is used for billable GCP and Gemini API keys, so you must verify API and referrer restrictions in GCP Console.
- How do I prevent billing abuse on a leaked Google Maps key?
- Apply HTTP referrer restrictions in Google Cloud Console, restrict the key solely to the specific Maps APIs you consume, and configure daily quota caps and budget alerts.
- Does Gemini API use the AIza key format?
- Yes. Google AI Studio / Gemini API keys start with AIza and must always be kept strictly server-side behind environment variables.