Class: Brakeman::Rails3ConfigProcessor
- Inherits:
-
BaseProcessor
- Object
- SexpProcessor
- BaseProcessor
- Brakeman::Rails3ConfigProcessor
- Defined in:
- lib/brakeman/processors/lib/rails3_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:
MyApp::Application.configure do
config.active_record.whitelist_attributes = true
end
will be stored in
tracker.config[:rails][:active_record][:whitelist_attributes]
Values for tracker.config will still be Sexps.
Constant Summary
Constant Summary
Constants included from Util
Util::ALL_PARAMETERS, Util::COOKIES, Util::PARAMETERS, Util::PATH_PARAMETERS, Util::QUERY_PARAMETERS, Util::REQUEST_PARAMETERS, Util::SESSION
Instance Attribute Summary
Attributes inherited from BaseProcessor
Instance Method Summary (collapse)
-
- (Object) get_rails_config(exp)
Returns an array of symbols for each 'level' in the config.
-
- (Boolean) include_rails_config?(exp)
Check if an expression includes a call to set Rails config.
-
- (Rails3ConfigProcessor) initialize(*args)
constructor
A new instance of Rails3ConfigProcessor.
-
- (Object) process_attrasgn(exp)
Look for configuration settings.
-
- (Object) process_class(exp)
Look for class Application < Rails::Application.
-
- (Object) process_config(src)
Use this method to process configuration file.
-
- (Object) process_iter(exp)
Look for MyApp::Application.configure do ...
Methods inherited from BaseProcessor
#find_render_type, #make_render, #process_and, #process_arglist, #process_block, #process_default, #process_dstr, #process_evstr, #process_hash, #process_iasgn, #process_if, #process_ignore, #process_lasgn, #process_or, #process_scope
Methods included from Util
#array?, #call?, #camelize, #cookies?, #false?, #hash?, #hash_insert, #hash_iterate, #integer?, #number?, #params?, #pluralize, #regexp?, #result?, #set_env_defaults, #sexp?, #string?, #symbol?, #true?, #underscore
Methods included from ProcessorHelper
Constructor Details
- (Rails3ConfigProcessor) initialize(*args)
A new instance of Rails3ConfigProcessor
18 19 20 21 22 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 18 def initialize *args super @tracker.config[:rails] ||= {} @inside_config = false end |
Instance Method Details
- (Object) get_rails_config(exp)
Returns an array of symbols for each 'level' in the config
config.action_controller.session_store = :cookie
becomes
[:action_controller, :session_store]
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 102 def get_rails_config exp if sexp? exp and exp.node_type == :attrasgn attribute = exp[2].to_s[0..-2].to_sym get_rails_config(exp[1]) << attribute elsif call? exp if exp[1] == Brakeman::RAILS_CONFIG [exp[2]] else get_rails_config(exp[1]) << exp[2] end else raise "WHAT" end end |
- (Boolean) include_rails_config?(exp)
Check if an expression includes a call to set Rails config
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 80 def include_rails_config? exp target = exp[1] if call? target if target[1] == Brakeman::RAILS_CONFIG true else include_rails_config? target end elsif target == Brakeman::RAILS_CONFIG true else false end end |
- (Object) process_attrasgn(exp)
Look for configuration settings
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 53 def process_attrasgn exp return exp unless @inside_config if exp[1] == Brakeman::RAILS_CONFIG #Get rid of '=' at end attribute = exp[2].to_s[0..-2].to_sym if exp[3].length > 2 #Multiple arguments?...not sure if this will ever happen @tracker.config[:rails][attribute] = exp[3][1..-1] else @tracker.config[:rails][attribute] = exp[3][1] 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[3][1] end exp end |
- (Object) process_class(exp)
Look for class Application < Rails::Application
42 43 44 45 46 47 48 49 50 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 42 def process_class exp if exp[1] == :Application @inside_config = true process exp[-1] if sexp? exp[-1] @inside_config = false end exp end |
- (Object) process_config(src)
Use this method to process configuration file
25 26 27 28 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 25 def process_config src res = Brakeman::AliasProcessor.new.process_safely(src) process res end |
- (Object) process_iter(exp)
Look for MyApp::Application.configure do ... end
31 32 33 34 35 36 37 38 39 |
# File 'lib/brakeman/processors/lib/rails3_config_processor.rb', line 31 def process_iter exp if sexp?(exp[1][1]) and exp[1][1][0] == :colon2 and exp[1][1][2] == :Application @inside_config = true process exp[-1] if sexp? exp[-1] @inside_config = false end exp end |