Guides · VibeVigil
Firebase Says My Firestore Rules Are Insecure (or Test Mode Is Expiring): How to Fix It in an AI-Built App
Got a Firebase email that your Cloud Firestore database has insecure rules, or that client access expires soon? Here's what test mode really allows, why 'request.auth != null' is not enough, how to test your rules in the Rules Playground, and a prompt to have Cursor, Bolt, v0 or Firebase Studio write owner-only rules.
Not sure your app is safe? Run a free scan first.
VibeVigil checks your live web app for exposed keys, Supabase tables a stranger can read, missing security headers, SSL problems and downtime. Every issue comes with a ready-to-paste prompt for your coding agent.
Scan my app for free → (only scan apps you own)
Note: the scan does not read your Firebase Security Rules. Use the steps below to check your Firestore and Storage rules yourself.
Firebase Says My Firestore Rules Are Insecure. What Do I Do?
You built your app with an AI tool and picked Firebase for the database. Everything works. Then an email arrives: your Cloud Firestore database has insecure rules, or client access to your database is expiring in a few days.
Both emails point at the same thing: your Security Rules. In a Firebase app, the browser or phone talks straight to the database. The rules are the only thing that decides who can read, change or delete each document. This guide shows what the email means, how to check your rules, and how to fix them without breaking your app.
The short answer
- Test mode means anyone can read and change your data. Firebase says test mode "allows anyone to read and overwrite your data" (Firebase: Get started with Cloud Firestore).
- Test mode stops working after 30 days. The default test rule is "configured to expire after 30 days." After that, "all client requests to your database will be denied" (firebase-tools: default Firestore rules). That is the "expiring" email.
- Do not just move the date forward. That keeps your whole database open to everyone.
request.auth != nullis not a fix on its own. It lets any logged-in user read and change everyone's data. Rules should check who owns each document.- Your Firebase API key is not the problem. Firebase says these keys are fine in your code. Your data is protected by Security Rules, "not by keeping your Firebase API key secret" (Firebase: API keys).
Why this happens
When you create a Firestore database, Firebase asks you to pick a starting mode. Many tutorials and AI agents pick test mode, because it makes everything work right away. The rule it writes looks like this:
match /{document=**} {
allow read, write: if request.time < timestamp.date(2026, 12, 20);
}{document=**} means "every document in the database." So until that date, anyone can read, change or delete anything. Firebase warns that if you deploy an app with open rules, "anyone who guesses your project ID can steal, modify, or delete the data" (Firebase: Avoid insecure rules). Your project ID is in your app's public code, so it is not hard to guess.
When the date passes, every request from your app is denied. Your app shows errors like "Missing or insufficient permissions." Your data is still there. The rules just stopped letting anyone in.
The three kinds of rules you might have
Open your rules and see which one looks like yours.
| Your rule says | What it means | Safe for a live app? |
|---|---|---|
allow read, write: if true; or if request.time < timestamp.date(...) | Anyone on the internet can read and change everything | ❌ No |
allow read, write: if request.auth != null; | Any logged-in user can read and change everyone's data | ❌ Usually no |
allow read, write: if request.auth.uid == userId; (or checks an owner field) | Each user can only reach their own documents | ✅ Yes, for private data |
Why is the middle one a problem? If your app has a sign-up button, anyone can make an account in a minute. Firebase's own guide lists auth != null as a common mistake and says to "confirm that you want any logged-in user to have access to the data" (Firebase: Avoid insecure rules).
How to check your rules
Step 1: Find the rules that are really live
- Open the Firebase console and pick your project.
- Go to Databases & Storage → Firestore → Rules.
- If you use file uploads, also check Storage → Rules. If you use Realtime Database, check its Rules tab too. Each one has its own rules (Firebase: Avoid insecure rules).
Firebase says the console "always shows the most recently deployed version" of your rules. If your AI tool also keeps a firestore.rules file in your project, deploying it with the Firebase CLI will overwrite what is in the console (Firebase: Get started with Security Rules). Pick one place to edit and stick to it.
Step 2: Test like a stranger in the Rules Playground
On the Rules tab, click Rules Playground. It lets you test reads and writes as a signed-out or signed-in user (Firebase: Get started with Security Rules). Try these:
- Signed out, get a real document path, like
orders/abc123. It should be denied. - Signed in as user B, get a document that belongs to user A. It should be denied.
- Signed in as user B, update user A's document. It should be denied.
- Signed in as user A, get their own document. It should be allowed.
The Playground tests the rules in the editor, not the ones you already published. So test, then click Publish.
How to fix it
Owner-only rules (the most common fix)
If each user has private data, store their user ID on each document (or use it as the document ID) and check it. This is close to Firebase's own "content owner only" example (Firebase: Avoid insecure rules):
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Each user's profile: document ID is their user ID
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
// Documents with an owner field
match /orders/{orderId} {
allow read, delete: if request.auth != null && request.auth.uid == resource.data.owner_uid;
allow create: if request.auth != null && request.auth.uid == request.resource.data.owner_uid;
allow update: if request.auth != null
&& request.auth.uid == resource.data.owner_uid
&& request.auth.uid == request.resource.data.owner_uid;
}
}
}resource.data is the document as it is saved now. request.resource.data is the document after the change. Checking both on update stops a user from handing a document to someone else.
There is no match /{document=**} line here. Any collection without its own rule is closed by default. That is what you want.
Stop users from giving themselves "admin" or "pro"
A common AI-built pattern: the user's profile has a field like role, isAdmin, plan or credits, and the app trusts it. With owner-only rules, users can still edit their own profile, and that includes those fields.
Firebase shows how to allow only some fields to change with affectedKeys().hasOnly(...) (Firebase: Control access to specific fields):
match /users/{userId} {
allow read: if request.auth != null && request.auth.uid == userId;
allow update: if request.auth != null && request.auth.uid == userId
&& request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['displayName', 'photoURL']);
}Set fields like role and plan only from your server or a Cloud Function (for example, after a verified Stripe webhook).
If your app breaks after the fix
- "Missing or insufficient permissions" on a list page. Firebase says "security rules are not filters." If a query could return one document the user can't read, the whole query fails (Firebase: Securely query data). Add a filter that matches your rule, like
where("owner_uid", "==", user.uid). - Changes don't show up yet. New rules can take up to a minute for new queries and up to 10 minutes for open listeners (Firebase: Get started with Security Rules).
The security part: things your rules don't cover
- Server code skips the rules. The Admin SDK and server libraries "bypass all Cloud Firestore Security Rules" (Firebase: Get started with Security Rules). That is fine on your server. But a service account key (a JSON file with
private_keyin it) must never be in your frontend code or a public repo. - The API key is public, but keep it limited. Firebase says keys for Firebase services can sit in your code, but they should only allow Firebase APIs. Firebase warns that the Gemini API should never be on the allow list of a public key (Firebase: API keys). If your app calls Gemini or OpenAI, do it from the server with a separate key.
- App Check helps, rules still matter. App Check makes it harder for other apps to use your backend, but Firebase lists Security Rules as what protects your data (Firebase: API keys).
Prompt for your coding agent
Copy this into Cursor, Bolt, v0, Firebase Studio, Claude Code or Lovable:
Please review and fix my Firebase Security Rules. My app is live, so do not open anything up, even for testing.
1. Find my Firestore rules (firestore.rules and firebase.json) and my Storage rules (storage.rules). Tell me if any rule uses "if true", "request.time < timestamp.date(...)", or "request.auth != null" with no owner check, or a match /{document=**} that allows access.
2. List every collection my app reads or writes, and which user should be allowed to read, create, update and delete each one.
3. Write new rules where private documents can only be reached by their owner (request.auth.uid matches the document ID or an owner_uid field). On update, check the owner both before and after the change.
4. Make sure users cannot change fields like role, isAdmin, plan, credits or anything about payments. Use request.resource.data.diff(resource.data).affectedKeys().hasOnly([...]) with only the fields users should edit. Those fields should be set only by server code.
5. Update my queries so they filter by the same owner field the rules check (rules are not filters).
6. Do the same for Storage: files under a path with the user's ID, only that user can read and write.
7. Check that no service account JSON or private_key is in my frontend code or repo.
8. Give me a test plan for the Rules Playground: signed out, user B reading and editing user A's data, and user A reading their own data.
Do not extend the test mode date and do not use "allow read, write: if true".Quick checklist
- [ ] No
if trueorrequest.time < timestamp.date(...)rules in Firestore, Storage or Realtime Database - [ ] No rule that lets any logged-in user reach all data
- [ ] Private documents check the owner's user ID
- [ ] Users can't edit
role,plan,creditsor payment fields - [ ] Rules Playground: signed-out and "user B" tests are denied
- [ ] Queries filter by the same owner field the rules check
- [ ] No service account key in your frontend or repo
- [ ] Your Firebase API key only allows Firebase APIs (no Gemini)
Related guides
- Can One User See Another User's Data? How to Test Your Lovable, Bolt, v0 or Cursor App
- How to Protect Admin Routes and Roles in a Lovable, Bolt or Cursor App
- How to Check if Your Vibe-Coded App Is Leaking API Keys
- How to Stop Fake "Paid" Users: Verify Stripe Webhooks in a Lovable, Bolt or Cursor App
Sources
- Firebase docs, Avoid insecure rules: https://firebase.google.com/docs/rules/insecure-rules
- Firebase docs, Get started with Cloud Firestore Security Rules: https://firebase.google.com/docs/firestore/security/get-started
- Firebase docs, Get started with Cloud Firestore (test mode vs production mode): https://firebase.google.com/docs/firestore/quickstart
- Firebase docs, Control access to specific fields: https://firebase.google.com/docs/firestore/security/rules-fields
- Firebase docs, Securely query data (rules are not filters): https://firebase.google.com/docs/firestore/security/rules-query
- Firebase docs, Learn about using and managing API keys for Firebase: https://firebase.google.com/docs/projects/api-keys
- Firebase CLI (firebase-tools), default Firestore rules template: https://github.com/firebase/firebase-tools/blob/main/templates/init/firestore/firestore.rules
Want a check on the public side of your app? VibeVigil looks for exposed keys, open Supabase tables, headers, SSL and uptime, and gives you a fix prompt for each issue. Run a free scan → (only scan apps you own)
Scan your app free. It checks the public page of a site you own. No account.