I'm developing a Firebase Realtime
database application. in the App, users don't want to Authenticate
.So, I make the rules as public
{
"rules": {
".read": true,
".write": true
}
}
(User no need to register/login).but in the Firebase Realtime
database section, it says as a Warning
Your security rules are defined as public, so anyone can steal, modify, or delete data in your database.
So, How can Secure the data without Authenticate(Login/Register) the user?
No Firebase Authentication… To use the Firebase Storage we need to authenticate a user via Firebase authentication. The default security rules require users to be authenticated. Firebase Storage is basically a powerful and simple object storage, in which you can store your files easily.
As of October 2020, any website using Google Firebase Auth with email and password login is vulnerable to this sort of attack.
If you want to secure data access without requiring the user to sign in with their credentials, consider using Firebase's anonymous authentication. With this provider, you can sign in a user with just this single line of code:
FirebaseAuth.getInstance().signInAnonymously();
After running this you won't know any details of the users yet. But you can now identify the user in any calls to the database, and then use the information in the security rules of your database, to ensure the user only has access to the data they're authorized for.
For an example of this, see the documentation on leveraging user information in security rules, which contains this example:
For example, your app may want to make sure users can only read and write their own data. In this scenario, you would want a match between the
auth.uid
variable and the user ID on the requested data:
{
"rules": {
"users": {
"$userId": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($userId)
".write": "$userId === auth.uid"
}
}
}
}
To learn more about that, I recommend reading the full documentation on securing data access.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With