criticalCWE-862

Firestore Rules Allow Read/Write True

Firestore security rules set to 'allow read, write: if true' give any user — authenticated or not — full access to read, create, modify, and delete all documents.

How It Works

Cloud Firestore uses security rules to control access to documents and collections. The rule 'allow read, write: if true' grants unrestricted access to everyone. Firebase projects start with this rule in test mode, but developers often forget to change it before going to production. Since Firebase config (apiKey, projectId) is public and embedded in the frontend, anyone can use the Firebase SDK to connect and perform any operation on any document. Attackers can exfiltrate all data, delete collections, or inject malicious content.

Vulnerable Code
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}
Secure Code
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;
      allow write: if request.auth != null
        && request.auth.uid == resource.data.authorId;
    }
  }
}

Real-World Example

In 2020, security researchers from Comparitech found 24,000 Firebase databases exposed due to open rules. They contained 4.22 billion records including plaintext passwords, health records, financial transactions, and GPS coordinates from apps with millions of users.

How to Prevent It

  • Never deploy with 'allow read, write: if true' rules
  • Always require request.auth != null for authenticated operations
  • Scope write access to document owners using request.auth.uid
  • Use the Firebase Emulator to test rules before deploying

Affected Technologies

FirebaseNode.jsReactMobile

Data Hogo detects this vulnerability automatically.

Scan Your Repo Free

Related Vulnerabilities