Class: CustomCops::DontPrintAllEnv

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

Constant Summary collapse

MSG =

This cop checks if someone accidentally print all environment variables

because some of them may contain secrets.

Examples:

# bad
puts ENV.to_h
puts `env`
puts ENVIRON.to_h

# good
puts ENV['SOME_KEY']
puts ENVIRON['SOME_KEY']
'Printing all Environment Variables is extremely risky ' \
'If this code has been run, then it is likely that secrets have been ' \
'exposed in plaintext. Please alert `#infosec` about this so it can be ' \
'investigated immediately.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



30
31
32
33
34
# File 'lib/simplycop/custom_cops/dont_print_all_env.rb', line 30

def on_send(node)
  return unless convert_env_to_hash_or_array?(node) || print_all_env_shell?(node)

  add_offense(node.loc.selector)
end