Class: Brakeman::LibraryProcessor

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

Overview

Process generic library and stores it in Tracker.libs

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_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

Methods inherited from SexpProcessor

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

Constructor Details

#initialize(tracker) ⇒ LibraryProcessor

Returns a new instance of LibraryProcessor.



7
8
9
10
11
# File 'lib/brakeman/processors/library_processor.rb', line 7

def initialize tracker
  super
  @file_name = nil
  @alias_processor = Brakeman::AliasProcessor.new tracker
end

Instance Method Details

#process_class(exp) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/brakeman/processors/library_processor.rb', line 18

def process_class exp
  name = class_name(exp.class_name)
  
  if @current_class
    outer_class = @current_class
    name = (outer_class[:name].to_s + "::" + name.to_s).to_sym
  end

  if @current_module
    name = (@current_module[:name].to_s + "::" + name.to_s).to_sym
  end

  if @tracker.libs[name]
    @current_class = @tracker.libs[name]
  else
    begin
      parent = class_name exp.parent_name
    rescue StandardError => e
      Brakeman.debug e
      parent = nil
    end

    @current_class = { :name => name,
                  :parent => parent,
                  :includes => [],
                  :public => {},
                  :private => {},
                  :protected => {},
                  :src => exp,
                  :file => @file_name }
  
    @tracker.libs[name] = @current_class
  end

  exp.body = process exp.body

  if outer_class
    @current_class = outer_class
  else
    @current_class = nil
  end

  exp
end

#process_defn(exp) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/brakeman/processors/library_processor.rb', line 100

def process_defn exp
  exp = @alias_processor.process exp
  exp.node_type = :methdef

  if @current_class
    @current_class[:public][exp.method_name] = exp
  elsif @current_module
    @current_module[:public][exp.method_name] = exp
  end

  exp
end

#process_defs(exp) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/brakeman/processors/library_processor.rb', line 113

def process_defs exp
  exp = @alias_processor.process exp
  exp.node_type = :selfdef

  if @current_class
    @current_class[:public][exp.method_name] = exp
  elsif @current_module
    @current_module[:public][exp.method_name] = exp
  end

  exp
end

#process_library(src, file_name = nil) ⇒ Object



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

def process_library src, file_name = nil
  @file_name = file_name
  process src
end

#process_module(exp) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/brakeman/processors/library_processor.rb', line 63

def process_module exp
  name = class_name(exp.module_name)

  if @current_module
    outer_class = @current_module
    name = (outer_class[:name].to_s + "::" + name.to_s).to_sym
  end

  if @current_class
    name = (@current_class[:name].to_s + "::" + name.to_s).to_sym
  end

  if @tracker.libs[name]
    @current_module = @tracker.libs[name]
  else
    @current_module = { :name => name,
                  :includes => [],
                  :public => {},
                  :private => {},
                  :protected => {},
                  :src => exp,
                  :file => @file_name }
  
    @tracker.libs[name] = @current_module
  end

  exp.body = process exp.body

  if outer_class
    @current_module = outer_class
  else
    @current_module = nil
  end

  exp
end