Firebase says your security rules are insecure: how to fix test mode rules
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
- Open Firestore Database > Rules in the Firebase console, and do the same for Storage and Realtime Database if you use them.
- Write down every collection your app reads or writes, and who should be allowed to do each.
- Replace the test mode block with one
matchper collection, as above. - 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.
- For anything more than a few rules, use the Firebase Emulator to run automated rule tests, as Firebase recommends.
- Publish, then use the app normally to make sure nothing you need is now denied.
- 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.
- Install Caelo: npx caelo . or the MCP server
- How Caelo compares with gitleaks, TruffleHog, Semgrep and others
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.
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
- Firebase docs: Fix insecure rules (Cloud Firestore).
- Firebase docs: Avoid insecure rules.
- Firebase docs: Cloud Firestore quickstart (test mode and production mode).
- Firebase docs: Rules Playground.
- Firebase docs: App Check.
- Apple Developer Forums: email "Client access to your Cloud Firestore database expiring in 4 day(s)".
- Caelo source: every rule in lib/rules.js.