【问题标题】:Meteor Collection and Security流星收集和安全
【发布时间】:2015-03-03 00:27:00
【问题描述】:

我很好奇我是否在这个集合上正确设置了允许语句。我正在使用aldeed:autoformaldeed:collection2

下面是来自玩具项目的 issue-collection.js 的快照。

这是设置允许检查的正确方法吗?这些是否在客户端(对于 minimongo)和服务器上运行?具体来说,在大多数update 调用中,return !!userId && (doc.userId == userId); 是否足以确保用户已登录并且已登录的用户是文档的所有者?

澄清和实际问题allowdeny 方法是否在BOTH 服务器和客户端上运行?还是它们只在客户端上运行?

问题 = new Mongo.Collection("问题");

if (Meteor.isClient){
  Meteor.subscribe("issues");
}

if(Meteor.isServer){
  Meteor.publish('issues', function () {
    return Issues.find({}, {limit: ServerSettings.maxSubscribe});
  });
}


Issues.attachSchema(new SimpleSchema({


  issue: {
    type: String,
    label: "Describe the issue you noticed",
    max:256
  }   

}));


//SECURITY - Allow Callbacks for posting

Issues.allow({
  insert: function(userId, doc) {


    /* Throw in some defaults. */
    doc.userId = userId;
    doc.sumbitDate = new Date();
    doc.date = new Date();


    // only allow posting if you are logged in
    return !! userId;
  },
  update: function(userId, doc) {

    // only allow updating if you are logged in
    return !!userId && (doc.userId == userId);
  },
  remove: function(userID, doc) {
    //only allow deleting if you are owner
    return doc.submittedById === Meteor.userId();
  }
});

【问题讨论】:

    标签: meteor


    【解决方案1】:

    请记住,允许/拒绝来自客户端。而且您不能信任来自客户端的任何内容(用户 ID、日期等)。 您要做的是从客户端调用Meteor.method_.extend 包含来自服务器的可信数据的文档。

    例如,在浏览器控制台中重写该代码并更改 userId 的值。

    查看 Discover Meteor 博客以了解更多信息(这可能是学习基本模式的最佳资源)https://www.discovermeteor.com/blog

    【讨论】:

    • 我的理解是允许/拒绝方法在两者上都运行。这是在客户端(即使它们与 JS 代码混淆)对 minimongo 进行的条目,但服务器端允许/拒绝仍会阻止插入()。我的假设是否错误?
    • 如果它阻止了 insert(),那么什么都不会进入数据库,对吧?您的代码明确允许插入,但它不知道来自本地集合的 userId 是否被客户端修改。
    • 我相信允许/拒绝方法确实在服务器上运行。并且可以依赖 userId 参数。参见,例如,[discovermeteor.com/blog/meteor-and-security/]。此代码需要 userId 并强制使用 doc.userId。所以我认为这段代码会很好。
    • 不要相信互联网上的某个人,而是自己检查一下。证明很容易。打开控制台,创建一个带有虚假userIddoc 对象并调用insert。看看会发生什么。
    • 它在服务器上运行。我在插入函数中添加了一个 console.log(doc)。我的终端吐出了文件。浏览器控制台保持空白。也就是说,对我来说还有更多的研究。
    猜你喜欢
    • 2013-05-31
    • 2015-07-22
    • 2014-04-16
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    相关资源
    最近更新 更多