Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Secure Firestore rules by starting with no client access, then allowing only the specific document paths and operations a feature needs. For each allowance, check who is requesting it and whether the relevant stored or incoming data meets your authorization and validation requirements. Test permitted and forbidden cases in the Local Emulator Suite before deployment.

Security Rules apply to requests made through Firestore mobile and web client libraries. They do not authorize server client-library access, so a client ruleset is not a complete access-control plan for your backend.

Start with no access, then add a feature’s minimum permissions

Firebase says the default rules for a Firestore instance created in the Firebase console deny access to all users. Treat that locked-down state as the baseline—not a temporary inconvenience to solve with a database-wide grant. Firebase’s Fix insecure rules guide explains why open rules expose data and shows how to replace them with conditions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Work from the feature’s data needs: identify the exact documents a client must read or write, the operation it performs, and the condition that makes that request legitimate. Then grant only that combination. A signed-in user is not automatically entitled to read or change every document.

Match document paths, not just collection names

A match statement identifies document paths; an allow expression authorizes specified operations on matching documents when its condition is true. For example, a match at /cities/{city} covers documents in that collection path. It does not automatically cover nested documents in /cities/{city}/landmarks/{landmark}. Add a separate match for a subcollection when clients need access to it.

Be cautious with recursive wildcards: they can cover more paths than a narrowly named match. Firebase documents version-sensitive wildcard behavior; in rules version 2, recursive wildcards match zero or more path items, and version 2 is required for collection group queries. Check the project’s declared rules version and the current rules structure documentation before relying on wildcard behavior.

Grant operations separately

Firestore rules can distinguish get, list, create, update, and delete. Use those distinctions to reflect what the product actually allows: a user might be allowed to fetch one known document but not enumerate a collection, or update a record but not delete it. A broad read or write grant can authorize more than intended.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review every matching rule for a path. When multiple match statements apply, their allow conditions combine permissively: if any matching condition evaluates to true, the request is allowed. A broad recursive rule can therefore reopen a path that a narrower rule appears to restrict. See Firebase’s guidance on rule structure and overlapping matches.

Authorize the user and the data state

For owner-only documents, connect the authenticated identity to the record’s intended owner. Depending on the data model, compare the authenticated UID with an owner ID in the document path or with an owner field in the stored document. Add role checks when access is role-based, and scope each check to the operation it protects.

For writes, authorization should account for both the current record and the proposed result. On an update, checking only the incoming owner field can let a user claim another owner’s record or transfer ownership through a write. Check that the requester is authorized for the existing document and constrain the incoming document so protected fields cannot be changed improperly.

Validate incoming data as well as identity: inspect the fields and values the application expects, and reject writes that violate those constraints. Firebase’s conditions documentation describes using authentication, document data, and pending post-write state in rule conditions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remember that queries must be safe for every possible result

Rules are not filters that remove unauthorized documents from a query result. Firestore evaluates whether a query could return a document the client is not allowed to read. If it could, the request fails rather than returning only the authorized subset. Shape queries around the same ownership or access constraints enforced by the rules, and test the actual query patterns your client uses. Firebase explains this behavior in its rules conditions guidance.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test allowed and denied cases in the emulator

Use the Local Emulator Suite to check your rules before deploying. Firebase provides a rules testing guide covering emulator setup and unit tests, including authenticated and unauthenticated test contexts.

  1. Confirm the rules are loaded. Make sure the emulator is using the rules file you intend to test. Firebase warns that if no rules file or loaded rules are provided, the emulator treats projects as open.
  2. Test expected access. Exercise each required path and operation as the intended owner or role, using the same query patterns the application will send.
  3. Test denials. Try the same actions without authentication, as a different signed-in user, and with operations that should remain forbidden, such as listing or deleting when those rights were not granted.
  4. Test invalid writes. Submit unexpected fields, disallowed values, and attempts to change protected ownership or role data.
  5. Run tests after rule changes. Keep positive and negative cases repeatable so a broader match or condition change does not silently reopen access.

Separate client rules from server-side access control

Firestore Security Rules evaluate requests from mobile and web client libraries. Server client libraries bypass those rules and use Google Application Default Credentials; REST and RPC access also require appropriate IAM configuration. Protect server and API access through IAM and the backend’s authorization design rather than assuming client rules cover it. Firebase outlines this boundary in Get started with Cloud Firestore Security Rules.

Deploy carefully and account for propagation

Firebase’s getting-started documentation says rule updates can take up to a minute to affect new queries and listeners, and up to 10 minutes to fully propagate to active listeners. Treat those timings as product guidance, not a guarantee that every deployment behaves identically. If a client continues to behave unexpectedly after a rule change, consider whether an active listener has received the update before concluding that the deployed rules are wrong. Consult the current deployment guidance for details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.