caelo

Caelo › Guides › Firebase insecure rules alert

Firebase says your security rules are insecure: how to fix test mode rules

By Arthi Arumugam, Irth Labs · Published · Updated

Short answerThe alert means your Firestore or Storage rules let anyone read or write without a real check, usually the test mode rule from when you created the database, or allow read, write: if true. Replace it with rules that check request.auth and who owns each document, test them in the Rules Playground or the emulator, then publish.

What triggered the alert?

Firebase's "Fix insecure rules" page starts: "If you receive an alert that your Cloud Firestore database isn't properly secured, you can resolve the vulnerabilities by modifying and testing your Cloud Firestore Security Rules." Firebase describes test mode as good for getting started, "but allows anyone to read and overwrite your data."

Developers also report emails titled "Client access to your Cloud Firestore database expiring in 4 day(s)". That one is about test mode's date: when the date passes, browser and mobile clients lose access and your app stops working.

Vulnerable: test mode, open to everyone until a date

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2026, 12, 20);
    }
  }
}

match /{document=**} covers every document in the database. Until that date, anyone with your public Firebase config can read, change or delete all of it.

Why not just push the date forward?

Changing the date silences the email and keeps the app working, but it also keeps the whole database open. Changing it to if true removes the expiry and makes it permanent. Both are the leak the alert is warning you about. The fix is a rule per collection that names who may do what.

Rules to use instead

Fixed: users own their own documents, posts are public to read

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
    match /posts/{postId} {
      allow read: if true; // public content, on purpose
      allow create: if request.auth != null
        && request.resource.data.authorId == request.auth.uid;
      allow update, delete: if request.auth != null
        && resource.data.authorId == request.auth.uid;
    }
  }
}

There is no match /{document=**} any more, so any collection you have not written a rule for is denied. Keep fields such as role, plan or credits out of reach of the client entirely and change them only from a server, as our Firebase rules guide explains.

Fix it, step by step

  1. Open Firestore Database > Rules in the Firebase console, and do the same for Storage and Realtime Database if you use them.
  2. Write down every collection your app reads or writes, and who should be allowed to do each.
  3. Replace the test mode block with one match per collection, as above.
  4. Test in the Rules Playground: Firebase says it "displays a message confirming that access was either allowed or denied." Try a read of another user's document while signed out and while signed in as a second user. Both should be denied.
  5. For anything more than a few rules, use the Firebase Emulator to run automated rule tests, as Firebase recommends.
  6. Publish, then use the app normally to make sure nothing you need is now denied.
  7. Consider App Check, which Firebase says helps protect your backends "by preventing unauthorized clients from accessing your backend resources." It is an extra layer, not a replacement for rules.

Check it automatically

Caelo reads firestore.rules, storage.rules and database.rules.json in your project and flags rules with no condition: allow read, write: if true, a bare allow write;, and ".write": true in Realtime Database (firebase.open-rule). Open writes are critical. It does not flag the test mode date rule, and it cannot see rules that exist only in the Firebase console, so open the console's Rules tab as well.

Caelo output for an open Firestore rule

- Firebase rule lets anyone write
    firestore.rules:7  (firebase.open-rule)
    value: allow read, write: if true
    why: There is no condition, so any visitor can write this data without signing in.

1. Run the free local check

npx caelo .

Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and .env files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.

2. Act on a finding

Follow the fix in your report and run Caelo again. If Git could commit an untracked file containing secrets, preview a US$19 quick fix for that file.

For findings that need an engineer, Irth Labs offers a US$490 App Health Check. You receive a written report within 48 hours and a fixed repair quote. The fee counts toward the repair if you proceed.

Book the App Health Check See repair services

Questions

What happens when test mode expires?

The rule's condition becomes false, so clients are denied and your app's reads and writes fail. Server code using the Admin SDK is not affected by security rules.

Is the Firebase apiKey in my app the problem?

No. Firebase web config is public by design and only identifies your project. Your security rules decide what that config can reach.

Is allow read, write: if request.auth != null safe?

Only for data every signed-in user may see and change. It lets anyone who creates an account read and overwrite everyone else's documents. Check ownership too.

Do I need to fix Storage rules as well?

Yes, if you use Cloud Storage. Storage has its own rules with the same test mode pattern, and an open Storage rule lets anyone read or overwrite uploaded files.

Sources