Ruby 在 Rails - 这些 Brakeman 警告是什么意思?

Ruby On Rails - What do these Brakeman warnings mean?

我正在使用 brakeman gem 扫描我的应用程序。

扫描应用程序后,我收到以下警告:

#Security warnings

Method                  | Warning Type    | Message                    
------------------------------------------------------
show                    | Unscoped Find   | Unscoped call to PatientMessage#find near line 27: Message.find(+params[:id]+)
------------------------------------------------------

#Controller warnings:

Controller            | Warning Type               | Message
----------------------------------------------------------------------------
ApplicationController | Cross-Site Request Forgery | 'protect_from_forgery' should be called in ApplicationController

谁能帮忙弄清楚这些警告是什么意思?

protect_from_forgery 错误几乎是不言自明的(它告诉您在应用程序控制器中包括有助于保护您的站点免受跨站点脚本攻击的方法)但是 Unscoped Find 的文档在这里:http://brakemanscanner.org/docs/warning_types/unscoped_find/

基本上,它告诉您应该执行以下操作:

current_user.messages.find(params[:id]) 

而不是 Message.find 这样用户就不能通过将 id 传递到参数中来查找任何消息。上面的示例假设您有一个 current_user 帮助程序,并且一条消息属于某个用户,这在您的应用中可能不是这种情况,但这就是警告的意思。