问题描述
此 Firebase Cloud Storage 规则失败(特别是“匹配”条件)。如果我删除它,当然,一切正常。或者,如果我拆分 resource.Metadata.sentTo
字段,如您在本文底部看到的那样,它也可以工作。
我的 RE2“匹配”正则表达式条件的语法错误是什么?显然,简单地放置一串字符是失败的。在评估时,假设 request.auth.uid
包含存储在 resource.Metadata.sentTo
中的 ID 之一?
rules_version = '2';
service firebase.storage {
function isSignedIn() {
return request.auth != null;
}
match /b/{bucket}/o {
match /accounts/{senderUid}/sent/{allPaths=**} {
allow read: if isSignedIn()
&& resource.Metadata.sentTo.matches(request.auth.uid);
}
}
}
我试图访问的 Storage 中的对象有一个 resource.Metadata.sentTo
字段,该字段设置为一串 uid,例如wQGc8YO1lovcW70FvD0fHwf04y72,LaOZzqOInUYlZJYcYg0D2Ghc8u43
。
根据 storage rules matches docs,我可以使用 RE2 执行正则表达式,我已经 tested。在下面的屏幕截图中,您可以看到我选择了使用 RE2 的 Golang。使用 uid 之一的简单检查在此在线工具中工作正常,但在存储规则中无效。
此外,更多的是仅供参考,有很多方法可以给众所周知的猫剥皮。这适用于 resource.Metadata.sentTo
字段条件。
rules_version = '2';
service firebase.storage {
function isSignedIn() {
return request.auth != null;
}
match /b/{bucket}/o {
match /accounts/{senderUid}/sent/{allPaths=**} {
allow read: if isSignedIn()
&& request.auth.uid in resource.Metadata.sentTo.split('\\,');
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)