Class: Brakeman::Rails2ConfigProcessor
- Inherits:
-
BaseProcessor
- Object
- SexpProcessor
- BaseProcessor
- Brakeman::Rails2ConfigProcessor
- Defined in:
- lib/brakeman/processors/lib/rails2_config_processor.rb
Overview
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.
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
Instance Attribute Summary
Attributes inherited from BaseProcessor
Attributes inherited from SexpProcessor
Instance Method Summary collapse
-
#get_rails_config(exp) ⇒ Object
Returns an array of symbols for each ‘level’ in the config.
-
#include_rails_config?(exp) ⇒ Boolean
Check if an expression includes a call to set Rails config.
-
#initialize(*args) ⇒ Rails2ConfigProcessor
constructor
A new instance of Rails2ConfigProcessor.
-
#process_attrasgn(exp) ⇒ Object
Look for configuration settings.
-
#process_call(exp) ⇒ Object
Check if config is set to use Erubis.
-
#process_cdecl(exp) ⇒ Object
Check for Rails version.
-
#process_config(src) ⇒ Object
Use this method to process configuration file.
Methods inherited from BaseProcessor
#find_render_type, #make_render, #make_render_in_view, #process_arglist, #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) ⇒ Rails2ConfigProcessor
Returns a new instance of Rails2ConfigProcessor.
23 24 25 26 |
# File 'lib/brakeman/processors/lib/rails2_config_processor.rb', line 23 def initialize *args super @tracker.config[:rails] ||= {} end |
Instance Method Details
#get_rails_config(exp) ⇒ Object
Returns an array of symbols for each ‘level’ in the config
config.action_controller.session_store = :cookie
becomes
[:action_controller, :session_store]
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# 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 == Brakeman::RAILS_CONFIG [exp.method] else get_rails_config(exp.target) << exp.method end else raise "WHAT" end end |
#include_rails_config?(exp) ⇒ Boolean
Check if an expression includes a call to set Rails config
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 == Brakeman::RAILS_CONFIG true else include_rails_config? target end elsif target == Brakeman::RAILS_CONFIG true else false end end |
#process_attrasgn(exp) ⇒ Object
Look for configuration settings
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/brakeman/processors/lib/rails2_config_processor.rb', line 48 def process_attrasgn exp if exp.target == Brakeman::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 = get_rails_config exp level = @tracker.config[:rails] [0..-2].each do |o| level[o] ||= {} level = level[o] end level[.last] = exp.first_arg end exp end |
#process_call(exp) ⇒ Object
Check if config is set to use Erubis
35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
Check for Rails version
73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
Use this method to process configuration file
29 30 31 32 |
# 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 |