【问题标题】:Relying on Meteor.userId() for security in Meteor?依靠 Meteor.userId() 来确保 Meteor 的安全性?
【发布时间】:2017-12-01 05:27:33
【问题描述】:

我在服务器上有一个更新用户电子邮件地址的方法。我知道这只会在用户只有 1 个电子邮件地址时才有效,但目前还可以。

Meteor.methods({
  'user.updateEmail'({ email, userId }) {
    Meteor.users.update(
      { _id: userId },
      {
        $set: {
          'emails.0.address': email,
          'emails.0.verified': false,
        },
      },
    );
  },
});

我从 React 组件中的表单调用此方法:

const formSubmit = e => {
    e.preventDefault();
    const email = e.target.email.value;
    const userId = Meteor.userId();
    Meteor.call('user.updateEmail', { email, userId }, err => {
      if (err) {
        alert(err);
      }
    });
  };

这不安全吗?我从客户端传递了 userId,所以大概可以更改它?

【问题讨论】:

    标签: reactjs meteor


    【解决方案1】:

    你是对的。您应该在您的方法中使用Meteor.userId() 来接收用户的ID。用户无法更改此项。

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 2011-06-19
      • 1970-01-01
      • 2015-04-02
      • 2021-05-25
      • 2021-03-03
      相关资源
      最近更新 更多