# Firebase says your security rules are insecure: how to fix test mode rules

Canonical: https://caelo.sh/guides/firebase-insecure-rules-alert-fix
Published: 2026-11-27 · Updated: 2026-11-27 · Arthi Arumugam, Caelo by Irth Labs

**Short answer:** The alert means your Firestore or Storage rules let anyone read or write without a real check, usually the test mode rule from when you created the database, or `allow read, write: if true`. Replace it with rules that check `request.auth` and who owns each document, test them in the Rules Playground or the emulator, then publish.

## What triggered the alert?

Firebase's "Fix insecure rules" page starts: "If you receive an alert that your Cloud Firestore database isn't properly secured, you can resolve the vulnerabilities by modifying and testing your Cloud Firestore Security Rules." Firebase describes test mode as good for getting started, "but allows anyone to read and overwrite your data."

Developers also report emails titled "Client access to your Cloud Firestore database expiring in 4 day(s)". That one is about test mode's date: when the date passes, browser and mobile clients lose access and your app stops working.

Vulnerable: test mode, open to everyone until a date

```js
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2026, 12, 20);
    }
  }
}
```

`match /{document=**}` covers every document in the database. Until that date, anyone with your public Firebase config can read, change or delete all of it.

## Why not just push the date forward?

Changing the date silences the email and keeps the app working, but it also keeps the whole database open. Changing it to `if true` removes the expiry and makes it permanent. Both are the leak the alert is warning you about. The fix is a rule per collection that names who may do what.

## Rules to use instead

Fixed: users own their own documents, posts are public to read

```js
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
    match /posts/{postId} {
      allow read: if true; // public content, on purpose
      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;
    }
  }
}
```

There is no `match /{document=**}` any more, so any collection you have not written a rule for is denied. Keep fields such as role, plan or credits out of reach of the client entirely and change them only from a server, as our Firebase rules guide explains.

## Fix it, step by step

1. Open Firestore Database > Rules in the Firebase console, and do the same for Storage and Realtime Database if you use them.
2. Write down every collection your app reads or writes, and who should be allowed to do each.
3. Replace the test mode block with one `match` per collection, as above.
4. Test in the Rules Playground: Firebase says it "displays a message confirming that access was either allowed or denied." Try a read of another user's document while signed out and while signed in as a second user. Both should be denied.
5. For anything more than a few rules, use the Firebase Emulator to run automated rule tests, as Firebase recommends.
6. Publish, then use the app normally to make sure nothing you need is now denied.
7. Consider App Check, which Firebase says helps protect your backends "by preventing unauthorized clients from accessing your backend resources." It is an extra layer, not a replacement for rules.

## Check it automatically

Caelo reads `firestore.rules`, `storage.rules` and `database.rules.json` in your project and flags rules with no condition: `allow read, write: if true`, a bare `allow write;`, and `".write": true` in Realtime Database (`firebase.open-rule`). Open writes are critical. It does not flag the test mode date rule, and it cannot see rules that exist only in the Firebase console, so open the console's Rules tab as well.

Caelo output for an open Firestore rule

```text
- Firebase rule lets anyone write
    firestore.rules:7  (firebase.open-rule)
    value: allow read, write: if true
    why: There is no condition, so any visitor can write this data without signing in.
```

- [Install Caelo: npx caelo . or the MCP server](/)
- [How Caelo compares with gitleaks, TruffleHog, Semgrep and others](/compare)

## Check your own app

1. Run the free local check: `npx caelo .` Caelo is a free, open source (MIT) command line tool and MCP server from Irth Labs that checks the files of an AI-built app for exposed API keys, Supabase and Firebase misconfigurations and `.env` files with real values. It runs on your machine, uploads nothing and uses no AI model. Each finding comes with a plain-English fix.
2. Follow the fix in the report and rerun Caelo. For an untracked, unignored file containing secrets, preview the US$19 quick fix. https://caelo.sh/fix
3. For an engineer's assessment, book the US$490 App Health Check. Irth Labs delivers a report and fixed repair quote, with credit toward the repair. https://www.irthlabs.com/start?service=app-health-check

## Questions

### What happens when test mode expires?

The rule's condition becomes false, so clients are denied and your app's reads and writes fail. Server code using the Admin SDK is not affected by security rules.

### Is the Firebase apiKey in my app the problem?

No. Firebase web config is public by design and only identifies your project. Your security rules decide what that config can reach.

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

Only for data every signed-in user may see and change. It lets anyone who creates an account read and overwrite everyone else's documents. Check ownership too.

### Do I need to fix Storage rules as well?

Yes, if you use Cloud Storage. Storage has its own rules with the same test mode pattern, and an open Storage rule lets anyone read or overwrite uploaded files.

## Sources

- [Firebase docs: Fix insecure rules (Cloud Firestore).](https://firebase.google.com/docs/firestore/security/insecure-rules)
- [Firebase docs: Avoid insecure rules.](https://firebase.google.com/docs/rules/insecure-rules)
- [Firebase docs: Cloud Firestore quickstart (test mode and production mode).](https://firebase.google.com/docs/firestore/quickstart)
- [Firebase docs: Rules Playground.](https://firebase.google.com/docs/rules/simulator)
- [Firebase docs: App Check.](https://firebase.google.com/docs/app-check)
- [Apple Developer Forums: email "Client access to your Cloud Firestore database expiring in 4 day(s)".](https://developer.apple.com/forums/thread/750809)
- [Caelo source: every rule in lib/rules.js.](https://github.com/arthi-arumugam-git/caelo/blob/master/lib/rules.js)

## Related guides

- [How to check your Firebase security rules are not open (test mode)](https://caelo.sh/guides/firebase-security-rules-check)
- [Security checklist for apps built with Lovable, Bolt, Cursor, Replit or v0](https://caelo.sh/guides/vibe-coded-app-security-checklist)
- [AI app builder security defaults, compared from their own docs (Nov 2026)](https://caelo.sh/guides/ai-app-builder-security-defaults-compared)
- [I leaked an API key or the Supabase service_role key. What do I do now?](https://caelo.sh/guides/leaked-api-key-what-to-do)
