Class: Brakeman::GemProcessor
- Inherits:
-
BaseProcessor
- Object
- SexpProcessor
- BaseProcessor
- Brakeman::GemProcessor
- Defined in:
- lib/brakeman/processors/gem_processor.rb
Overview
Processes Gemfile and Gemfile.lock
Constant Summary
Constants inherited from BaseProcessor
Constants included from Util
Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::SESSION, Util::SESSION_SEXP
Constants inherited from SexpProcessor
Instance Attribute Summary
Attributes inherited from SexpProcessor
Instance Method Summary collapse
-
#initialize(*args) ⇒ GemProcessor
constructor
A new instance of GemProcessor.
- #process_call(exp) ⇒ Object
- #process_gem_lock(gem_lock) ⇒ Object
- #process_gems(src, gem_lock = nil) ⇒ Object
-
#set_gem_version(line) ⇒ Object
Supports .rc2 but not ~>, >=, or <=.
Methods inherited from BaseProcessor
#find_render_type, #ignore, #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?, #block?, #call?, #camelize, #contains_class?, #context_for, #cookies?, #false?, #file_by_name, #file_for, #github_url, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #make_call, #node_type?, #number?, #params?, #pluralize, #regexp?, #relative_path, #request_env?, #request_value?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #table_to_csv, #template_path_to_name, #true?, #truncate_table, #underscore
Methods included from ProcessorHelper
#class_name, #process_all, #process_all!, #process_call_args, #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 @gem_name_version = /^\s*([-_+.A-Za-z0-9]+) \((\w(\.\w+)*)\)/ @tracker.config[:gems] ||= {} end |
Instance Method Details
#process_call(exp) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/brakeman/processors/gem_processor.rb', line 40 def process_call exp if exp.target == nil and exp.method == :gem gem_name = exp.first_arg return exp unless string? gem_name gem_version = exp.second_arg if string? gem_version @tracker.config[:gems][gem_name.value.to_sym] = gem_version.value else @tracker.config[:gems][gem_name.value.to_sym] = ">=0.0.0" end end exp end |
#process_gem_lock(gem_lock) ⇒ Object
57 58 59 60 61 |
# File 'lib/brakeman/processors/gem_processor.rb', line 57 def process_gem_lock gem_lock gem_lock.each_line do |line| set_gem_version line end end |
#process_gems(src, gem_lock = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/brakeman/processors/gem_processor.rb', line 12 def process_gems src, gem_lock = nil process src if gem_lock process_gem_lock gem_lock @tracker.config[:rails_version] = @tracker.config[:gems][:rails] elsif @tracker.config[:gems][:rails] =~ /(\d+.\d+.\d+)/ @tracker.config[:rails_version] = $1 end if @tracker.[:rails3].nil? and @tracker.[:rails4].nil? and @tracker.config[:rails_version] if @tracker.config[:rails_version].start_with? "3" @tracker.[:rails3] = true Brakeman.notify "[Notice] Detected Rails 3 application" elsif @tracker.config[:rails_version].start_with? "4" @tracker.[:rails3] = true @tracker.[:rails4] = true Brakeman.notify "[Notice] Detected Rails 4 application" end end if @tracker.config[:gems][:rails_xss] @tracker.config[:escape_html] = true Brakeman.notify "[Notice] Escaping HTML by default" end end |
#set_gem_version(line) ⇒ Object
Supports .rc2 but not ~>, >=, or <=
64 65 66 67 68 |
# File 'lib/brakeman/processors/gem_processor.rb', line 64 def set_gem_version line if line =~ @gem_name_version @tracker.config[:gems][$1.to_sym] = $2 end end |