Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
Updated · Applies to: Firebase, Firestore, Replit, Bolt, Cursor, FlutterFlow
TL;DR fix: Your Firestore rules allow open access, usually allow read, write: if true or a global match /{document=**} left over from Test mode. Anyone on the internet can read (and maybe write) your whole database. Replace it with per-collection rules: public data gets allow read: if true but no public writes, and user data gets request.auth.uid == userId. Test in the Rules Playground, then publish.
Steps
- Open your current rules. Firebase console → Firestore Database → Rules. Look for allow read, write: if true, a time-limited test-mode rule, or match /{document=**}.
- List your collections and who should access each. For each collection decide: public read? signed-in users only? only the owner? server only?
- Replace the global wildcard with per-collection rules. Write a match block per collection and keep a final deny-by-default. Don't use match /{document=**} with allow read, write.
- Restrict writes to owners. Use request.auth.uid == userId for user documents, or compare to a field like request.resource.data.ownerId for created documents.
- Test before publishing. Use the Rules Playground (or the emulator) to try reads and writes as a signed-out user, the owner, and a different user.
- Publish and confirm the app still works. Publish the rules, then click through your app. Move admin-only operations to Cloud Functions or a server using the Admin SDK.
Replace open rules with this starting point
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Public catalog: anyone can read, nobody writes from the client
match /products/{productId} {
allow read: if true;
allow write: if false;
}
// Each user can read and write only their own profile
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// Posts: public read, only the author can create/edit
match /posts/{postId} {
allow read: if true;
allow create: if request.auth != null
&& request.resource.data.authorId == request.auth.uid;
allow update, delete: if request.auth != null
&& resource.data.authorId == request.auth.uid;
}
// Everything else: denied by default (no match = no access)
}
}
Firebase’s own guidance: “If you’re not authenticating users and configuring security rules, then anyone who guesses your project ID can steal, modify, or delete the data.” (Firebase docs)
Prompt for your AI tool
Our Firestore rules are "allow read, write: if true". Replace them with per-collection rules:
list every collection the app uses, propose who may read/write each, require request.auth.uid
ownership for user data, deny everything else. No global /{document=**} allow rule. Show rules first. When to get help
Get help if your data model mixes public and private fields in the same documents, if you have admin roles, or if the database was open long enough that you need to check what was read or changed.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
What does "Your Cloud Firestore database has insecure rules" mean?
Firebase detected security rules that let any user read or write your entire database, typically allow read, write: if true or an expired test-mode rule. Anyone who knows your project ID, which is public in your app config, can access the data. Replace them with per-collection rules that check request.auth.
Is "allow read, write: if request.auth != null" secure?
It is better than open access but often still too broad: any signed-up user can read and change every document, including other users' data. Firebase's docs warn to confirm you really want any logged-in user to have access, and to narrow it with conditions like request.auth.uid == userId.
My Firebase config (apiKey) is in my frontend. Is that a leak?
No. The Firebase web config including apiKey is meant to be public. Security comes from Security Rules (and App Check), which is why open rules are the real problem.
Sources
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- "Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)