# What does 'Missing or insufficient permissions' mean?

**Short answer:** Cloud Firestore Security Rules denied the read or write (error code `permission-denied`). Fix the rule for that path so the signed-in owner is allowed. Don't reopen the database with test-mode rules like `allow read, write: if true`.

*Last updated 2026-11-25 · Reviewed by ProofForge*

## The exact error

```text
FirebaseError: Missing or insufficient permissions.
(code: "permission-denied")
```

## Why it happens

- Test-mode rules expired (they're time-limited), so every request is now denied.
- The request runs before Firebase Auth has signed the user in, so `request.auth` is null.
- The rule checks a field (such as `uid`) the document doesn't have, or the query asks for documents the rule can't prove are allowed.

## How to fix it

1. Wait for `onAuthStateChanged` before querying.
2. Write rules that match your data model, scoped to the owner:
3. Make queries match the rule (for example filter by `where('uid', '==', user.uid)`).

```js
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/{document=**} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}
```

## Check it's fixed

Use the Rules Playground in the Firebase console: allowed as the owner, denied as another user and as unauthenticated.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## FAQ

### Can I switch back to test mode?
Test mode lets anyone read and overwrite your data. Firebase's docs list it as an insecure rule to avoid in production.

### Why does the query fail even though each document is mine?
Rules aren't filters. The query must include constraints that guarantee every result passes the rule.

### Does the Admin SDK hit this error?
No. The Admin SDK bypasses Security Rules, which is why its credentials must stay on a server.

## Sources

- [Firebase: Get started with Cloud Firestore Security Rules](https://firebase.google.com/docs/firestore/security/get-started)
- [Firebase: Avoid insecure rules](https://firebase.google.com/docs/rules/insecure-rules)

## Related

- [Fix: open Firebase rules](/fix/firebase-open-rules)
- [Firebase rules checker](/tools/firebase-rules-checker)
- [Security check for Firebase Studio apps](/check/firebase-studio)
- [Firebase Admin (service account) key leaked: first 10 minutes](/leaked-keys/firebase-admin)
- [All errors](/errors)
