Class: Security::RejectAllRequestsLocal

Inherits:
RuboCop::Cop::Base
  • Object
show all
Defined in:
lib/simplycop/security/reject_all_requests_local.rb

Constant Summary collapse

RAILS_ENV =
['integration', 'staging', 'production']
MSG =
"RAILS CONFIG: Restrict usage of option 'consider_all_requests_local' on #{RAILS_ENV.join(', ')} envs"

Instance Method Summary collapse

Instance Method Details

#block_listed?(string) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/simplycop/security/reject_all_requests_local.rb', line 15

def block_listed?(string)
  RAILS_ENV.each_with_object([]) do |env, results|
    results << string.include?(env)
  end.any?(true)
end

#found_match(string) ⇒ Object



21
22
23
# File 'lib/simplycop/security/reject_all_requests_local.rb', line 21

def found_match(string)
  /config.consider_all_requests\S?.*=\s?.*true/.match?(string)
end

#on_send(node) ⇒ Object



8
9
10
11
12
13
# File 'lib/simplycop/security/reject_all_requests_local.rb', line 8

def on_send(node)
  source = node.source
  file_name = node.loc.operator.to_s

  add_offense(node.loc.selector) if found_match(source) && block_listed?(file_name)
end