【发布时间】:2016-05-23 16:08:16
【问题描述】:
我在 Firebase 中有一个名为“pending_members”的字段,其中包含等待“所有者”授予权限的成员列表,因此,“pending_members”需要以下规则:
- 当前用户只能添加自己(uid)
- 当前用户只能从列表中删除自己 (uid)
- “所有者”可以从列表中删除任何成员
- 只有“所有者”才能读取列表
我尝试了各种安全规则,但似乎遗漏了许多极端情况,例如,用户被授予写入权限,因为数据包含他们的 uid,但随后他们可以提交其他人的 uid。
任何人都可以针对这种情况提出适当的规则吗?非常感谢
"pending_members" : {
".write" : "auth !== null &&
// The user is authenticated AND
(newData.child(auth.uid).exists() ||
// The new data contains either the current user's id OR
(!newData.exists() &&
// There's no new data (a delete operation) AND
data === auth.uid))",
// The old data is the current user's id
"$member" : {
".validate" : "newData.isString()",
"$other": { ".write": false, ".read": false }
}
}
编辑: 结构示例:
users ->
personal_data ->
email (user email address)
first_name (user first name)
last_name (user last name)
networks_index ->
networks ->
members (list of uids of users linked to the network)
owner (uid of the owner/primary user)
pending_members (list of uids of users wishing to link to the network)
【问题讨论】:
-
你能添加一个你的firebase结构的例子吗?
-
@AndréKool 按要求添加。
标签: firebase firebase-security