firebase-authentication - Firebase 存储安全规则 Playground "Simulated read denied"

标签 firebase-authentication firebase-storage firebase-security

我希望我的用户只能读取和写入他自己的数据,但是。当我测试规则时,我收到消息“模拟器读取被拒绝”。请告诉我哪里错了?感谢您抽出时间。

这里有一些信息:

规则

service firebase.storage {
  // Only a user can upload their file, but anyone can view it
  match /users/{userId}/{fileName} {
    allow read ;
    allow write: if request.auth != null && request.auth.uid == userId;
  }
}

地点

/b/online-notepad-d43d2.appspot.com/o/WkqtgpdUYRUGOBaAfmCByXtVPoT2/file1.txt

提供商

"password"

FIREBASE UID

WkqtgpdUYRUGOBaAfmCByXtVPoT2

电子邮件

[email protected]

电子邮件已验证

true

身份验证负载

{
  "uid": "WkqtgpdUYRUGOBaAfmCByXtVPoT2",
  "token": {
    "sub": "WkqtgpdUYRUGOBaAfmCByXtVPoT2",
    "aud": "online-notepad-d43d2",
    "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="325a5553474005020372555f535b5e1c515d5f" rel="noreferrer noopener nofollow">[email protected]</a>",
    "email_verified": true,
    "firebase": {
      "sign_in_provider": "password"
    }
  }
}

屏幕截图

我正在使用的确切位置:“/WkqtgpdUYRUGOBaAfmCByXtVPoT2/file1.txt” 另一件事是我通过上传按钮上传此文件夹和文件。 不是来自 POST 请求。

enter image description here

enter image description here

enter image description here

After changing rules still getting same result 😥

enter image description here

enter image description here

enter image description here

仍然得到相同的结果:(

enter image description here

enter image description here

enter image description here

enter image description here

最佳答案

这里定义了两个完全独立的子句:

allow read ;
allow write: if request.auth != null && request.auth.uid == userId;

因此,您有一个空的读取子句和一个非空的写入子句。

您可能想使用:

allow read, write: if request.auth != null && request.auth.uid == userId;

编辑第二个问题:正如您在编辑中所说,您正在访问路径 /WkqtgpdUYRUGOBaAfmCByXtVPoT2/file1.txt,但您的规则仅定义 匹配/users/{userId}/{fileName}。由于您只允许在 /users/... 中进行访问,并且您尝试使用的路径不在 /users 中,因此访问会被规则拒绝。

关于firebase-authentication - Firebase 存储安全规则 Playground "Simulated read denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70409878/

相关文章:

android - Firebase 规则解析错误

android - 更新到 Firebase Android 版本 15.0.0,将用户注销

java - 为管理员 Firebase Android 创建重置密码

android - 如何从 Firebase Storage 下载文件到 Android 的 External_Storage

Firebase 函数 - 生成和托管静态网页

javascript - Promise.all 在 firebase 中使用 getDownloadURL()

firebase - 允许特定用户写访问

javascript - 如何更正在 firebase 实时规则上添加索引

firebase - Firestore - 云功能 - 获取 uid

angular - ionic 3 中的 "Runtime Error Zone already loaded"