限制Firebase中允许的密钥

限制Firebase中允许的密钥,firebase,firebase-security,Firebase,Firebase Security,是否有办法只允许(但不要求)Firebase对象中的密钥?我知道您可以使用.validate来确保对象具有某些键。在各种白名单中,是否可以只允许某些键?如果不是,这似乎是一种很好的方法,可以让不需要的/不必要的数据从恶意客户端进入数据库。您可以使用Firebase的$variables来禁止所有未指定的子级。下面的示例来自: { "rules": { "widget": { // a widget can have a title or color attribute

是否有办法只允许(但不要求)Firebase对象中的密钥?我知道您可以使用
.validate
来确保对象具有某些键。在各种白名单中,是否可以只允许某些键?如果不是,这似乎是一种很好的方法,可以让不需要的/不必要的数据从恶意客户端进入数据库。

您可以使用Firebase的$variables来禁止所有未指定的子级。下面的示例来自:

{
  "rules": {
    "widget": {
      // a widget can have a title or color attribute
      "title": { ".validate": true },
      "color": { ".validate": true },
      // but no other child paths are allowed
      // in this case, $other means any key excluding "title" and "color"
      "$other": { ".validate": false }
    }
  }
}
因此
小部件
节点可以具有
颜色
和/或
标题
属性。但如果它有任何其他属性,它将被拒绝

根据这些安全规则,这些都是有效的:

ref.child('widget').set({ title: 'all is blue' });
ref.child('widget').set({ color: 'blue' });
ref.child('widget').set({ title: 'all is blue', color: 'blue' });
但根据上述规则,这些是无效的:

ref.child('widget').set({ titel: 'all is blue' });
ref.child('widget').set({ title: 'all is blue', description: 'more...' });
您可以使用Firebase的$variables来禁止所有未指定的子级。下面的示例来自:

{
  "rules": {
    "widget": {
      // a widget can have a title or color attribute
      "title": { ".validate": true },
      "color": { ".validate": true },
      // but no other child paths are allowed
      // in this case, $other means any key excluding "title" and "color"
      "$other": { ".validate": false }
    }
  }
}
因此
小部件
节点可以具有
颜色
和/或
标题
属性。但如果它有任何其他属性,它将被拒绝

根据这些安全规则,这些都是有效的:

ref.child('widget').set({ title: 'all is blue' });
ref.child('widget').set({ color: 'blue' });
ref.child('widget').set({ title: 'all is blue', color: 'blue' });
但根据上述规则,这些是无效的:

ref.child('widget').set({ titel: 'all is blue' });
ref.child('widget').set({ title: 'all is blue', description: 'more...' });