Menu

Firebase rules: how to find allow read, write: if true and fix it before launch
📰

Firebase rules: how to find allow read, write: if true and fix it before launch

DEV Community: firebase·ProofForge·3 days ago
#76LJrKSn
#devtofirebase#devto#dev#rules#firebase
Long article (272 words) — no AI summary yet.
Reading 0:00
15s threshold

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;

Enter fullscreen mode

Exit fullscreen mode

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; } } }

Enter fullscreen mode

Exit fullscreen mode

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.