Class: RuboCop::Cop::Betterment::UnsafeJob

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/betterment/unsafe_job.rb

Constant Summary collapse

MSG =
<<~MSG
  This job takes a parameter that will end up serialized in plaintext. Do not pass sensitive data as bare arguments into jobs.

  See here for more information on this error:
  https://github.com/Betterment/betterlint#bettermentunsafejob
MSG

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, options = nil) ⇒ UnsafeJob

Returns a new instance of UnsafeJob.



16
17
18
19
20
# File 'lib/rubocop/cop/betterment/unsafe_job.rb', line 16

def initialize(config = nil, options = nil)
  super
  @sensitive_params = cop_config.fetch("sensitive_params").map(&:to_sym)
  @class_regex = Regexp.new cop_config.fetch("class_regex")
end

Instance Attribute Details

#class_regexObject

Returns the value of attribute class_regex.



7
8
9
# File 'lib/rubocop/cop/betterment/unsafe_job.rb', line 7

def class_regex
  @class_regex
end

#sensitive_paramsObject

Returns the value of attribute sensitive_params.



7
8
9
# File 'lib/rubocop/cop/betterment/unsafe_job.rb', line 7

def sensitive_params
  @sensitive_params
end

Instance Method Details

#on_def(node) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/betterment/unsafe_job.rb', line 22

def on_def(node)
  return unless %i(perform initialize).include?(node.method_name)
  return unless @class_regex.match(node.parent_module_name)

  node.arguments.any? do |argument|
    name, = *argument
    add_offense(argument) if @sensitive_params.include?(name)
  end
end