Skip to content

Firebase Security Rules: A Practical Deep Dive

12 min read
FirebaseSecurityFirestoreRules
Firebase Security Rules

Firebase Security Rules: A Practical Deep Dive

Security Rules are the first and last line of defence for your Firestore data. Here is what years of production use taught me.

The Core Mental Model

Rules answer one question: "Should this request be allowed?" They do NOT filter results — if a query would match a document a user can't read, the entire query is rejected.

Common Patterns

Role-based access

function isAdmin() {
  return request.auth != null
    && get(/databases/$(database)/documents/users/main/users/$(request.auth.uid)).data.role == 'admin';
}

Protecting updates to sensitive fields

allow update: if isOwner(userId)
  && !('role' in request.resource.data);

Anti-patterns to Avoid

  • Never allow read, write: if true in production
  • Never trust client-supplied user IDs — always use request.auth.uid
  • Never skip testing rules with the Firebase Rules Playground
GM

About the Author

Gerasimos Makris

AI Web Developer & FinTech Specialist

View Resume

Gerasimos Makris is an AI Web Developer with a background in FinTech operations. He specializes in building secure, scalable web applications that solve real-world financial problems. When he's not coding, he enjoys exploring the intersection of technology, finance, and business strategy.

Share:

Valuing Your Privacy

We use cookies to optimize your experience, analyze site usage, and support personalization. By clicking “Accept All”, you consent to our use of cookies. Learn more in our Cookie Policy.