Class: Brakeman::GemProcessor

Inherits:
BaseProcessor show all
Defined in:
lib/brakeman/processors/gem_processor.rb

Overview

Processes Gemfile and Gemfile.lock

Constant Summary

Constants included from Util

Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from BaseProcessor

#ignore

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods inherited from BaseProcessor

#find_render_type, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_class, #process_default, #process_dstr, #process_evstr, #process_hash, #process_if, #process_ignore, #process_iter, #process_lasgn, #process_scope

Methods included from Util

#array?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #node_type?, #number?, #params?, #pluralize, #regexp?, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #true?, #truncate_table, #underscore

Methods included from ProcessorHelper

#class_name, #process_all, #process_module

Methods inherited from SexpProcessor

#error_handler, #in_context, #process, #process_dummy, #scope

Constructor Details

#initialize(*args) ⇒ GemProcessor

Returns a new instance of GemProcessor.



6
7
8
9
10
# File 'lib/brakeman/processors/gem_processor.rb', line 6

def initialize *args
  super

  @tracker.config[:gems] ||= {}
end

Instance Method Details

#get_rails_version(gem_lock) ⇒ Object



42
43
44
45
46
# File 'lib/brakeman/processors/gem_processor.rb', line 42

def get_rails_version gem_lock
  if gem_lock =~ /\srails \((\d+.\d+.\d+.*)\)$/
    @tracker.config[:rails_version] = $1
  end
end

#process_call(exp) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/brakeman/processors/gem_processor.rb', line 28

def process_call exp
  if exp.target == nil and exp.method == :gem
    args = exp.args

    if string? args.second
      @tracker.config[:gems][args.first.value.to_sym] = args.second.value
    else
      @tracker.config[:gems][args.first.value.to_sym] = ">=0.0.0"
    end
  end

  exp
end

#process_gems(src, gem_lock = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/brakeman/processors/gem_processor.rb', line 12

def process_gems src, gem_lock = nil
  process src

  if gem_lock
    get_rails_version gem_lock
  elsif @tracker.config[:gems][:rails] =~ /(\d+.\d+.\d+)/
    @tracker.config[:rails_version] = $1
  end

  if @tracker.config[:gems][:rails_xss]
    @tracker.config[:escape_html] = true

    Brakeman.notify "[Notice] Escaping HTML by default"
  end
end