流星 - 它有多安全?

Meteor - How safe it is?

我实际上是在使用 meteor 创建我的第一个应用程序,特别是使用 angular 2。我有使用 Angular 1 和 2 的经验,所以基于它。我有一些顾虑...

让我们想象一下这个场景...我的数据存储在 MongoDb:

Collection:客户

{
 name : "Happy client",
 password : "Something non encrypted",
 fullCrediCardNumber : "0000 0000 0000 0000"
}

现在,在我的 meteor 客户端文件夹中,我有这个结构...

collection clients.ts(服务器文件夹)

export var Clients = new Mongo.Collection('clients');

组件client.ts(不是服务器文件夹)

import {Clients} from '../collections/clients.ts';

class MyClients {
clients: Array<Object>;
constructor(zone: NgZone) {
    this.clients = Clients.find();
    }
}

..最后:html 页面呈现它,但只显示客户的名称:

<li *ngFor="#item of clients">
  {{client.name}}
</li>

到此为止。但我担心的是:在 angular 1 和 2 应用程序中,组件或控制器或指令在客户端运行,而不是服务器端。

我设置html只是为了显示客户的名字。但是因为它是啊 html 渲染,可能有一些技巧很容易将一些代码注入到 angular 上的 HTML 渲染中以显示我的所有字段。

或者可以很容易地转到控制台并键入一些命令来显示数据库 collection 中的整个 object。

所以,我的问题是:从这个意义上说,meteor 的安全性如何?我的担忧是否正确? meteor 能够保护我的数据,保护 collection 的名字吗?我知道我可以在 find() 上指定不给我带来那些敏感数据,但由于 find() 可能 运行 不在服务器端,因此可以很容易地即时修改它,不?

无论如何......我会很感激关于流星在这个意义上如何安全(或不安全)的解释。

ty !

您可以通过不在服务器端发布任何敏感数据来保护数据。

Meteor.publish("my-clients", function () {
  return Clients.find({
    contractorId: this.userId   // Publish only the current user's clients
  }, {
    name: 1,    // Publish only the fields you want the browser to know of
    phoneNumber: 1 
  });
});

此示例仅发布当前登录用户客户端的 nameaddress 字段,而不发布其 passwordfullCreditCardNumber

另一个很好的例子是Meteor.users collection。在服务器上,它包含所有用户的所有用户数据、登录凭据、配置文件等。但它也可以在客户端访问。 Meteor 做了两件重要的事情来保护这个非常敏感的 collection:

  • 默认情况下,它只发布一个文档:登录的用户。如果您在浏览器控制台中键入 Meteor.users.find().fetch(),您只会看到当前登录用户的数据,并且客户端无法获取整个 MongoDB users collection。正确的做法是在 Meteor.publish function. See my example above, or 10.9 in the Meteor publish and subscribe tutorial.

  • 中限制已发布文档的数量
  • 并未发布整个用户文档。例如,OAuth 登录凭据和密码哈希不是,您不会在 client-side collection 中找到它们。您始终可以选择发布文档的哪一部分,一个简单的方法是使用 MongoDB projections,如上例所示。