I'm trying to find the best way to design security for our app that uses firebase
Basic problem
We want our users’ data to be secure. We don’t want a malicious agent to be able to access other users’ private data on the Firebase db. It seems that there should be a solution for this via firebaseSimpleLogin, but despite scouring the documentation, we haven’t seen one.
Problem specifics
- We offer an app with user accounts, and these users have private data
- Users should only be able to read:
- their own data
- app-wide data relevant to all users, e.g. a template that all users get a copy of when they initially create their account, the original copy of which is on the fb db
- a portion of data of another user, if that other user has explicitly decided to share it with them e.g. a game they made that they want another user to have a copy of
- Right now, users log in with FirebaseSimpleLogin. This is problematic because any malicious user can create their own account legitimately, and use their account’s e-mail and password to login with a malicious script, and access the db
Solutions we’ve considered
1. Store a user_secret to ensure user has legitimate access
- Inspired by 2nd method in answer to How to setup Firebase security rules to accept connections only from an iOS App
- The structure would look like security->user_secret->associated_user OR security->user->{all_valid_user_secrets}
- Security rule: ".read": "root.child('user_secrets/'+auth.uid).exists()"
- We could store multiple user secret keys per user, allowing access from multiple verified sources (iOS app, web-app, etc)
Problems with #1
- How do we restrict write/read access to the security child?
- SimpleLogin doesn’t exist for servers
- We don’t want this information visible, as a malicious user could technically read it to find info about his/her own account, and then use that to peruse the rest of the db
- Same problem as in the problem statement: a user can generate an account legitimately, and then use those credentials to gain malicious access to the db
2. Temporarily Store User Secret
- User initiates login
- Node server generates password, stores it in restricted security child in Firebase (the server would be able to do this, as Firebase Secret allows full access)
- We authorize firebase client side using Firebase SimpleLogin as we have been
- The user interacts with the app. Firebase security rules only allow read/write access if the security child written by the node server is present
- User initiates logout/crashes/closes app
- Node server removes password from restricted security child
- Unauthorize Firebase ref as we have been
- Done
Problem with #2 - The issue with this method is the user is vulnerable while they’re logged in, as their security information would be present.
3. Use built in Firebase Security Rules
- We hoped there was a built in firebase solution, but haven’t found one that solves the resolves the above problem. If you can point us to one that would be terrific.
We are hoping someone can help shed light on the best approach here, either using our ideas or another route. Thanks so much for your help.