GVKun编程网logo

邮件阵列的Firebase安全规则(邮件列表)

3

这篇文章主要围绕邮件阵列的Firebase安全规则和邮件列表展开,旨在为您提供一份详细的参考资料。我们将全面介绍邮件阵列的Firebase安全规则的优缺点,解答邮件列表的相关问题,同时也会为您带来an

这篇文章主要围绕邮件阵列的Firebase安全规则邮件列表展开,旨在为您提供一份详细的参考资料。我们将全面介绍邮件阵列的Firebase安全规则的优缺点,解答邮件列表的相关问题,同时也会为您带来angularjs – 需要检查数组中值的Firebase规则(安全规则中的contains())、Firebase Firestore 安全规则似乎根本没有应用、Firebase Flutter:Cloud Firestore 数据库有不安全的规则、firebase – 用于在用户之间共享文档的Firestore数据库规则和结构的实用方法。

本文目录一览:

邮件阵列的Firebase安全规则(邮件列表)

邮件阵列的Firebase安全规则(邮件列表)

我试图显示基于收件人的邮件列表,但现在让我们保持简单。我只是想显示消息列表。

我的规则看起来像这样

{"rules": {  "communications" : {    "$communication":{      ".read" : true,      ".write": true    }  }}

但是由于某种原因,我的应用程序不想读取它

fireRef = new Firebase(url);fireRef.auth(MY_TOKEN);commsRef = fireRef.child(''communications'')$scope.communications = $firebase(commsRef)

只有在我有一条规则看起来像

{"rules": {  "communications" : {    ".read" : true,    ".write": true  }}

但这会引起问题,因为我想在通讯的子节点上添加条件。就像是:

{"rules": {  "communications" : {    ".read" : true, ### I would like to get rid of this line as well and have the child handling it    ".write": true,    "$communication":{      ".read" : "data.child(''to'').val() == auth.uid"    }  }}

我假设这是因为我在通讯上有一个$ firebase,它需要一些读或写规则,但是添加新消息后如何获取事件?

谢谢

答案1

小编典典

关于安全规则,Firebase操作是全有或全无。

这意味着发送到客户端的数据列表将永远不会是不完整的,也不是完整服务器数据的 过滤
视图。因此/communications,即使您确实有权按照子规则在读取其中的某些数据,使用第一组安全规则尝试在处加载所有数据也会失败/communications/$communication

要处理此用例,请考虑重组您的数据,以使每个通信都按收件人进行索引,即/communications/$recipient/$communication,这将简化您的安全规则。

此外,您甚至可以使该存储桶由收件人(即.read: auth.id ==$recipient)设为只读,同时允许任何人向该用户发送消息(即.write: auth != null &&!data.exists())。最后一条规则可确保发送方的客户端经过身份验证并写入不存在的位置,例如新的推送ID。

angularjs – 需要检查数组中值的Firebase规则(安全规则中的contains())

angularjs – 需要检查数组中值的Firebase规则(安全规则中的contains())

如何在firebase规则中检查数组中的值.我想做这样的事情:

root.child('connections/'+auth.uid).child('friends').child(someFriendId).exists()

因此,在当前用户的连接节点下,如果在friends数组中存在someFriendId,则允许访问. ‘someFriendId’不是friends数组的键,也就是使用firebase push()方法生成的自动ID.

解决方法

一般来说,avoid arrays in distributed data,并在结构数据指南中阅读 Arrays in Firebase.

您无法在Firebase安全规则中执行“包含”.相反,您需要将用户存储为密钥,类似于we demonstrate this use case in the security docs.

因此,给出您的示例,唯一的更改是使用用户ID替换数组索引,并将值更改为布尔值(或任何其他有用的值).然后您的安全规则可以构造为:

root.child('connections/'+auth.uid+'/friends/'+someFriendId).exists();

Firebase Firestore 安全规则似乎根本没有应用

Firebase Firestore 安全规则似乎根本没有应用

如何解决Firebase Firestore 安全规则似乎根本没有应用?

我对 Firebase 还很陌生,但要么我完全误解了某些东西,要么我的 Firebase 帐户有问题。

我向 Firebase 应用添加了一个 Firestore 数据库,最初我选择在测试模式下创建它。据我在文档中读到,测试模式与生产模式的不同之处仅在于默认 security rules。

我想正确配置我的规则,以便用户只能访问他们自己的数据。

但是,我无法让它工作,所以我尝试将我的 Firestore 安全规则配置为不允许对任何人进行任何读取或写入操作。这是我目前在 Firestore 数据库中设置的 -> 规则:

rules_version = ''2'';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read,write: if false;
        }
      }
    }

据我所知,这些规则不应允许在我的数据库中的任何集合中进行任何读取或写入。 规则操场告诉我当我尝试运行任何请求时:

access denied in firestore rules playground

但是,从我的 NextJS 应用程序中,我仍然可以获取如下数据:

import {
    getFirebaseAdmin
} from ''next-firebase-auth'';
// ...
const categoriesdocument = await getFirebaseAdmin()
        .firestore()
        .collection(''categories'')
        .doc(''D47pV7TxNpDNYNkHgfU0'')
        .get();

一切正常。我还确定数据正是从这个 Firestore 数据库中获取的,因为当我更改某些文档时,它会反映在获取的数据中。

我还注意到,在 Firebase 的 Firestore 数据库 -> 规则 -> 监控规则中,我根本看不到任何结果(总允许数:0,总拒绝数:0,总错误数:0)。

知道这里有什么问题吗?我错过了什么?

解决方法

在服务器上,您以管理员身份使用 firestore。规则在那里不适用。

Firebase Flutter:Cloud Firestore 数据库有不安全的规则

Firebase Flutter:Cloud Firestore 数据库有不安全的规则

你能把你的 read 显式设置为 false 吗?

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
  allow read: if false;
  allow write: if request.auth != null;
  }
 }
} 

