high · M3 · MASVS-AUTH-1 · PTKD-BACKEND-FIREBASE-EMAIL-UNVERIFIED

    Firebase rules trust an email address nobody verified

    A Firebase security rule lets a user in because of their email address (an admin address or your company's domain) but does not check that the address was verified. With email and password sign-up anyone can create an account with that address and pass the rule straight away, without access to the mailbox.

    How it is exploited

    The rule is `allow write: if request.auth.token.email.matches('.*@acme[.]com$');`. Someone opens the app's sign-up screen (or calls createUserWithEmailAndPassword with the config from the app) as boss@acme.com, never opens the confirmation mail, and can write every document the rule covers.

    Why it matters

    Anyone can pass rules meant for your staff or admins: read or change their data, or act as an admin.

    How to fix it

    1. Search your rules for `auth.token.email`.
    2. Add `&& request.auth.token.email_verified == true` to each of those conditions.
    3. For admin rights use a custom claim set from a Cloud Function (`admin.auth().setCustomUserClaims(uid, { admin: true })`) and check `request.auth.token.admin == true`.

    firestore.rules

    function isStaff() {
      return request.auth != null
        && request.auth.token.email_verified == true
        && request.auth.token.email.matches('.*@acme[.]com$');
    }

    Does your app have this?

    PTKD checks your build or your source project for PTKD-BACKEND-FIREBASE-EMAIL-UNVERIFIED and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M3)