Skip to content

Firebase user can take over another user's document

Scan rule · RSC-SEC-134

  • Security
  • Severity: High
  • CWE-639
  • OWASP A01-2021

Finds an `update`/`write` rule that checks ownership only on the INCOMING document (`request.resource.data.ownerId == request.auth.uid`), without checking the existing owner or pinning the field — any signed-in user can make themselves the owner of someone else's document.

Why this matters

`allow update: if request.resource.data.uid == request.auth.uid` looks like owner binding, but it checks the value the writer supplies themselves. The question “am I the new owner?” is always yes — the rule protects nothing.

For `create` this exact form is correct (you create your own document). For `update` it is a takeover: a signed-in user writes to someone else's document, sets `ownerId`/`uid` to themselves and satisfies the condition. Any foreign record can be hijacked — seen in the field on a combined `allow create, update` rule.

Fix: in the `update` rule check the EXISTING owner (`resource.data.ownerId == request.auth.uid`) and pin the field to its previous value. Separate `create` and `update`, because they need different checks.

Scan tier

  • Repo access (deep scan)

How to fix it

Check the existing owner (`resource.data.ownerId == request.auth.uid`) and pin the owner field to its previous value (`request.resource.data.ownerId == resource.data.ownerId`).

Scan your own app for free