Firestore security rules are a short program that runs on Google's servers and allows or denies every read and write from your app. Start by denying everything, then allow only what a signed-in user needs, such as their own documents. Your Flutter code cannot override a rule that says no.
This guide is for Flutter developers who have a working Firestore app and want it safe. The rule examples come from Firebase's documentation as of October 2026. The running example is a bakery where each customer sees only their own notes and orders.
In short:
- The Firebase config inside your app is an identifier, not a password.
- Rules do not filter results. A query that could return forbidden documents fails.
request.resource.datalets you check what a write will produce.- The Admin SDK on a server bypasses rules entirely.
Open rules put the database on the internet
When you deploy, the app is public. The insecure rules guide warns that you might think you are the only user, but the app is available to everyone.
allow read, write: if true lets anyone overwrite your database. request.auth != null is better but still lets any account touch everything. Both are valid yet not recommended for production, says the getting started page.
Rules are match blocks with allow lines
A match picks documents by path. An allow line states the condition:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/notes/{noteId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
match /{document=**} {
allow read, write: if false;
}
}
}
{userId} is a wildcard whose value you can use in the condition. The last block denies anything unmatched.
A subcollection needs its own match, because a parent's rule does not cover it. request.auth is null for signed-out users, so check it first.
Rules are not filters
The rules and queries page explains that Firestore checks a query against its possible results. If it could include a document the user may not read, the whole request fails, even when they own every document that exists. So this fails under an author-only rule:
db.collection('stories').get(); // fails
db.collection('stories')
.where('author_uid', isEqualTo: uid).get(); // allowed
Add the same constraint your rule demands. Fetching one document by id is different: rules see the real document.
Check the data being written
resource.data is the stored document and request.resource.data is the result after the write. The docs' example rejects a city update that sets a non-positive population or changes the name.
For bakery orders you could require customerId == request.auth.uid on create, and forbid changing totalCents later. get() and exists() read other documents, such as a user's role, and each one is billed as a read.
Test before you ship
The Rules Playground in the console simulates a request for a path, operation and user, as the simulator guide shows. The emulator and unit tests let you automate it. Test four cases: signed-out read denied, user A reading user B denied, user A writing B's path denied, and a malformed write denied.
Rules protect clients, not servers
The insecure-rules page notes that server client libraries (the Admin SDK) bypass rules and use IAM instead. Put trusted work such as pricing or credits in server code. Add App Check as a second lock so only your genuine app calls Firebase.
Generated apps start open, so keep data public-safe
Apps built with GrowApps share one managed Firebase project, with each app's data under its own path prefix. Apps are no-auth by default, so that data area is not tied to signed-in users. The builder is told to treat it as shared: validate inputs, cap sizes, keep secrets out.
Use a generated app for content that can be public or low-stakes. For private data, export the code, create your own Firebase project and apply rules like these. More at growapps.ai.
Run four rule checks in the playground
Paste the notes rule above into the Rules tab, open the Playground, and try the first three test cases; the fourth requires data-validation conditions that this example does not include. If any is allowed that should not be, fix the rule before shipping. Next, learn how sign-in feeds these rules in Firebase Auth for Flutter.