gpt4 book ai didi

javascript - ES6 导入的安全方面 - 在 Meteor 的客户端使用

转载 作者:行者123 更新时间:2023-12-01 17:30:06 25 4
gpt4 key购买 nike

在官方Meteor guide它说;

Code that runs on the server can be trusted. Everything else: code that runs on the client, data sent through Method and publication arguments, etc, can’t be trusted.

还有;

Secret business logic in your app should be located in code that is only loaded on the server. This means it is in a server/ directory of your app, in a package that is only included on the server, or in a file inside a package that was loaded only on the server.

敏感的方法/算法等必须放在服务器端。我的第一个问题是,我们如何才能安全地从客户端调用服务器端的敏感方法(比如 createUser())?

我的第二个问题;使用 Meteor.method 之间有什么区别吗?和 Validated-Method在安全方面?调用标准 Meteor 方法时不需要使用 import 语句,但如果调用 Validated-Method 则需要导入它。对于相同的 createUser() 示例,最好在 Meteor 方法中定义它以提高安全性?

最佳答案

In the official Meteor guide it says;

meteor 向导想说的是:

Meteor 是一个完整的堆栈框架,可以通过多种方式解决许多产品需求(在服务器和客户端中分配代码)。假设您想在每次购买商品时向客户收取 20% 的费用。

解决方案 1:向客户收取 20% 的费用

Template.yourTemplate.events({
// ... other events
'click .buyme': function(event, template) {
// Suppose you have product id in element's id attr
let productId = event.target.id,
product = Products.findOne({_id: productId}),
charge = Math.ceil(product.price * 0.2);

// Add a order
Order.insert({
charge,
productId,
userId: Meteor.userId()
})
},
// ... other events
})

解决方案 1:在服务器上收取 20% 的费用

Meteor.methods({
// ... other methods
'order': function(productId) {
// Suppose you have product id in element's id attr
let product = Products.findOne({_id: productId}),
charge = Math.ceil(product.price * 0.2);

// Add a order
Order.insert({
charge,
productId,
userId: Meteor.userId()
})
},
// ... other methods
})

从服务器调用方法。

现在您一定很清楚,我们不能相信解决方案 1,对吧?

is there any difference between using Meteor.method and Validated-Method in terms of security?

不,当然不是。请引用https://github.com/meteor/validated-method了解有关验证方法的更多信息。你会看到两者之间的主要区别是 Metor.Methods 依赖于 magic string 来访问方法,但是 validated-method 在另一手提供用于访问该方法的对象。而且,这就是为什么我们需要导入而不仅仅是 Method.call()

关于javascript - ES6 导入的安全方面 - 在 Meteor 的客户端使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48870864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com