如何实现Sails.js中所有属性的白名单,避免批量赋值安全错误?
How can I achieve white listing of all attributes in Sails.js to avoid mass assignment security mistake?
Sails.js 为 GET、PUT、POST、DELETE 提供蓝图路由,映射到控制器的 find/findOne、更新、创建和销毁操作。现在,我最近在 Rails 中阅读了关于白名单属性功能的 this 文章,它告诉了哪些属性可以通过批量更新进行更新,这也保护了 API 免受意外更改。
我想知道 Sails 中是否有类似的功能?
我认为 sails 没有这个功能。您可能必须覆盖控制器中的蓝图方法才能在那里声明白名单。
您也可以通过覆盖 the update blueprint. You could had some code that looks for a attr_accessible
attribute in the model and clean the values.
来实现此功能
查看 this answer 了解如何覆盖蓝图。
Sails.js 为 GET、PUT、POST、DELETE 提供蓝图路由,映射到控制器的 find/findOne、更新、创建和销毁操作。现在,我最近在 Rails 中阅读了关于白名单属性功能的 this 文章,它告诉了哪些属性可以通过批量更新进行更新,这也保护了 API 免受意外更改。
我想知道 Sails 中是否有类似的功能?
我认为 sails 没有这个功能。您可能必须覆盖控制器中的蓝图方法才能在那里声明白名单。
您也可以通过覆盖 the update blueprint. You could had some code that looks for a attr_accessible
attribute in the model and clean the values.
查看 this answer 了解如何覆盖蓝图。