应该可以。让我知道它是否仍然存在。 根本原因是,即使您只允许经过身份验证的用户读取或写入,但他们可以访问整个数据库,如 Google Cloud Firestore Documentation 中所述。这也意味着任何经过身份验证的用户都可以在您的数据库中写入任何内容。

如果您的数据库为每个用户都有一个单独的文档,我建议使用以下规则,允许用户仅写入/读取自己的数据。

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
  allow read,write: if request.auth.uid === userId;
  }
 }
} 

firebase – 用于在用户之间共享文档的Firestore数据库规则和结构

firebase – 用于在用户之间共享文档的Firestore数据库规则和结构

我正在尝试创建一个允许用户在列表上进行协作的应用程序.需要邀请每个用户才能在列表上工作.

我构建了这样的数据(松散地基于this blog post).
如果需要,也可以改变这种结构.

list
  list_1:
    users:
      owner:
        owner@company.com: true
      shared:
        user@company.com: true
        user2@company.com: true
    id
    name
    items:
      item_1:
        id:
        name:
      ...

我想要实现的目标:每个人都应该能够创建列表.然后,他们的创建者将成为创建列表的所有者.
只有“共享”文档中的所有者和用户才能读取和写入此列表.

我想权限设置看起来应该是这样的.但这不起作用:

service cloud.firestore {
  match /databases/{database}/documents {
    match /lists/{listId}/{anything=**} {
        allow read,write: if !exists(resource.data.users.owner) ||
                               resource.data.users.owner == request.auth.token.email ||
                               request.auth.token.email in resource.data.users.shared
    }
  }
}

解决方法

我弄清楚了.

我将数据结构更改为:

list
  list_1
    owner: owner@company.com
    writeAccess: [user1@company.com,user2@company.com]
    id
    name
    items:
      item_1:
        id:
        name:
      ...

然后像这样的数据库规则正在工作:

service cloud.firestore {
  match /databases/{database}/documents {
    match /lists/{listId} {
        // Allow RW on lists for owner,shared user or for everyone if it's a new list
      allow read,write: if resource.data.owner == request.auth.token.email ||
                            request.auth.token.email in resource.data.writeAccess ||
                            !exists(/databases/$(database)/documents/lists/$(listId))
    }
    match /lists/{listId}/items/{itemId} {
        // Allow RW on item for owner or shared user of parent list
        allow read,write: if get(/databases/$(database)/documents/lists/$(listId)).data.owner == request.auth.token.email ||
                              request.auth.token.email in get(/databases/$(database)/documents/lists/$(listId)).data.writeAccess ||
                             !exists(/databases/$(database)/documents/lists/$(listId)) // Needed for new lists. Because lists and items are created in a batch
    }
  }
}

今天关于邮件阵列的Firebase安全规则邮件列表的分享就到这里,希望大家有所收获,若想了解更多关于angularjs – 需要检查数组中值的Firebase规则(安全规则中的contains())、Firebase Firestore 安全规则似乎根本没有应用、Firebase Flutter:Cloud Firestore 数据库有不安全的规则、firebase – 用于在用户之间共享文档的Firestore数据库规则和结构等相关知识,可以在本站进行查询。

本文标签: