Firebase¶
Scope: web apps, mobile apps and games whose clients read and write Firebase directly: Cloud Firestore, Realtime Database, Cloud Storage for Firebase, Firebase Authentication, App Check and Cloud Functions for Firebase (2nd gen), with the current SDKs and tools (Firebase JavaScript SDK 13, firebase-functions 7 and the Firebase CLI 15). Because clients reach the data without a server of your own in between, Firebase Security Rules carry the server-side authorisation that SEC-1 asks for, and everything in the client is public (SEC-11 in Security). Sign-in in general is covered in Authentication and sessions, consent and personal data in Privacy and personal data, browser apps in Web front end, and store purchases, integrity checks and live operations with Remote Config in Mobile games. A Firebase project is a Google Cloud project, so Google Cloud also applies to its IAM, secrets and billing. For a PostgreSQL-based backend of the same kind, see Supabase.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 9 Firebase security checklist: the baseline. Abusive traffic, API keys, Security Rules, Authentication, Cloud Functions, environments and libraries.
- 8 Firebase launch checklist: what to check before going to production: emulator testing, App Check, budget alerts and spend caps, project protection and access, and the settings of each product you use.
- 8 Firebase Security Rules: how rules protect Firestore, Realtime Database and Cloud Storage, the rules language, conditions, Authentication, and managing, deploying and testing rules.
- 8 Avoid insecure rules: the common insecure configurations, such as open access and access for any signed-in user, and how to fix them.
- 8 General best practices for setting up Firebase projects: how projects, apps and resources relate, which app variants share a project, and why to avoid putting unrelated apps in one project.
- 8 Best practices for Cloud Firestore: database location, document IDs, index exemptions, reads and writes, and designing for scale without hotspots.
- 7 Learn about and manage API keys for Firebase: why Firebase API keys aren't secret, how to restrict them, and when to use separate keys.
- 7 Firebase App Check: the attestation providers for each platform, the products App Check protects, request metrics and enforcement.
- 7 Understand Cloud Firestore billing: what counts as a read, write and delete, including listeners, offsets, aggregation queries and documents that Security Rules read.
- 7 Avoid surprise bills: testing locally, usage dashboards, alert-only budgets and spend cap budgets.
- 7 Introduction to Firebase Local Emulator Suite: local emulators for Firestore, Realtime Database, Cloud Storage, Authentication, Hosting and Cloud Functions, for development, testing and CI.
- 7 Cloud Functions tips and tricks: best practices for the correctness, performance and cold starts of functions.
Key rules¶
Security Rules¶
- 10
FIREBASE-1Start every Firestore database, Realtime Database and Storage bucket with rules that deny all access, and never deploy test-mode rules,allow read, write: if true, or rules that let any signed-in user (request.auth != null) reach all data. Clients access the data directly, so the rules are the only safeguard: grant access per collection or path, based onrequest.auth.uid, custom claims or the data itself. This appliesSEC-1. (Firebase security checklist, Initialize rules in production or locked mode, Avoid insecure rules, Basic Security Rules, Development-environment rules) - 8
FIREBASE-2Write the rules for each new collection or path together with the code that uses it, keep the rules and index definitions (firestore.rules,storage.rulesandfirestore.indexes.json) in the repository, and deploy them with the Firebase CLI instead of editing them in the console. Firebase advises treating rules like a database schema, and a CLI deploy overwrites rules that were changed in the console. This appliesOPS-14. (Firebase security checklist, Security rules are a schema, Manage and deploy Firebase Security Rules, Manage indexes: use the Firebase CLI) - 8
FIREBASE-4Validate every client write in the rules: allow only known fields withrequest.resource.data.keys().hasOnly(), check their types, and usediff().affectedKeys()to stop clients from changing fields such as an owner ID, a role or a balance. When clients write directly, the rules are the server-side input validation thatSEC-10asks for. (Firestore, Control access to specific fields, Writing conditions: data validation) - 7
FIREBASE-3Unit-test the rules with@firebase/rules-unit-testingagainst the emulators, asserting withassertSucceedsandassertFailsthat allowed requests succeed and forbidden ones fail, and run the tests in CI withfirebase emulators:exec. (Firebase security checklist, Unit test security rules with the Local Emulator Suite, Build unit tests, Integrate with your CI system) - 7
FIREBASE-5Keep fields that not every reader may see in a separate document, such as a private subcollection with its own rules, because rules allow or deny reads of whole documents. Rules are also not filters: a query fails unless its constraints guarantee that the user may read every document it could return. (Firestore, Allowing read access only for specific fields, Securely query data: rules are not filters) - 7
FIREBASE-6If you use anonymous authentication, protect all non-public data with rules that require a permanent sign-in provider or a verified email address, because anyone can create an anonymous account. Use anonymous accounts only to keep a user's state until they sign in. (Firebase security checklist, Anonymous authentication)
App Check, API keys and Authentication¶
- 8
FIREBASE-8Treat Firebase API keys and Remote Config values as public: restrict each API key to the APIs it needs, use a separate restricted key for any API that isn't a Firebase service, and never put a Gemini Developer API key, a service account key or another server credential in a client. Firebase API keys only identify the project, and users can read every Remote Config parameter their app receives. This appliesSEC-11. (Learn about and manage API keys for Firebase, Use separate, restricted API keys for any non-Firebase service, Firebase security checklist, Keep service account keys secret, Remote Config, Policies and limits) - 7
FIREBASE-7Enforce App Check for every product that supports it, such as Firestore, Realtime Database, Cloud Storage, Authentication and callable functions, once its request metrics show that your current app versions send valid tokens. App Check checks that requests come from your app on a genuine device; it complements Authentication and Security Rules and doesn't replace them. For server-side integrity checks in mobile games, seeMOBGAME-11. (Firebase launch checklist, App Check, Monitor App Check request metrics, Enable App Check enforcement, App Check and Firebase Authentication) - 7
FIREBASE-9Harden Firebase Authentication before launch: disable the sign-in providers you don't use, enable email enumeration protection, tighten the quota of the sign-in endpoints, and allow only your own domains. These settings limit account guessing and brute-force attempts (AUTH-14). (Firebase security checklist, Authentication, Firebase launch checklist, Authentication)
Projects and environments¶
- 8
FIREBASE-10Use a separate Firebase project for each environment, such as development, staging and production, register debug and release builds in different projects, and don't put unrelated apps in one project. All apps in a project share its databases, buckets, functions and Analytics property. Develop and test on the emulators with ademo-project ID, so that code can't reach live resources by mistake. This appliesSEC-16. (Firebase security checklist, Set up development and staging projects, Registering app variants with Firebase projects, Avoiding multi-tenancy, Local Emulator Suite, Choose a Firebase project)
Firestore data and cost¶
- 7
FIREBASE-11Model Firestore data around the queries your screens run and what they cost: each document a query returns, each document a listener receives when it's added or changed, and each document a rule reads withget()orexists()is billed as a read. Page withlimit()and cursors rather than offsets, which bill the skipped documents; use aggregation queries such ascount(), or keep aggregates up to date at write time, instead of reading whole collections; and put lists that keep growing in subcollections, because a document can't exceed 1 MiB. (Understand Cloud Firestore billing: listening to query results, Managing large result sets, Cloud Firestore Security Rules, Write-time aggregations, Choose a data structure, Usage and limits) - 7
FIREBASE-12Turn on point-in-time recovery and scheduled backups for production Firestore databases. Without PITR, you can read past versions of your data only from the last hour; with it, from the last seven days. Scheduled daily or weekly backups need the Blaze plan and are kept for the retention period you set. This is how Firestore followsDATA-8. (Firestore, Point-in-time recovery: PITR window, Back up and restore data)
Cloud Functions¶
- 7
FIREBASE-13Give Cloud Functions their credentials through Secret Manager, withdefineSecret()bound only to the functions that need each secret, not through.envfiles orfunctions.config().functions.config()is deprecated, and deployments that still use it fail after March 2027. This is how functions followSEC-2andGCP-8. (Configure your environment: store and access sensitive configuration, Secret parameters, Migrate from runtime configuration) - 7
FIREBASE-14Make event-triggered functions idempotent, for example by using the event ID as an idempotency key, turn on retries only for transient errors, and test on the emulators that a function's writes can't trigger it again in a loop. Event-driven functions run at least once for each event. This appliesDATA-9. (Retry asynchronous functions: best practices, Tips and tricks: write idempotent functions, Firebase security checklist, Prevent self-DOSes)
Costs¶
- 7
FIREBASE-15Set budget alerts on every project on the pay-as-you-go Blaze plan, add spend caps for the services that support them, such as Cloud Functions, and limit each function's maximum number of instances to what normal traffic needs. Budget alerts only notify you; they don't stop spending, and functions scale out automatically during an attack. This is how Firebase projects followOPS-17andGCP-13. (Firebase launch checklist, Know your pricing plan limits and set budget alerts, Avoid surprise bills: set up budgets, Firebase security checklist, Configure your Cloud Functions to scale for normal traffic, Manage functions: limit the maximum number of instances)
Privacy¶
- 7
FIREBASE-16Where users must consent to analytics or crash reporting, set the Google Analytics consent defaults in the app's configuration, update them withsetConsent()when the user decides, and turn on Crashlytics opt-in reporting. By default, no consent values are set and Crashlytics collects crash reports from every user. This is how Firebase apps followPRIV-5andPRIV-6. (Google, Set up consent mode for apps, Configure Analytics data collection and usage, Customize your Crashlytics crash reports: enable opt-in reporting)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 Security Rules unit tests:
@firebase/rules-unit-testingruns your tests against the emulators, andfirebase emulators:execstarts the emulators for them in CI and stops them afterwards. ChecksFIREBASE-3, and partlyFIREBASE-1,FIREBASE-4,FIREBASE-5andFIREBASE-6, as far as the tests cover them. - 6 GitHub secret scanning push protection: blocks pushes that contain Google Cloud service account credentials. Partly checks
FIREBASE-8. - 5 @firebase/eslint-plugin-security-rules: Firebase's ESLint plugin for
.rulesfiles, first released in 2026. Itsno-open-readsandno-open-writesrules flag reads and writes allowed withif true. Partly checksFIREBASE-1.
Tutorials and further reading¶
- 7 Protect your Firestore data with Firebase Security Rules (Firebase codelab): granular permissions, data and type validation, attribute-based access, access by sign-in method, and when to denormalize data, tested on the emulators.
- 6 Local Development with the Firebase Emulator Suite (Firebase codelab): running an app against the emulators, writing Security Rules, and unit-testing them with the emulators.
- 6 App Check Web Codelab (Firebase codelab): monitoring a backend for unauthorised access, enforcing App Check for Firestore and Cloud Storage, and using debug tokens for local development.