Security

Firebase security rules that actually protect your data

Most Firebase breaches are not clever attacks — they are default-open rules and trust placed in client-side checks. A short, practical hardening pass.

CodePOV Technology7 min read

Firebase makes it easy to ship an app in a weekend, and just as easy to leave the database readable by the whole internet. Nearly every exposed Firebase project we have audited failed for one of five reasons. None of them required an attacker to do anything sophisticated.

1. Test-mode rules that outlived the test

Starting in test mode gives everyone read and write access for 30 days. The deadline passes, nothing breaks loudly, and the project goes to production with the rules still wide open. Treat the expiry date as a release blocker, not a reminder.

2. Trusting the client to say who it is

A rule that checks a field the client itself sends — a role name in the request body, a user ID in a query parameter — protects nothing, because the client can send anything. Authorisation has to be derived from the verified authentication token or from data the client cannot write.

3. Rules that check the shape of a write but not its owner

request.resource.data.keys().hasAll([...]) tells you the write is well-formed. It does not tell you the person writing it is allowed to. Validation and authorisation are two separate conditions, and both belong in the rule.

4. Reading more than the screen needs

If the whole collection is readable because one screen needs five documents, a single query exports your customer list. Scope reads to the document the user owns, or move the aggregate behind a server function that returns only what the screen renders.

5. Storage left out of the review

Database rules get attention; Storage rules often do not. Uploaded resumes, invoices and identity documents end up on a public download URL. Storage needs the same ownership checks, plus a content-type and size limit, because "image" in the file name means nothing.

The pattern we deploy

For products where the client only ever talks to our own API, the simplest rule is also the strongest: deny every client read and write, and let the server — which holds a service account and verifies the caller's token — be the only thing that touches the database. The client gets data through endpoints that check the caller's role on every request. Where the client does talk to Firebase directly, each rule answers three questions in order: is this request authenticated, does this user own this path, and is the payload valid?

How to check your own project today

  • Open the Rules tab and read them out loud. If a rule does not mention request.auth, ask why.
  • Try to read a document while signed out, from the browser console. Do the same for Storage.
  • Grep the client bundle for secrets: service account keys, SMTP passwords and API secrets belong on the server only.
  • Turn off self-service sign-up if only staff should have accounts.
  • Log administrative actions, so you can tell what changed when something looks wrong.

Rules are code. They deserve a review, a test and a deployment step like the rest of the product. If you want a second pair of eyes on yours, that is one of the things our cybersecurity service does.

  • Firebase
  • Security
  • Cloud