Skip to content
ShipCheck
Guides

Firebase security rules for a Lovable or Vite app: fix allow read, write: if true

Updated 1 December 2026

If your Lovable, Bolt, v0 or Vite app uses Firebase, the web config in the frontend — including the apiKey that starts with AIza, the project ID and the database or Storage URLs — is public by design. That key only identifies your project. It does not decide who can read or write your data. Firebase Security Rules do that. The usual failure on a vibe-coded app is leaving Test mode rules in place, or publishing allow read, write: if true, so anyone who can reach the project can steal, change or delete the data.

Check your own app for this, free.

Paste your live URL. ShipCheck looks for leaked API keys in your page and JavaScript, exposed files like /.env and /.git, missing security headers, SSL certificate problems, domain expiry (custom domains only) and what Google sees without running JavaScript. You'll see your score without signing up.

See an example report

Short answer

Do not hide the Firebase web config. Fix the rules. In the Firebase console, open Firestore, Realtime Database and Storage, and open the Rules tab for each one you use. If you see allow read, write: if true (or Realtime Database ".read": true / ".write": true), or Test mode rules that still allow anyone access, replace them before you treat the app as launched. A solid default is that a signed-in user can only read and write their own documents, using request.auth.uid (or auth.uid in Realtime Database). Then test an unauthenticated request and a second user in the Rules Playground. Firebase's docs say API keys for Firebase services are safe to include in your code, and that Security Rules and App Check — not secrecy of the key — protect the data. See API keys for Firebase. For the Supabase version of this problem, see how to check Row Level Security. If you are unsure whether a string in the bundle is a secret, type only its first few characters into the is this key safe? tool (nothing leaves your browser).

The web config is public; the rules are the lock

Firebase also says the content of the Firebase config object is considered public, including the API key, project ID, Realtime Database URL and Cloud Storage bucket name (Understand Firebase projects). Authorization is handled by Google Cloud IAM (for server/admin access), Security Rules (for which end users can access data) and App Check (for which apps can call covered APIs). Restrict the key to Firebase APIs in Google Cloud, and use a separate, tightly restricted key if the app also calls Maps or the Gemini Developer API. A Gemini Developer API key must not be in frontend code at all.

Hiding or renaming the AIza key does not protect Firestore, the Realtime Database or Storage. The browser has to send the config in order to use Firebase.

Test mode and open rules

When you create Firestore, Realtime Database or Storage in the console, you choose a starting mode. Locked or production mode denies client access by default. Test mode is for getting started and allows anyone to read and overwrite your data. If you have deployed the app, it is on the internet, even if you have not “launched” yet.

Firebase's Firestore docs warn you never to use this rule set in production, because it lets anyone overwrite the entire database (Fix insecure rules):

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

On Realtime Database, official docs say that if you create the database in Test mode and leave the default world-readable, world-writeable rules unchanged for a trial period, Firebase emails you and then changes the rules so they deny all requests. Note the expiry date shown in the console when you create the database (Realtime Database setup). Do not rely on that expiry: until it happens, and any time you later publish open rules with no time limit, the data is open.

Another common hole is “any signed-in user can read and write everything” (allow read, write: if request.auth != null). Firebase marks that as not recommended for a whole database: any account, including one an attacker just created, would have access. Narrow it to the owner, or to a role, instead.

Lock the rules down with the signed-in user

A typical owner-only pattern, from Firebase's own examples, is that the document ID or an owner field must match the signed-in user's UID. Keep public only what is meant to be public.

Cloud Firestore (Writing conditions):

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, update, delete:
        if request.auth != null && request.auth.uid == userId;
      allow create: if request.auth != null;
    }
  }
}

Realtime Database (the variable is auth.uid, not request.auth.uid; Rules Playground examples):

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

Cloud Storage follows the Firestore-style syntax. Start from locked rules and grant only the paths you need, for example so a user can read and write under their own prefix, not the whole bucket. Official starting point for locked Storage rules is in Basic Security Rules.

Write the rule when you add a new collection or path, as you would a schema. Do not leave it as a pre-launch chore. Firebase's security checklist also recommends enabling App Check on every service that supports it, so calls have to come from your genuine app. App Check is a complement to rules, not a substitute.

