VibeSecCheck
Home/Security Guides/firebase-security-rules-check
Critical RiskSupabase & DatabasesFirebaseFirestoreReactAI Builders

Fixing Open Firebase Firestore Security Rules

Just like Supabase RLS, Firebase's apiKey is intentionally public — your entire database security depends on Firestore & Storage Security Rules. Shipping test-mode rules leaves every document world-readable and writable.

Why AI Builders Introduce This

Firebase Studio and AI coding assistants frequently initialize Firestore in test mode (`allow read, write: if request.time < timestamp...` or `if true`) so prototypes work without permission errors.

Real-World Exploit Impact
  • Any anonymous visitor can dump your entire Firestore users collection with a 1-line REST call
  • Attackers can overwrite subscription tiers or delete every document in your database
  • Open Firebase Storage buckets get abused to host malware or rack up massive egress bills

Vulnerable Pattern vs. Production Fix

CRITICAL: Wide-Open Firestore Rulesjavascript
// firestore.rules — EXPOSES ENTIRE DATABASE TO THE INTERNET!
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}
Locked Down Default-Deny Firestore Rules
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Default deny everything not explicitly matched
    match /{document=**} {
      allow read, write: if false;
    }

    match /users/{userId} {
      allow read, update: if request.auth != null && request.auth.uid == userId;
      allow create: if request.auth != null && request.auth.uid == userId;
    }

    match /projects/{projectId} {
      allow read, delete: if request.auth != null && resource.data.userId == request.auth.uid;
      allow create: if request.auth != null && request.resource.data.userId == request.auth.uid;
      allow update: if request.auth != null
        && resource.data.userId == request.auth.uid
        && request.resource.data.userId == request.auth.uid;
    }
  }
}

Copy-Paste AI Fix Prompt (Cursor · Lovable · Bolt · Claude Code)

Audit firestore.rules and storage.rules in this Firebase project:
1. Remove any wildcard 'allow read, write: if true;' or temporary timestamp rules and add an explicit default-deny block.
2. Scope every user/project collection to request.auth != null && resource.data.userId == request.auth.uid (and validate request.resource.data.userId on creates/updates so owners cannot be reassigned).
3. Lock billing/subscription collections to owner read-only (writes strictly via Firebase Admin SDK Cloud Functions).
4. Restrict Firebase Storage uploads by auth, file size limit, and allowed contentType.

How to Verify Your Fix Worked

  1. 1Open Firebase Console -> Firestore -> Rules Playground and simulate unauthenticated and cross-user reads/writes.
  2. 2Deploy rules with `firebase deploy --only firestore:rules,storage`.
  3. 3Scan your live app URL with VibeSecCheck to check headers, secrets, and sourcemaps.

Frequently Asked Questions

Is my Firebase apiKey supposed to be secret?

No, Firebase web apiKeys identify your project to Google servers and are public by design. Database protection comes from Firestore/Realtime DB/Storage Security Rules and App Check.

Why check both resource.data and request.resource.data on update?

Checking resource.data verifies the caller owns the existing document; checking request.resource.data stops them from changing the userId field to transfer or hijack ownership.

Should I also enable Firebase App Check?

Yes — App Check (with reCAPTCHA Enterprise or Turnstile) helps stop automated bots from abusing your public Firebase endpoints.

Related Security Playbooks