How do I check my Firebase security rules?

Read the rules that are deployed, for every product you use: Cloud Firestore, the Realtime Database and Cloud Storage. Look for rules that allow everyone or only check that someone is signed in. Then test from the outside as a visitor and as a second user, and keep unit tests in the emulator so the rules stay right as the app changes.

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.

Why do the rules decide so much?

In a Firebase app, the browser or phone talks to your database and storage directly. Firebase is plain about it: the data in the Realtime Database, Cloud Firestore and Cloud Storage is protected by Security Rules, and covered APIs by App Check, not by keeping the API key secret (API keys). App Check helps confirm requests come from your real app; Firebase calls it complementary to Authentication, and it does not decide which user may read which document (App Check). Firestore's test mode allows anyone to read and overwrite your data (quickstart).

Do the three products' rules work the same way?

Not quite. Firestore and Storage rules are match blocks with allow conditions. In Firestore, rules are not filters: if a query could return a document the user may not read, the whole query is refused (securely query data). Realtime Database rules cascade: a rule at a parent path overrides the rules below it, and a child rule can only grant more, never take access away (insecure rules, core syntax).

How do I check the rules, step by step?

Seven steps on your own project. Do these checks only on an app you own or have written permission to test, with test accounts you created.

  1. Open the deployed rules of every product

    In the console, open the Rules tab of Firestore, the Realtime Database and Storage, even the ones you think you do not use. Compare each with the rules file in your project. The deployed rules are the ones your users meet.

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

  2. Look for rules that allow everyone

    Search for allow read, write: if true, for a match /{document=**} at the top with a broad allow, and, in the Realtime Database, for ".read": true or ".write": true near the root (Firebase's list of insecure rules). Each needs a real condition unless the data is meant to be public.

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

  3. Look for rules that only check sign-in

    Firebase lists allow read, write: if request.auth != null as not recommended: any signed-in user can then read and change everything it covers (insecure rules). For user data, compare request.auth.uid with the owner, as in match /users/{userId} { allow read, write: if request.auth != null && request.auth.uid == userId; } (basic rules). On writes, check request.resource.data too, so nobody can set the owner field to someone else (conditions).

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

  4. Check what each Realtime Database parent grants

    Because the rules cascade, read every .read and .write from the root down. A broad rule on a parent cannot be narrowed by a stricter rule on a child, so move the grant down to the paths that need it.

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

  5. Ask as a visitor

    From a terminal, with no sign-in, request a private Firestore collection through the REST API at https://firestore.googleapis.com/v1/projects/ followed by your project id and /databases/(default)/documents/ and the collection name (Firestore REST API). For the Realtime Database, request the database address shown in the console followed by /.json?shallow=true (Realtime Database REST API). Unless the data is meant to be public, both should be refused with a permission error.

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

  6. Ask as a second user

    In the Rules Playground, choose a read of a path that belongs to your first test account, set the authentication to the second account's user id, and run it; it should be denied. Repeat for a write and for a Storage path (Rules Playground). Then confirm in the app itself: signed in as the second account, change an id in the address to the first account's.

    If it fails: Stop one user reading another user's records by changing an id

  7. Keep unit tests and deploy from the tested file

    With the emulator and the @firebase/rules-unit-testing library, write tests that use assertFails and assertSucceeds for a visitor, the owner and another user, for reads and writes (unit tests). Deploy the same file with firebase deploy --only firestore:rules, database or storage (manage and deploy), so what you tested is what runs.

What if a step fails?

Change the rule in your rules file, add a unit test that fails on the old rule, deploy from that file, and repeat the outside request that failed. If a Firestore query starts failing after you tighten a rule, add the rule's condition to the query too, for example the owner's id. The Firebase guide covers keys and storage; the fix prompts have ready instructions for your AI coding tool.

Facts worth knowing, with sources

  • Firestore's test mode allows anyone to read and overwrite your data. Source
  • Firebase lists rules that only check that a user is signed in as not recommended: any signed-in user gets access to everything the rule covers. Source
  • Realtime Database rules cascade: a child rule can only grant additional access, never revoke it. Source
  • Firestore rules are not filters: a query that could return documents the user may not read fails as a whole. Source
  • Firebase data is protected by Security Rules and App Check, not by keeping the API key secret. Source

Questions

Does App Check replace Security Rules?

No. App Check helps confirm that requests come from your real app, and Firebase describes it as complementary to Authentication. Which user may read or change which document is still decided by Security Rules.

Do the Rules Playground and the emulator test my live app?

No. The Rules Playground simulates requests in the console, and the emulator runs your rules file on your machine. Neither sends a real request to your live app, so finish with a test from the outside.

Why does my Firestore query fail when each document is allowed?

Rules are not filters. Firestore checks a query against everything it could return, and if any of that could be a document the user may not read, the whole query is refused. Add the condition the rule checks to the query, for example the owner's id.

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.