为什么即使有规则,我仍然可以通过浏览器打开存储在Firebase存储中的图像?

时间:2020-01-01 07:51:08

标签: firebase firebase-storage firebase-security

所以我有这样的安全规则:

service firebase.storage {
  match /b/{bucket}/o {

    match /eventPoster/{imageID} {
            allow read: if isSignedIn()
          allow create: if isSignedIn() && isImage() && lessThanNMegabytes(0.5)
        }



        function isSignedIn() {
          return request.auth != null;
        }

        function isBelongTo(userId) {
          return request.auth.uid == userId;
        }

        function lessThanNMegabytes(n) {
            return request.resource.size < n * 1024 * 1024;
        }

        function isImage() {
            return request.resource.contentType.matches('image/.*');
        }
   }

}

如您所见,我只设置了可以查看/读取图像的登录用户。但是,如果我像下面的隐身浏览器一样,将文件中的链接复制并粘贴到存储区中,仍然可以看到我的图片

https://firebasestorage.googleapis.com/v0/b/XXXXXXX.appspot.com/o/eventPoster%2F0050370e-a226-4a69-a635-ceccce10007c?alt=media&token=44f6d5a4-ff44-4376-3c7b9dfac465

我希望我无法通过浏览器看到图像,我使用Google chrome对其进行了测试。即使我的应用程序仅适用于Android和iOS,也仅用于测试,我还是使用浏览器。我认为,如果我通过浏览器访问它,则没有登录

1 个答案:

答案 0 :(得分:0)

您共享的URL是一个下载URL。无论安全规则如何,该URL都是公共可读的。阻止其运行的唯一方法是从Firebase控制台撤消其令牌。

如果您希望仅根据其安全规则访问Firebase Storage中的文件,请不要为其生成下载URL,或者至少不要与任何人共享下载URL。