Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How safe is auth !== null? Firebase

I've been using Firebase for quite some time, but I only now decided to really look into the security rules.

My question is, how safe is "auth !== null"? Yes, I realize that this means that only an authenticated user can access the data, but how easy is it to become authenticated? Can someone sign up for the app, and then use those credentials to GET request right into my database?

Like I said, I'm new to Security rules, so I'm sorry if this is an obvious question.

Here's my security rules:

{
  "rules": {
    "Users": {
      "$user_id": {
        ".write": "$user_id === auth.uid",  
        ".read" : "auth !== null",
        "shoofers" : {
          ".write" : "auth != null"
        }
      }
    }
  }
}

Thanks!

Neil

like image 864
Neil Shweky Avatar asked Jul 19 '17 15:07

Neil Shweky


2 Answers

A user can authenticate via anonymous, email/password, various OAuth providers and phone number sign in. You can enable/disable either of them. Your root rule above allows read only access to any authenticated user via any of the mechanisms stated and write access for a specified user to their own data. It is very difficult to fake sign in. The database will always check that the request has an ID token (when auth is not null). ID tokens use public-key cryptography and are hard to fake without possession of the private key.

like image 84
bojeil Avatar answered Oct 16 '22 20:10

bojeil


You can give users access to the database either after sign in authentication or with out authentication. But it is good and safe to allow users to access your database with authentication

with authentication security rules are

  {
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

and without authentication

     {
  "rules": {
    ".read": "auth == null",
    ".write": "auth == null"
  }
}
like image 12
Wahdat Jan Avatar answered Oct 16 '22 22:10

Wahdat Jan