Guides · Updated 2026-11-10
Is my Firebase database open? How to check Firestore and Realtime Database rules (test mode) before strangers do
Short answer: It depends on your Security Rules, not on your API key. The Firebase apiKey in your web app is public by design: it only identifies your project. What protects your data are Firebase Security Rules (and App Check). If your Firestore rules say `allow read, write: if true`, or your Realtime Database rules say ".read": true at the top, or you're still on test-mode rules, anyone who finds your project ID can read and overwrite your data. Open the Rules tab, replace open rules with owner-only rules, and test them in the Rules Playground before you publish.
The API key is not the problem. The rules are.
Apps built with AI tools often ship a Firebase config object with an apiKey in the public JavaScript. Firebase's own docs say this key is public by design: it only identifies your Firebase project, and access to your data is controlled by Firebase Security Rules and App Check, not by keeping the key secret.
So hiding the key won't protect you, and finding it in your bundle isn't an emergency by itself. The real question is what your rules allow. Two exceptions: a key used for other Google APIs (for example the Gemini Developer API) must stay out of your code, and every key should have API restrictions in the Google Cloud console (APIs & Services > Credentials).
What 'open' looks like
When you create Firestore or Realtime Database in the console you pick a starting mode. Firebase describes test mode as allowing anyone to read and overwrite your data, and production (locked) mode as denying all reads and writes from web and mobile clients. Many quick-start and AI-generated setups pick test mode and never change it.
Firestore rules that leave everything open look like this:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}Realtime Database rules that leave everything open look like this:
{
"rules": {
".read": true,
".write": true
}
}Also watch for a rule like `allow read, write: if request.time < timestamp.date(...)`. That is open to everyone until the date in it. And a rule like `if request.auth != null` only checks that someone is logged in: if anyone can sign up, anyone can read and write everything.
Firebase's guide on insecure rules puts it plainly: if you're not authenticating users and configuring security rules, anyone who guesses your project ID can steal, modify, or delete the data. Your project ID is in the same public config as the API key.
How to check your rules in 5 minutes
- In the Firebase console, open your project, go to Firestore (and/or Realtime Database, and Storage) and click the Rules tab. The console always shows the rules that are actually deployed.
- Look for `if true`, `".read": true` / `".write": true` near the top, `request.time <` with a date, or rules that only check `request.auth != null` / `auth !== null` on everything.
- Open the Rules Playground (Firestore > Rules > Rules Playground) and simulate an unauthenticated get on a real path, for example users/some_id. If it says allowed and that data is private, your database is open.
- If you deploy rules from code (firebase.json points to a .rules file), check that file too. Deploying with the Firebase CLI overwrites what's in the console, so keep both in sync.
- For Realtime Database you can also test from outside on your own project: `curl https://<your-project-id>-default-rtdb.firebaseio.com/.json` (or your database URL + /.json). If it returns your data instead of a permission error, it's readable by anyone.
Only test projects you own. A quick outside check of your live site, including whether Firebase config and open Realtime Database data are visible, is what the free scan at the top of this page does.
How to lock it down
Replace open rules with rules that match your data. The most common safe pattern is owner-only: each user can read and write only their own documents. In Firestore:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}In Realtime Database:
{
"rules": {
"users": {
"$uid": {
".read": "auth !== null && auth.uid === $uid",
".write": "auth !== null && auth.uid === $uid"
}
}
}
}- Anything not matched by a rule is denied in Firestore, and in Realtime Database access is denied unless a rule at or above that path allows it. Start closed and open only what you need.
- Realtime Database rules cascade: a `.read: true` at a parent path can't be taken back by `.read: false` deeper down. Don't put broad rules at the top.
- If your app only reads and writes from a server (Admin SDK, Cloud Functions), you can deny all client access: `allow read, write: if false;`. The Admin SDK is not affected by Security Rules.
- Public data (for example published posts) can be `allow read: if true` while writes stay owner-only. Make that a deliberate choice per collection, not a global wildcard.
- Turn on App Check so only your real app can call your Firebase backend. It complements rules; it doesn't replace them.
- Do the same review for Cloud Storage rules: `allow read, write;` on {allPaths=**} lets anyone read and overwrite every file.
Rule changes can take up to a minute for new queries and up to 10 minutes to reach active listeners. After publishing, run the Playground check and the outside check again.
A prompt you can paste into your AI builder
Review my Firebase Security Rules for Firestore, Realtime Database and Storage. Remove any rule that allows read or write to everyone (if true, ".read": true, test-mode date rules) or to any logged-in user on all data. Write owner-only rules based on request.auth.uid for user data, keep public read only where I explicitly need it, and show me the final rules files plus Rules Playground tests for an unauthenticated read and for one user reading another user's data (both should be denied).
Sources
Related: what to do if you leaked a real secret key (https://leakyvibe.com/guides/leaked-api-key-what-to-do) and is the Supabase anon key safe to expose (https://leakyvibe.com/guides/is-supabase-anon-key-safe-to-expose).
Official sources (checked 2026-11-10): Firebase, "Avoid insecure rules" (https://firebase.google.com/docs/rules/insecure-rules); Firebase, "Learn about and manage API keys for Firebase" (https://firebase.google.com/docs/projects/api-keys); Firebase, "Get started with Cloud Firestore Security Rules" (https://firebase.google.com/docs/firestore/security/get-started); Firebase, "Get started with Cloud Firestore" test vs production mode (https://firebase.google.com/docs/firestore/quickstart); Firebase, "Core syntax of Realtime Database Security Rules" (https://firebase.google.com/docs/database/security/core-syntax).