【问题标题】:Firebase: Does the bucket owner have access to all data?Firebase:存储桶所有者是否有权访问所有数据?
【发布时间】:2021-04-24 05:42:45
【问题描述】:

我正在使用 Firebase 后端制作待办事项 Android 应用程序。为此,我可以使用一个简单的访问规则,仅当uid == auth.uid 时才允许读写访问。但是,作为存储桶的所有者,我目前能够查看任何用户创建的所有待办事项。显然,这是出乎意料的行为。如何限制对自己存储桶中某些数据的访问?还是有其他选择?

编辑:更多细节。目前的安全规则如下

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if uid == auth.uid;
    }
  }
}

我正在使用 react-native 并关注 rnfirebase 并通过此 SDK 包装器 here 使用 Google 登录。将图像上传到 Firebase 存储的代码遵循教程 here。这是 react-native 中的 sn-p。

const reference = storage().ref('black-t-shirt-sm.png');

  return (
    <View>
      <Button
        onPress={async () => {
          // path to existing file on filesystem
          const pathToFile = `${utils.FilePath.PICTURES_DIRECTORY}/black-t-shirt-sm.png`;
          // uploads file
          await reference.putFile(pathToFile);
        }}
      />
    </View>
  );

【问题讨论】:

  • “存储桶所有者”是 Google 身份验证用户,而不是 Firebase 身份验证用户。当您通过所有者的 Google 帐户访问存储桶时,您确实可以访问其中的所有数据。但是,当您通过 Firebase 身份验证帐户访问它时,情况就不应该如此。所以:请编辑您的问题以显示您如何访问存储桶,因为目前很难(帮助您)拍摄。另见how to create a minimal, complete, verifiable example
  • @FrankvanPuffelen 谢谢。添加了我当前的默认安全规则和相应的 JS 代码,以将测试图像上传到 firebase。
  • 我在下面写了一些反馈作为答案,只是为了更容易阅读。

标签: javascript react-native firebase-storage firebase-security


【解决方案1】:

这毫无意义:

match /{allPaths=**} {
  allow read, write: if uid == auth.uid;
}

如果内置变量 auth.uid 与上下文变量 uid 匹配,则允许访问文件。但是你永远不会在任何地方定义uid,所以规则总是失败。事实上,这甚至不应该保存,因为在使用之前没有在任何地方定义 uid 会导致语法错误。

您是说通过这些规则您有一个能够查看所有文件的用户吗?你能举个例子吗?

【讨论】:

    猜你喜欢
    • 2022-01-09
    • 2010-10-16
    • 2021-09-07
    • 1970-01-01
    • 2021-06-22
    • 2018-03-08
    • 2022-10-14
    • 2020-08-23
    • 2022-01-18
    相关资源
    最近更新 更多