My Firebase API key is public. Is that safe?

Usually, yes. Firebase says API keys for Firebase services are OK to include in code, because your data is protected by Security Rules and covered APIs by App Check, not by keeping the key secret. The answer changes when the same key may call paid, non-Firebase APIs, when your rules let anyone read or write, or when nothing limits sign-in attempts.

Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.

What does the Firebase API key actually do?

It tells Firebase services which project a request is for. Firebase is plain that security of your Realtime Database, Cloud Firestore and Cloud Storage data is enforced by Security Rules, and protection of covered APIs by App Check. API keys that Firebase creates for you are automatically restricted to Firebase-related APIs (API keys).

That is why hiding the key in an environment variable changes nothing: a VITE_ or NEXT_PUBLIC_ variable is sent to the browser anyway (Vite, Next.js).

When is a public key a problem?

In three cases, all from Firebase's own documentation:

  • The key can call other APIs. Firebase strongly recommends separate, restricted keys for non-Firebase APIs, and says never to include the Gemini Developer API in the allowlist of a publicly accessible key, which is critical for a billable Google Cloud service (API keys).
  • The rules are open. Firestore's test mode lets anyone read and overwrite your data (quickstart).
  • Sign-in can be hammered. Anyone with the key can reach Firebase's authentication endpoints, and Firebase suggests tightening their quota to limit brute force attempts (API keys).

How do I check my Firebase API key setup?

Six checks in the Firebase console and the Google Cloud console for your project. Do these checks only on an app you own or have written permission to test, with test accounts you created.

  1. Find the key and read its API restrictions

    In the Google Cloud console, open the Credentials page for your project and find the key your app uses, often named "Browser key (auto created by Firebase)". Read its API restrictions: they should list only the Firebase APIs your app uses (Google Cloud).

  2. Make sure no paid API is on a public key

    If the key's list includes the Gemini Developer API or another billable API, create a separate, restricted key for it, call that API from your server, and remove it from the public key (API keys).

    If it fails: Move secret keys out of the browser bundle

  3. Add an application restriction

    A websites restriction limits the key to the sites you list (Google Cloud). Add your production domain and any staging domain you use, and check that the app still signs in and loads data afterwards.

  4. Read the Security Rules of every product

    Open the Rules tab of Firestore, the Realtime Database and Storage, and look for rules that allow everyone or only check that someone is signed in. The Firebase security rules check goes through it step by step.

    If it fails: Tighten Firebase rules left open or in test mode

  5. Turn on App Check for each supported service

    Firebase's security checklist says to enable App Check for every service that supports it (security checklist). With enforcement on, requests from clients without a valid attestation are rejected. App Check and Authentication are complementary (App Check); neither replaces Security Rules.

  6. Protect sign-in

    Tighten the default quota of the identitytoolkit.googleapis.com endpoints, then confirm real users can still sign in (API keys). Turn on email enumeration protection in Authentication settings; it is on by default for projects created on or after 15 September 2023 (Google Cloud).

    If it fails: Add a rate limit to sign-in and password reset

What if a key for another API is in my app?

Treat it as exposed. Rotate it, which in Google Cloud creates a new key with the same restrictions, update your server to the new key, then delete the previous one (Google Cloud). Deleting a key that an app still uses makes that app's calls fail, so switch first (API keys). The guide to an API key exposed in the frontend has the full order of steps.

Facts worth knowing, with sources

  • Firebase says API keys for Firebase services are OK to include in code or checked-in config files. Source
  • Firebase-provisioned API keys are automatically restricted to Firebase-related APIs. Source
  • Firebase says never to include the Gemini Developer API in the allowlist of a publicly accessible API key. Source
  • Email enumeration protection is enabled by default for projects created on or after 15 September 2023. Source

Questions

Should I hide my Firebase config in environment variables?

You can, but it does not make the key secret: a VITE_ or NEXT_PUBLIC_ variable is sent to the browser anyway. Spend the effort on Security Rules, App Check and the key's API restrictions instead.

Can someone run up my bill with my Firebase API key?

Firebase-provisioned keys are restricted to Firebase-related APIs. The risk grows when a key is also allowed to call billable APIs, such as the Gemini Developer API, which Firebase says never to allow on a public key. Firebase's security checklist also suggests budget alerts.

Should I delete my Firebase API key and create a new one?

Not just because it is public. Deleting a key is permanent, and apps that still use it stop working. Rotate a key when it allows more than it should, for example a paid API.

Where does Saqr fit?

These checks cover what is on the list, on the pages you think to try. Saqr runs this kind of test on the live app for you, in a real browser and including signed-in pages, and shows the proof for each finding with a fix prompt for your AI coding tool. After you fix something, ask it to recheck. Plans are Starter at $19 a month and Pro at $49 a month, and you can cancel any time.

Every task ends in three PDFs. These are the ones from a task on a demo shop, unedited:

No test can promise an app is secure. A task tells you what Saqr found that day, with proof.

Sources

The statements above were checked against these pages on 24 November 2026. Products change; follow the links for the current wording.

  1. Firebase documentation: API keys
  2. Firebase documentation: App Check
  3. Firebase: Security checklist
  4. Google Cloud documentation: Manage API keys
  5. Google Cloud documentation: Email enumeration protection
  6. Firebase documentation: Get started with Cloud Firestore
  7. Vite documentation: Env variables and modes
  8. Next.js documentation: Environment variables

Saqr is independent and is not affiliated with Firebase, Google Cloud, Vite or Next.js. Each name is a trademark of its owner.