Firestore and Realtime Database rules decide who can read and write your data. AI app builders often leave the starter rule that allows everything. Here is how to find and fix that.
The rule to look for
allow read, write: if true;
That lets anyone on the internet read and write the collection. Test-mode rules that expire are another trap: when they expire, the app breaks, and people paste in the open rule to make it work.
A safer pattern
Require sign-in and check ownership:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}
Each user can only reach their own documents. Add narrower rules for shared data.
How to test
Use the Firebase Emulator and the Rules Playground. Test three cases: signed out, owner, and an unrelated signed-in user. All three should behave as you intend. The signed-out and unrelated-user cases should be denied for private data.
What to check on the live app
- Does the app's JavaScript include a Firebase config? That is normal. The config is not a secret. The rules are the protection.
- Are Storage rules also restricted?
- Did you ever ship an admin or service account key in the front end? That is a real secret. Rotate it.
Free read-only check
ProofForge has a free checker for bounded anonymous Firebase signals. It does not download records: https://proofforge.live/tools/firebase-rules-checker . Fix guide for open rules: https://proofforge.live/fix/firebase-open-rules
A clean signal does not prove every path is protected. Test with the emulator.
Top comments (0)