Class: Spektr::Checks::CsrfSetting
- Defined in:
- lib/spektr/checks/csrf_setting.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(app, target) ⇒ CsrfSetting
constructor
A new instance of CsrfSetting.
- #run ⇒ Object
Methods inherited from Base
#app_version_between?, #dupe?, #full_receiver, #model_attribute?, #receivers_for, #should_run?, #target_affected?, #user_input?, #version_affected, #version_between?, #warn!
Constructor Details
#initialize(app, target) ⇒ CsrfSetting
Returns a new instance of CsrfSetting.
4 5 6 7 8 9 |
# File 'lib/spektr/checks/csrf_setting.rb', line 4 def initialize(app, target) super @name = 'Cross-Site Request Forgery' @type = 'Cross-Site Request Forgery' @targets = ['Spektr::Targets::Controller'] end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/spektr/checks/csrf_setting.rb', line 11 def run return unless super return if @target.concern? target = @target return if @target.find_calls(:skip_forgery_protection).none? skip = @target.find_calls(:skip_forgery_protection).last return if skip && skip.arguments && skip.arguments.arguments.first.elements.map(&:key).map(&:unescaped).intersection(%w[only except]).any? warn! @target, self, nil, 'protect_from_forgery should be enabled' end |