How to test the rules

  1. Read the live rules in the Firebase console: Firestore, Realtime Database and Storage each have their own Rules tab. Check all three if the app uses them. Deployed rules are what matters, not only a local file you have not published.
  2. Use the Rules Playground in that same tab (Quickly validate Firebase Security Rules). Choose a read or a write, enter a real path, set Authentication to unauthenticated, and click Run. Then run the same path again as a specific user ID, and once more as a second user ID. You want: unauthenticated denied (unless the path is intentionally public), the owner allowed, and the second user denied on the first user's data.
  3. Repeat as a real client. Open the live app in a private window (logged out) and, if you can, in a second account. If either can see or change someone else's data, the rules are not doing the job yet.
  4. For automated checks, Firebase recommends the Local Emulator Suite, and adding those tests to CI, rather than relying on the Playground alone.

What ShipCheck checks (and what it doesn't)

The free scan fetches the raw HTML of your live URL and the same-origin JavaScript files linked from that HTML (and public source maps from those files, when they are available). It does not run JavaScript or click around the app. If those files contain a Firebase hostname (firebaseio.com, .firebaseapp.com or firebasestorage.app), it records an info finding that Firebase is in use, reminds you that the web config is public by design, and points you at the rules (including not leaving allow read, write: if true). It does not download or evaluate your rules, and it does not read or write Firestore, Realtime Database or Storage data, so a clean scan is not proof that the rules are tight. Use the Playground and the logged-out / second-user checks above.

If the scan finds a Google API key (AIza…) and it did not also detect Firebase, it flags that key as a low finding and asks you to restrict it to your domain and to the APIs you use. If Firebase was detected, it does not raise a separate AIza finding, because that key is expected in the web config. The key prefix checker will still identify an AIza prefix as a Google API key. For other frontend keys, see how to check for leaked API keys. If a Firebase Admin SDK credential or a server key ever appeared in the bundle or a public .env, treat it as a secret and rotate it; the order is in which keys to rotate, and in what order.

The scan does not probe Storage buckets, and it does not detect Next.js versions. The Supabase table-read test needs a free account that has verified it owns the app; the anonymous scan does not query tables, and it does not run an equivalent probe against Firebase. Paid plans re-scan weekly on Solo ($12/mo) or daily on Builder ($29/mo). Separately, paid plans also check once a day that the app URL returns a status below 400 (a 15 second timeout, with an email after two failed checks). That daily check is not a rules test.

FAQ

Is the Firebase apiKey (AIza…) in my Lovable or Vite app a leak?

No, not by itself. Firebase's docs say API keys for Firebase services are public by design and are safe to include in your code if they are restricted to Firebase APIs. They identify the project; they do not authorize access to data. Security Rules and App Check do that. A Gemini Developer API key is different and must not be in the frontend.

What is Firebase Test mode, and is it safe after the expiry date?

Test mode starts with rules that allow anyone to read and overwrite your data, so you can build quickly. On Realtime Database, if you leave those default open rules unchanged for a trial period, Firebase emails you and then denies all requests. Until that happens, and any time you publish allow read, write: if true with no time limit, the data is open. Do not wait for an expiry. Replace the rules with owner-based access and test them.

Is allow read, write: if request.auth != null enough?

Usually not for a whole database. That rule only checks that someone is signed in. Any new account could then read or change every document. Firebase's insecure-rules guide marks that pattern as not recommended. Prefer request.auth.uid (or auth.uid in Realtime Database) matching the owner of the document or path.

How do I test Firebase security rules?

In the Firebase console, open the Rules tab for Firestore, Realtime Database or Storage, then open Rules Playground. Run a read and a write as unauthenticated, as the owner, and as a second user. For automated coverage, use the Firebase Local Emulator Suite. Also try the live app logged out and in a second account.

Does ShipCheck test my Firebase security rules?

No. If the scan sees a Firebase hostname in your public HTML or JavaScript, it records an info finding and reminds you to check the rules. It does not download or evaluate the rules, and it does not read your Firebase data. If it finds an AIza key without detecting Firebase, it flags that key as low and asks you to restrict it. Use the Rules Playground and a logged-out test to verify the rules yourself.

Run the same checks on your app.

A free scan takes under a minute. No card, and no sign-up to see your score and the list of issues.

See an example report