critical · M3 · MASVS-AUTH-2 · PTKD-BACKEND-FIREBASE-OPEN-RULES

    Firebase security rules open to everyone

    Firestore, Realtime Database or Storage rules let anyone (or any signed-in user) read or write all data. The Firebase config in your app is enough to use them.

    How it is exploited

    The project was created in Firestore test mode: `allow read, write: if request.time < timestamp.date(2026, 12, 1);`. Until that date anyone can list and overwrite every collection using the apiKey and projectId from the app. Afterwards the app breaks for everyone, and the usual quick fix (`if true`) makes it permanent.

    Why it matters

    Full read/write of user data by anyone; mass deletion; billing spikes from abuse.

    How to fix it

    1. Replace catch-all `match /{document=**}` rules with one `match` per collection.
    2. Require ownership: `allow read, write: if request.auth != null && request.auth.uid == resource.data.ownerId;`.
    3. Validate writes (`request.resource.data`) so users cannot set fields like isAdmin.
    4. Test with the Firebase Emulator and the Rules Playground before `firebase deploy --only firestore:rules`.

    firestore.rules

    rules_version = '2';
    service cloud.firestore {
      match /databases/{db}/documents {
        match /users/{uid} {
          allow read, write: if request.auth != null && request.auth.uid == uid;
        }
      }
    }

    Does your app have this?

    PTKD checks your build or your source project for PTKD-BACKEND-FIREBASE-OPEN-RULES and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M3)