Firebase Security Rules: How an Open Database Gets Found

Firebase's default rules are locked, then test mode makes development easy and leaves the door open. Here is how an open Firebase database is found, what safe rules look like and how to check yours.

Dr. Security2 MIN READ

๐Ÿ’ก The short version: your Firebase web configuration is public by design, so the only thing protecting your data is your Security Rules. Firebase's own docs describe them as the only safeguard against malicious users. If your rules let anyone read or write, so can everyone.

Firebase's default rules are locked, and that's the good news. Then test mode shows up. It makes building feel effortless, and it quietly leaves the front door open. ๐Ÿšช Let's look at how that gets found, and how to shut it.

๐Ÿ”’ Locked mode vs test mode

ModeWhat it does
LockedDenies all access. For Firestore the rule is allow read, write: if false;
TestAllows anyone access. Handy while building, dangerous once the app can be reached

Firebase warns that a deployed app is publicly accessible even before it has launched, and says to update your rules before you ship.

๐Ÿ•ต๏ธ How an open database gets found

  1. The Firebase configuration (project id, API key and database address) sits in your site's JavaScript. That's normal.
  2. Anyone can read it, then ask the database for data directly, with no account.
  3. If the rules say yes, the answer comes back.

Nothing clever is needed, which is exactly why open Firebase projects are so easy to find.

๐Ÿ›ก๏ธ Rules that protect user data

Firestore: users read and write only their own document

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth != null
                         && request.auth.uid == userId;
    }
  }
}

Realtime Database: the same idea

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

๐Ÿšซ Rule shapes to avoid

  • allow read, write: if true; opens everything.
  • Rules that only check request.auth != null let any signed-in user read everyone's data. Firebase's docs advise against leaving data open to "any user that's signed in".
  • Rules written once for a prototype and never looked at again.

๐Ÿงช Check your own project

  1. Open the Firebase console and read the rules for Firestore, Realtime Database and Cloud Storage. Each one has its own.
  2. Use the Rules Playground to simulate a read as an unauthenticated user.
  3. Look for rules that return true or only check that someone is signed in.

On a paid plan, once you've verified you own the site, Dr. Security reads the Firebase address your public code points at and checks, read-only, whether the Realtime Database, Firestore and Storage answer to anyone. It reports what is exposed, never the contents.

Working with another database? Here's the Supabase equivalent.

๐Ÿš€ Not sure what your site exposes? Start with a free scan of your live site.

  • firebase security rules
  • firestore security rules
  • open firebase database
  • realtime database rules
  • firebase security

FIND OUT WHAT YOU'RE EXPOSING.