流星收集与安全

时间:2015-03-01 23:57:31

标签: meteor

如果我正确地在此集合上设置allow语句,我很好奇。我正在使用aldeed:autoformaldeed:collection2

以下是玩具项目中issue-collection.js的快照。

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

澄清和实际问题:{strong} BOTH 服务器和客户端上运行allowdeny方法吗?或者他们只在客户端上运行?

问题=新的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();
  }
});

1 个答案:

答案 0 :(得分:0)

请记住,允许/拒绝来自客户端。而且你不能相信来自客户端的任何东西(userId,date等)。 您要做的是从客户端拨打Meteor.method& _.extend该文档包含来自服务器的可靠数据。

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

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