Class/Module Index [+]

Quicksearch

Brakeman::Rails2ConfigProcessor

Processes configuration. Results are put in tracker.config.

Configuration of Rails via Rails::Initializer are stored in tracker.config. For example:

Rails::Initializer.run |config|
  config.action_controller.session_store = :cookie_store
end

will be stored in

tracker.config[:rails][:action_controller][:session_store]

Values for tracker.config will still be Sexps.

Constants

RAILS_CONFIG

Replace block variable in

Rails::Initializer.run |config|

with this value so we can keep track of it.

Public Class Methods

new(*args) click to toggle source
# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 23
def initialize *args
  super
  @tracker.config[:rails] ||= {}
end

Public Instance Methods

get_rails_config(exp) click to toggle source

Returns an array of symbols for each 'level' in the config

config.action_controller.session_store = :cookie

becomes

[:action_controller, :session_store]
# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 105
def get_rails_config exp
  if node_type? exp, :attrasgn
    attribute = exp.method.to_s[0..-2].to_sym
    get_rails_config(exp.target) << attribute
  elsif call? exp
    if exp.target == RAILS_CONFIG
      [exp.method]
    else
      get_rails_config(exp.target) << exp.method
    end
  else
    raise "WHAT"
  end
end
include_rails_config?(exp) click to toggle source

Check if an expression includes a call to set Rails config

# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 83
def include_rails_config? exp
  target = exp.target
  if call? target
    if target.target == RAILS_CONFIG
      true
    else
      include_rails_config? target
    end
  elsif target == RAILS_CONFIG
    true
  else
    false
  end
end
process_attrasgn(exp) click to toggle source

Look for configuration settings

# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 48
def process_attrasgn exp
  if exp.target == RAILS_CONFIG
    #Get rid of '=' at end
    attribute = exp.method.to_s[0..-2].to_sym
    if exp.args.length > 1
      #Multiple arguments?...not sure if this will ever happen
      @tracker.config[:rails][attribute] = exp.args
    else
      @tracker.config[:rails][attribute] = exp.first_arg
    end
  elsif include_rails_config? exp
    options = get_rails_config exp
    level = @tracker.config[:rails]
    options[0..-2].each do |o|
      level[o] ||= {}
      level = level[o]
    end

    level[options.last] = exp.first_arg
  end

  exp
end
process_call(exp) click to toggle source

Check if config is set to use Erubis

# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 35
def process_call exp
  target = exp.target
  target = process target if sexp? target

  if exp.method == :gem and exp.first_arg.value == "erubis"
    Brakeman.notify "[Notice] Using Erubis for ERB templates"
    @tracker.config[:erubis] = true
  end

  exp
end
process_cdecl(exp) click to toggle source

Check for Rails version

# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 73
def process_cdecl exp
  #Set Rails version required
  if exp.lhs == :RAILS_GEM_VERSION
    @tracker.config[:rails_version] = exp.rhs.value
  end

  exp
end
process_config(src) click to toggle source

Use this method to process configuration file

# File lib/brakeman/processors/lib/rails2_config_processor.rb, line 29
def process_config src
  res = Brakeman::ConfigAliasProcessor.new.process_safely(src)
  process res
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.