Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DocumentReference返回敏感数据-Firestore_Javascript_Node.js_Firebase_Google Cloud Firestore - Fatal编程技术网

Javascript DocumentReference返回敏感数据-Firestore

Javascript DocumentReference返回敏感数据-Firestore,javascript,node.js,firebase,google-cloud-firestore,Javascript,Node.js,Firebase,Google Cloud Firestore,我有一个“post”和“user”集合,在post中我附加了“userId”作为对用户文档的引用 除了我在Post文档中调用的get().data()方法公开了所有敏感数据(我将通过Express server发送给客户机)之外,其他方法都可以正常工作 这是我在ref变量中得到的: { "success": true, "msg": { "foo": "bar", "userId": { "_firestore": { "_settings":

我有一个“post”和“user”集合,在post中我附加了“userId”作为对用户文档的引用

除了我在Post文档中调用的get().data()方法公开了所有敏感数据(我将通过Express server发送给客户机)之外,其他方法都可以正常工作

这是我在ref变量中得到的:

{
  "success": true,
  "msg": {
    "foo": "bar",
    "userId": {
      "_firestore": {
        "_settings": {
          "credentials": {
            "private_key": "-----BEGIN PRIVATE KEY---------END PRIVATE KEY-----\n", <--- Big problem
            "client_email": "..."
          },
          "projectId": "cpanel-9ac21",
          "firebaseVersion": "8.9.0",
          "libName": "gccl",
          "libVersion": "3.3.3 fire/8.9.0",
          "servicePath": "firestore.googleapis.com",
          "port": 443,
          "clientConfig": {},
          "scopes": [
            "https://www.googleapis.com/auth/cloud-platform",
            "https://www.googleapis.com/auth/datastore"
          ]
        },
        "_settingsFrozen": true,
        "_serializer": {},
        "_projectId": "cpanel-9ac21",
        "_lastSuccessfulRequest": 1578712168345,
        "_backoffSettings": {
          "initialDelayMs": 100,
          "maxDelayMs": 60000,
          "backoffFactor": 1.3
        },
        "_preferTransactions": false,
        "_clientPool": {
          "concurrentOperationLimit": 100,
          "maxIdleClients": 1,
          "activeClients": {},
          "terminated": false
        }
      },
      "_path": {
        "segments": [
          "users",
          "TXMF00S2PugwdwO5ge3vwQA6pV63"
        ]
      }
    },
    "foo": "bar"
  }
}
{
“成功”:没错,
“味精”:{
“foo”:“bar”,
“用户ID”:{
“_firestore”:{
“_设置”:{
“全权证书”:{

“私钥”:“----开始私钥-----结束私钥----\n”,使用Firestore,将公共数据和私有数据分开的典型方法是将它们放在不同的集合中。因此,如果您有一个post,并且需要将公共数据和私有数据分开,您可能有两个集合:“posts public/{id}”和“posts private/{id}”。或者您可以使用相同id下的子集合:“posts/{id}/public”和“posts/{id}/private”


拆分集合后,您还可以使用不同的安全规则保护它们,这些规则只允许访问用户应该能够看到的内容。如果您根本不希望用户看到任何私有数据,则该集合不应授予访问权限。

使用Firestore,将公共数据与私有数据分开的典型方法是因此,如果您有一个post,并且需要划分公共和私有数据,那么您可能有两个集合:“posts public/{id}”和“posts private/{id}”。或者您可以使用相同id下的子集合:“posts/{id}/public”和“posts/{id}/private”


一旦您拆分了集合,您还可以使用不同的安全规则来保护它们,这些规则只允许访问用户应该能够看到的内容。如果您根本不想让用户看到任何私有数据,那么该集合就不应该授予访问权。

我想是这样的,所以firestore基本上会返回DocumentReference instance。我只需要转换到文档的路径:

const purifyData = (data) => {
  const purifiedData = Object.keys(data).reduce((accumulator, prop) => {
    const propData = data[prop];
    if (propData instanceof firebase.firestore.DocumentReference) {
      accumulator[prop] = propData.path;
    } else {
      accumulator[prop] = propData;
    }

    return accumulator;
  }, {});

  return purifiedData;
};

我猜到了,所以firestore基本上会返回DocumentReference实例。我只需要转换到文档的路径:

const purifyData = (data) => {
  const purifiedData = Object.keys(data).reduce((accumulator, prop) => {
    const propData = data[prop];
    if (propData instanceof firebase.firestore.DocumentReference) {
      accumulator[prop] = propData.path;
    } else {
      accumulator[prop] = propData;
    }

    return accumulator;
  }, {});

  return purifiedData;
};

在发送到客户端之前,只需从
ref
对象中删除敏感属性。不要将整个响应发送到客户端。从技术上讲,我可以在发送到客户端时删除“userId”属性,但它不是动态的。如果我有“userId”、“postId”怎么办,…等等,我每次都必须手动删除它。如果某个属性是DocumentReference对象,有没有办法删除它?是的,这很正常,您从Firestore获得很多东西,您的服务可能需要这些东西,但是这些炎症对您的客户没有帮助,除非有业务需要这样做。您正在编写
\u Firestore吗
您自己将数据输入到文档中?或者您是说Firestore会在您共享的代码中返回这些数据,但这些数据并不存在于存储的文档中?如果您能准确显示文档中的内容,这也会很有帮助。字段及其类型是什么?屏幕截图会很好。另外,请显示具体内容您认为应该从该文档中返回给客户端。只需在将对象发送给客户端之前从
ref
对象中删除敏感属性。不要将整个响应发送给客户端。从技术上讲,我可以在发送给客户端时删除“userId”道具,但它不是动态的。如果我有“userId”、“postId”怎么办,…等等,我每次都必须手动删除它。如果某个属性是DocumentReference对象,有没有办法删除它?是的,这很正常,您从Firestore获得很多东西,您的服务可能需要这些东西,但是这些炎症对您的客户没有帮助,除非有业务需要这样做。您正在编写
\u Firestore吗
您自己将数据输入到文档中?或者您是说Firestore会在您共享的代码中返回这些数据,但这些数据并不存在于存储的文档中?如果您能准确显示文档中的内容,这也会很有帮助。字段及其类型是什么?屏幕截图会很好。另外,请显示具体内容您认为应该从该文档返回给客户端。我认为OP可能在谈论
\u设置
。我不确定这是文档数据的一部分。@FrankvanPuffelen不会调用data()只需返回文档中的数据就可以了?应该是的。但是帖子中有太多的系统元数据,我想知道它是否来自Firestore。可能值得尝试重新编写。我想OP可能是在谈论
\u设置
。我不确定这是文档数据的一部分。@FrankvanPuffelen不会打电话给我data()只返回文档中的数据?应该是的。但是帖子中有太多的系统元数据,我想知道它是否来自Firestore。可能值得尝试重新创建。。