仅使用 SimpleSchema 进行验证而不使用 allow/deny 规则是否不安全?
Is it insecure to just validate with SimpleSchema, and not use allow/deny rules?
我正在以同构方式使用 SimpleSchema(node-simpl-schema
包)。验证消息显示在客户端以及来自 meteor shell
.
我的问题是这个设置是否真的安全,如果我还需要写 allow/deny 规则。
例如:
SimpleSchema.setDefaultMessages
messages:
en:
"missing_user": "cant create a message with no author"
MessagesSchema = new SimpleSchema({
content: {
type: String,
label: "Message",
max: 200,
},
author_id: {
type: String,
autoform:
defaultValue: ->
Meteor.userId()
custom: ->
if !Meteor.users.findOne(_id: @obj.author_id)
"missing_user"
},
room_id: {
type: String,
}
}, {tracker: Tracker})
在 meteor shell
中,我对其进行了测试,它按预期工作。
> Messages.insert({content: "foo", author_id: "asd"})
/home/max/Desktop/project/meteor/two/.meteor/local/build/programs/server/packages/aldeed_collection2-core.js:501
throw error; // 440
^
Error: cant create a message with no author
我应该在我的 allow/deny 规则中复制这个验证逻辑吗?或者我可以让我的 allow
功能始终 return true
,就像我现在所做的那样?
我有一些非常简单的规则来确保应用程序的安全:
- 不要使用 allow/deny 规则 - 拒绝所有客户端写入请求。
- 如果客户端需要在数据库中写入一些东西,他们必须通过 Meteor 方法来完成。
- 理想情况下,Meteor 方法会调用一个函数(可以是共享代码,或特定于服务器的代码),然后检查数据库修饰符的有效性(使用模式)将在这些函数内部完成。
- 您还可以选择创建客户端方法,该方法会在调用服务器端方法之前清理对象并使用架构执行自己的验证。
我正在以同构方式使用 SimpleSchema(node-simpl-schema
包)。验证消息显示在客户端以及来自 meteor shell
.
我的问题是这个设置是否真的安全,如果我还需要写 allow/deny 规则。
例如:
SimpleSchema.setDefaultMessages
messages:
en:
"missing_user": "cant create a message with no author"
MessagesSchema = new SimpleSchema({
content: {
type: String,
label: "Message",
max: 200,
},
author_id: {
type: String,
autoform:
defaultValue: ->
Meteor.userId()
custom: ->
if !Meteor.users.findOne(_id: @obj.author_id)
"missing_user"
},
room_id: {
type: String,
}
}, {tracker: Tracker})
在 meteor shell
中,我对其进行了测试,它按预期工作。
> Messages.insert({content: "foo", author_id: "asd"})
/home/max/Desktop/project/meteor/two/.meteor/local/build/programs/server/packages/aldeed_collection2-core.js:501
throw error; // 440
^
Error: cant create a message with no author
我应该在我的 allow/deny 规则中复制这个验证逻辑吗?或者我可以让我的 allow
功能始终 return true
,就像我现在所做的那样?
我有一些非常简单的规则来确保应用程序的安全:
- 不要使用 allow/deny 规则 - 拒绝所有客户端写入请求。
- 如果客户端需要在数据库中写入一些东西,他们必须通过 Meteor 方法来完成。
- 理想情况下,Meteor 方法会调用一个函数(可以是共享代码,或特定于服务器的代码),然后检查数据库修饰符的有效性(使用模式)将在这些函数内部完成。
- 您还可以选择创建客户端方法,该方法会在调用服务器端方法之前清理对象并使用架构执行自己的验证。