Class: Brakeman::LibraryProcessor

Inherits:
BaseProcessor show all
Includes:
ModuleHelper
Defined in:
lib/brakeman/processors/library_processor.rb

Overview

Process generic library and stores it in Tracker.libs

Constant Summary

Constants inherited from BaseProcessor

BaseProcessor::IGNORE

Constants included from Util

Util::ALL_COOKIES, Util::ALL_PARAMETERS, Util::COOKIES, Util::COOKIES_SEXP, Util::DIR_CONST, Util::LITERALS, Util::PARAMETERS, Util::PARAMS_SEXP, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_COOKIES, Util::REQUEST_ENV, Util::REQUEST_PARAMETERS, Util::REQUEST_PARAMS, Util::REQUEST_REQUEST_PARAMETERS, Util::SAFE_LITERAL, Util::SESSION, Util::SESSION_SEXP

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary

Attributes inherited from SexpProcessor

#context, #env, #expected

Instance Method Summary collapse

Methods included from ModuleHelper

#handle_class, #handle_module

Methods inherited from BaseProcessor

#find_render_type, #ignore, #make_inline_render, #make_render, #make_render_in_view, #process_arglist, #process_attrasgn, #process_block, #process_cdecl, #process_default, #process_dstr, #process_evstr, #process_file, #process_hash, #process_if, #process_ignore, #process_lasgn, #process_scope

Methods included from Util

#array?, #block?, #call?, #camelize, #class_name, #constant?, #contains_class?, #cookies?, #dir_glob?, #false?, #hash?, #hash_access, #hash_insert, #hash_iterate, #integer?, #kwsplat?, #literal?, #make_call, #node_type?, #number?, #params?, #pluralize, #rails_version, #regexp?, #remove_kwsplat, #request_env?, #request_value?, #result?, #safe_literal, #safe_literal?, #safe_literal_target?, #set_env_defaults, #sexp?, #string?, #string_interp?, #symbol?, #template_path_to_name, #true?, #underscore

Methods included from ProcessorHelper

#current_file, #process_all, #process_all!, #process_call_args, #process_call_defn?

Methods inherited from SexpProcessor

#in_context, #process, processors, #scope

Constructor Details

#initialize(tracker) ⇒ LibraryProcessor

Returns a new instance of LibraryProcessor.


10
11
12
13
14
15
16
17
# File 'lib/brakeman/processors/library_processor.rb', line 10

def initialize tracker
  super
  @current_file = nil
  @alias_processor = Brakeman::AliasProcessor.new tracker
  @current_module = nil
  @current_class = nil
  @initializer_env = nil
end

Instance Method Details

#process_call(exp) ⇒ Object


55
56
57
58
59
60
61
# File 'lib/brakeman/processors/library_processor.rb', line 55

def process_call exp
  if process_call_defn? exp
    exp
  else
    process_default exp
  end
end

#process_class(exp) ⇒ Object


24
25
26
# File 'lib/brakeman/processors/library_processor.rb', line 24

def process_class exp
  handle_class exp, @tracker.libs, Brakeman::Library
end

#process_defn(exp) ⇒ Object Also known as: process_defs


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/brakeman/processors/library_processor.rb', line 32

def process_defn exp
  if exp.method_name == :initialize
    @alias_processor.process_safely exp.body_list
    @initializer_env = @alias_processor.only_ivars
  elsif node_type? exp, :defn
    exp = @alias_processor.process_safely exp, @initializer_env
  else
    exp = @alias_processor.process exp
  end

  if @current_class
    exp.body = process_all! exp.body
    @current_class.add_method :public, exp.method_name, exp, @current_file
  elsif @current_module
    exp.body = process_all! exp.body
    @current_module.add_method :public, exp.method_name, exp, @current_file
  end

  exp
end

#process_iter(exp) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/brakeman/processors/library_processor.rb', line 63

def process_iter exp
  res = process_default exp

  if node_type? res, :iter and call? exp.block_call # sometimes this changes after processing
    if exp.block_call.method == :included and (@current_module or @current_class)
      (@current_module || @current_class).options[:included] = res.block
    end
  end

  res
end

#process_library(src, current_file = @current_file) ⇒ Object


19
20
21
22
# File 'lib/brakeman/processors/library_processor.rb', line 19

def process_library src, current_file = @current_file
  @current_file = current_file
  process src
end

#process_module(exp) ⇒ Object


28
29
30
# File 'lib/brakeman/processors/library_processor.rb', line 28

def process_module exp
  handle_module exp, Brakeman::Library
end