Cloud Firestore:根据身份验证设置安全规则
Cloud Firestore: setting security rule based on authentication
我想了解基于身份验证的安全规则有多安全,如下所示:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
我有一些集合,其中每个文档都与特定用户相关。
我只在 Android 和 iOS 移动设备上使用 Cloud Firestore,而不是在 Web 上使用。
用户是否可以通过任何方式在我的移动应用程序之外进行身份验证,从而读取或写入其他用户的文档?
如果你想确保用户无法阅读彼此的信息,你应该实施比auth != null
更强大的规则。
例如,这些规则规定,如果您的身份验证为 userId
。
,则您只能在 /users/userId
读取和写入数据
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
// Anybody can write to their ouser doc
allow read, write: if request.auth.uid == userId;
}
}
}
这将使某人无法像您提到的那样"get authenticated outside my mobile apps, and hence going to read or write some other user's documents"。
我想了解基于身份验证的安全规则有多安全,如下所示:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
我有一些集合,其中每个文档都与特定用户相关。
我只在 Android 和 iOS 移动设备上使用 Cloud Firestore,而不是在 Web 上使用。
用户是否可以通过任何方式在我的移动应用程序之外进行身份验证,从而读取或写入其他用户的文档?
如果你想确保用户无法阅读彼此的信息,你应该实施比auth != null
更强大的规则。
例如,这些规则规定,如果您的身份验证为 userId
。
/users/userId
读取和写入数据
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
// Anybody can write to their ouser doc
allow read, write: if request.auth.uid == userId;
}
}
}
这将使某人无法像您提到的那样"get authenticated outside my mobile apps, and hence going to read or write some other user's documents"。