You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Storage规则:自定义声明列表值检查失败及官方解决方案

Firebase Storage安全规则检查自定义声明数组元素的解决方案

更新
事实证明,原本预期可行的方法因存在bug失效,Firebase技术支持推荐的以下解决方案已验证有效:

request.auth.token.permissions.toSet().hasAll([0])

我的自定义声明中包含一个仅含单个整数的数组:

someList: [0]

我需要在Firebase Storage安全规则中检查该数组是否包含指定数字,尝试了官方文档提及的hasAll方法,但始终无法生效。

目前已确认自定义声明中的该属性确实存在——因为直接引用数组的部分规则可以正常运行,但使用hasAll或字符串拼接匹配的规则均失效。

示例规则如下:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /clients/{clientId}/{allPaths=**} {      
      // 以下规则有效 - 
      allow read, write: if request.auth.token.someList.join('').size() > 0
      allow read, write: if request.auth.token.someList != null

      // 以下规则无效 -
      allow read, write: if request.auth.token.someList.hasAll([0])
      allow read, write: if request.auth.token.someList.join('').matches('0')
    }
  }
}

内容的提问来源于stack exchange,提问作者chevin99

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 21:22:06