The short answer
If you open almost any Firebase web app and look at its page source, you'll find a config object with an apiKey. That's normal. Firebase's documentation on API keys explains that these keys only identify your Firebase project and app to Google's services. They don't decide who can read your data: Firebase Security Rules and App Check do that.
So you don't need to hide the key, and you can't: the browser needs it. What you need to get right is everything around it.
What the web API key can and can't do
- It can tell Google which project a request is for, so the Firebase SDK in the browser can sign users in and reach Firestore, the Realtime Database and Storage.
- It can't bypass your Security Rules. A read that your rules refuse is refused, whoever holds the key.
- It can be used from someone else's website if you haven't restricted it, which matters for quotas and paid services like phone sign-in or Maps.
Firebase applies API restrictions to the keys it creates for Firebase services. You can also restrict which websites may use a browser key, in Google Cloud under APIs & Services → Credentials. If you use the same project for Google Maps or other paid APIs, the Firebase security checklist recommends separate keys, each restricted to what it's for.
The Firebase credentials that really are secret
The same checklist names credentials that must never be in client code:
- Service account private keys (a JSON file with
"type": "service_account"and aprivate_key). Anyone with one can act as your server, with admin access that ignores Security Rules. - FCM server keys for the legacy Cloud Messaging API, which can send notifications as your app.
If either ends up in your website, a public repository or a shared file, delete the key in Google Cloud and create a new one.
Security Rules are where data leaks happen
Because the browser talks to the database directly, your rules are the only thing between a visitor and your data. The usual mistakes:
Rules that allow everything
allow read, write: if true; opens the data to the whole internet. Firebase's guide to insecure rules says never to use it in production. It often stays in place from early development.
"Signed in" instead of "owner"
allow read: if request.auth != null; lets every signed-in user read every document. If anyone can sign up, that's close to public. Compare the user's id with the document's owner instead, for example request.auth.uid == resource.data.ownerId.
Forgetting Storage and the Realtime Database
Firestore, the Realtime Database and Cloud Storage each have their own rules. Locking one down doesn't lock the others.
How to check your own app
- Read your rules for Firestore, the Realtime Database and Storage, in the Firebase console. Look for
if trueand for rules that only checkrequest.auth != null. - Test them with the Rules Playground in the console or the Firebase emulator, as Firebase recommends, including as a signed-out user and as a different user.
- Search your website's JavaScript (browser developer tools) for
private_keyandservice_account. Neither should be there. - In Google Cloud → Credentials, restrict your browser key to your own domains.
- Consider App Check so only your app can use your back-end resources.
What Securick checks
From your public URL:
- #7 Google/Firebase API key without restrictions Free
- #42 Firebase service account exposed Pro
- #8 Private key exposed Free
On a domain you verify, the Deep scan reads without signing in, using only what your web app already publishes, and reports what was open. It never writes:
- #61 Firebase Realtime Database not open to read Deep
- #62 Firestore not open to read Deep
- #63 Firebase Storage not open to list Deep
- #96 Data isolation between users Deep
- #97 User files and profiles isolated Deep
More in our Firebase security check.
Questions
Google emailed me that my Firebase API key is public. What should I do?
For a Firebase web key that's expected. Check that it's restricted to your own websites and the APIs you use, and that your Security Rules are strict. If the warning is about a service account key, delete that key and create a new one.
Can someone steal my data with my Firebase API key?
Only what your Security Rules allow. The key identifies your project; the rules decide access. That's why rules that allow everything are the real risk.
Should I put the Firebase config in environment variables?
You can, for tidiness, but it still ends up in the browser. It's designed to be public, so focus on rules and key restrictions rather than hiding it.