brakeman 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,378 @@
1
+ # 1.8.2
2
+
3
+ * Fixed rescanning problems caused by 1.8.0 changes
4
+ * Fix scope calls with single argument
5
+ * Report specific model name in rendered collections
6
+ * Handle overwritten JSON escape settings
7
+ * Much improved test coverage
8
+ * Add CHANGES to gemspec
9
+
10
+ # 1.8.1
11
+
12
+ * Recover from errors in output formatting
13
+ * Fix false positive in redirect_to (Neil Matatall)
14
+ * Fix problems with removal of `Sexp#method_missing`
15
+ * Fix array indexing in alias processing
16
+ * Fix old mail_to vulnerability check
17
+ * Fix rescans when only controller action changes
18
+ * Allow comparison of versions with unequal lengths
19
+ * Handle super calls with blocks
20
+ * Respect `-q` flag for "Rails 3 detected" message
21
+
22
+ # 1.8.0
23
+
24
+ * Support relative paths in reports (fsword)
25
+ * Allow Brakeman to be run without tty (fsword)
26
+ * Fix exit code with `--compare` (fsword)
27
+ * Fix `--rake` option (Deepak Kumar)
28
+ * Add high confidence warnings for `to_json` XSS (Neil Matatall)
29
+ * Fix `redirect_to` false negative
30
+ * Fix duplicate warnings with `raw` calls
31
+ * Fix shadowing of rendered partials
32
+ * Add "render chain" to HTML reports
33
+ * Add check for XSS in `content_tag`
34
+ * Add full backtrace for errors in debug mode
35
+ * Treat model attributes in `or` expressions as immediate values
36
+ * Switch to method access for Sexp nodes
37
+
38
+ # 1.7.1
39
+
40
+ * Add check for CVE-2012-3463
41
+ * Add check for CVE-2012-3464
42
+ * Add check for CVE-2012-3465
43
+ * Add charset to HTML report (hooopo)
44
+ * Report XSS in select() for Rails 2
45
+
46
+ # 1.7.0
47
+
48
+ * Add check for CVE-2012-3424
49
+ * Link report types to descriptions on website
50
+ * Report errors raised while running check
51
+ * Improve processing of Rails 3 routes
52
+ * Fix "empty char-class" error
53
+ * Improve file access check
54
+ * Avoid warning on non-ActiveModel models
55
+ * Speed improvements by stripping down SexpProcessor
56
+ * Fix how `params[:x] ||=` is handled
57
+ * Treat user input in `or` expressions as immediate values
58
+ * Fix processing of negative array indexes
59
+ * Add line breaks to truncated table rows
60
+
61
+ # 1.6.2
62
+
63
+ * Add checks for CVE-2012-2660, CVE-2012-2661, CVE-2012-2694, CVE-2012-2695 (Dave Worth)
64
+ * Avoid warning when redirecting to a model instance
65
+ * Add `request.parameters` as a parameters hash
66
+ * Raise confidence level for model attributes in redirects
67
+ * Return non-zero exit code when missing dependencies
68
+ * Fix `before_filter :except` logic
69
+ * Only accept symbol literals as before_filter names
70
+ * Cache before_filter lookups
71
+ * Turn off quiet mode by default for `--compare`
72
+
73
+ # 1.6.1
74
+
75
+ * Major rewrite of CheckSQL
76
+ * Fix rescanning of deleted templates
77
+ * Process actions mixed into controllers
78
+ * Handle `render :template => ...`
79
+ * Check for inherited attr_accessible (Neil Matatall)
80
+ * Fix highlighting of HTML escaped values in HTML report
81
+ * Report line number of highlighted value, if available
82
+
83
+ # 1.6.0
84
+
85
+ * Remove the Ruport dependency (Neil Matatall)
86
+ * Add more informational JSON output (Neil Matatall)
87
+ * Add comparison to previous JSON report (Neil Matatall)
88
+ * Add highlighting of dangerous values in HTML/text reports
89
+ * Model#update_attribute should not raise mass assignment warning (Dave Worth)
90
+ * Don't check `find_by_*` method for SQL injection
91
+ * Fix duplicate reporting of mass assignment and SQL injection
92
+ * Fix rescanning of deleted files
93
+ * Properly check for rails_xss in Gemfile
94
+
95
+ # 1.5.3
96
+
97
+ * Add check for user input in Object#send (Neil Matatall)
98
+ * Handle render :layout in views
99
+ * Support output to multiple formats (Nick Green)
100
+ * Prevent infinite loops in mutually recursive templates
101
+ * Only check eval arguments for user input, not targets
102
+ * Search subdirectories for models
103
+ * Set values in request hashes and propagate to views
104
+ * Add rake task file to gemspec (Anton Ageev)
105
+ * Filter rescanning of templates (Neil Matatall)
106
+ * Improve handling of modules and nesting
107
+ * Test for zero errors in test reports
108
+
109
+ # 1.5.2
110
+
111
+ * Fix link_to checks for Rails 2.0 and 2.3
112
+ * Fix rescanning of lib files (Neil Matatall)
113
+ * Output stack trace on interrupt when debugging
114
+ * Ignore user input in if statement conditions
115
+ * Fix --skip-files option
116
+ * Only warn on user input in render paths
117
+ * Fix handling of views when using rails_xss
118
+ * Revert to ruby_parser 2.3.1 for Ruby 1.8 parsing
119
+
120
+ # 1.5.1
121
+
122
+ * Fix detection of global mass assignment setting
123
+ * Fix partial rendering in Rails 3
124
+ * Show backtrace when interrupt received (Ruby 1.9 only)
125
+ * More debug output
126
+ * Remove duplicate method in Brakeman::Rails2XSSErubis
127
+ * Add tracking of module and class to Brakeman::BaseProcessor
128
+ * Report module when using Brakeman::FindCall
129
+
130
+ # 1.5.0
131
+
132
+ * Add version check for SafeBuffer vulnerability
133
+ * Add check for select vulnerability in Rails 3
134
+ * select() is no longer considered safe in Rails 2
135
+ * Add check for skipping CSRF protection with a blacklist
136
+ * Add JSON report format
137
+ * Model#id should not be considered XSS
138
+ * Standardize methods to check for SQL injection
139
+ * Fix Rails 2 route parsing issue with nested routes
140
+
141
+ # 1.4.0
142
+
143
+ * Add check for user input in link_to href parameter
144
+ * Match ERB processing to rails_xss plugin when plugin used
145
+ * Add Brakeman::Report#to_json, Brakeman::Warning#to_json
146
+ * Warnings below minimum confidence are dropped completely
147
+ * Brakeman.run always returns a Tracker
148
+
149
+ # 1.3.0
150
+
151
+ * Add file paths to HTML report
152
+ * Add caching of filters
153
+ * Add --skip-files option
154
+ * Add support for attr_protected
155
+ * Add detection of request.env as user input
156
+ * Descriptions of checks in -k output
157
+ * Improved processing of named scopes
158
+ * Check for mass assignment in ActiveRecord::Associations::AssociationCollection#build
159
+ * Better variable substitution
160
+ * Table output option for rescan reports
161
+
162
+ # 1.2.2
163
+
164
+ * --no-progress works again
165
+ * Make CheckLinkTo a separate check
166
+ * Don't fail on unknown options to resource(s)
167
+ * Handle empty resource(s) blocks
168
+ * Add RescanReport#existing_warnings
169
+
170
+ ## 1.2.1
171
+
172
+ * Remove link_to warning for Rails 3.x or when using rails_xss
173
+ * Don't warn if first argument to link_to is escaped
174
+ * Detect usage of attr_accessible with no arguments
175
+ * Fix error when rendering a partial from a view but not through a controller
176
+ * Fix some issues with rails_xss, CheckCrossSiteScripting, and CheckTranslateBug
177
+ * Simplify Brakeman Rake task
178
+ * Avoid modifying $VERBOSE
179
+ * Add Brakeman::RescanReport#to_s
180
+ * Add Brakeman::Warning#to_s
181
+
182
+ ## 1.2.0
183
+
184
+ * Speed improvements for CheckExecute and CheckRender
185
+ * Check named_scope() and scope() for SQL injection
186
+ * Add --rake option to create rake task to run Brakeman
187
+ * Add experimental support for rescanning a subset of files
188
+ * Add --summary option to only output summary
189
+ * Fix a problem with Rails 3 routes
190
+
191
+ ## 1.1.0
192
+
193
+ * Relax required versions for dependencies
194
+ * Performance improvements for source processing
195
+ * Better progress reporting
196
+ * Handle basic operators like << + - * /
197
+ * Rescue more errors to prevent complete crashes
198
+ * Compatibility with newer Haml versions
199
+ * Fix some warnings
200
+
201
+ ## 1.0.0
202
+
203
+ * Better handling of assignments inside ifs
204
+ * Check more expressions for SQL injection
205
+ * Use latest ruby_parser for better 1.9 syntax support
206
+ * Better behavior for Brakeman as a library
207
+
208
+ ## 1.0.0rc1
209
+
210
+ * Brakeman can now be used as a library
211
+ * Faster call search
212
+ * Add option to return error code if warnings are found (tw-ngreen)
213
+ * Allow truncated messages to be expanded in HTML
214
+ * Fix summary when using warning thresholds
215
+ * Better support for Rails 3 routes
216
+ * Reduce SQL injection duplicate warnings
217
+ * Lower confidence on mass assignment with no user input
218
+ * Ignore mass assignment using all literal arguments
219
+ * Keep expanded context in view with HTML output
220
+
221
+ ## 0.9.2
222
+
223
+ * Fix Rails 3 configuration parsing
224
+ * Add t() helper to check for translate XSS bug
225
+
226
+ ## 0.9.1
227
+
228
+ * Add warning for translator helper XSS vulnerability
229
+
230
+ ## 0.9.0
231
+
232
+ * Process Rails 3 configuration files
233
+ * Fix CSV output
234
+ * Check for config.active_record.whitelist_attributes = true
235
+ * Always produce a warning for without_protection => true
236
+
237
+ ## 0.8.4
238
+
239
+ * Option for separate attr_accessible warnings
240
+ * Option to set CSS file for HTML output
241
+ * Add file names for version-specific warnings
242
+ * Add line number for default routes in a controller
243
+ * Fix hash_insert()
244
+ * Remove use of Queue from threaded checks
245
+
246
+ ## 0.8.3
247
+
248
+ * Respect -w flag in .tabs format (tw-ngreen)
249
+ * Escape HTML output of error messages
250
+ * Add --skip-libs option
251
+
252
+ ## 0.8.2
253
+
254
+ * Run checks in parallel threads by default
255
+ * Fix compatibility with ruby_parser 2.3.1
256
+
257
+ ## 0.8.1
258
+
259
+ * Add option to assume all controller methods are actions
260
+ * Recover from errors when parsing routes
261
+
262
+ ## 0.8.0
263
+
264
+ * Add check for mass assignment using without_protection
265
+ * Add check for password in http_basic_authenticate_with
266
+ * Warn on user input in hash argument with mass assignment
267
+ * auto_link is now considered safe for Rails >= 3.0.6
268
+ * Output detected Rails version in report
269
+ * Keep track of methods called in class definition
270
+ * Add ruby_parser hack for Ruby 1.9 hash syntax
271
+ * Add a few Rails 3.1 tests
272
+
273
+ ## 0.7.2
274
+
275
+ * Fix handling of params and cookies with nested access
276
+ * Add CVEs for checks added in 0.7.0
277
+
278
+ ## 0.7.1
279
+
280
+ * Require BaseProcessor for GemProcessor
281
+
282
+ ## 0.7.0
283
+
284
+ * Allow local variable as a class name
285
+ * Add checks for vulnerabilities fixed in Rails 2.3.14 and 3.0.10
286
+ * Check for default routes in Rails 3 apps
287
+ * Look in Gemfile or Gemfile.lock for Rails version
288
+
289
+ ## 0.6.1
290
+
291
+ * Fix XSS check for cookies as parameters in output
292
+ * Don't bother calling super in CheckSessionSettings
293
+ * Add escape_once as a safe method
294
+ * Accept '\Z' or '\z' in model validations
295
+
296
+ ## 0.6.0
297
+
298
+ * Tests are in place and fully functional
299
+ * Hide errors by default in HTML output
300
+ * Warn if routes.rb cannot be found
301
+ * Narrow methods assumed to be file access
302
+ * Increase confidence for methods known to not escape output
303
+ * Fixes to output processing for Erubis
304
+ * Fixes for Rails 3 XSS checks
305
+ * Fixes to line numbers with Erubis
306
+ * Fixes to escaped output scanning
307
+ * Update CSRF CVE-2011-0447 message to be less assertive
308
+
309
+ ## 0.5.2
310
+
311
+ * Output report file name when finished
312
+ * Add initial tests for Rails 2.x
313
+ * Fix ERB line numbers when using Ruby 1.9
314
+
315
+ ## 0.5.1
316
+
317
+ * Fix issue with 'has_one' => in routes
318
+
319
+ ## 0.5.0
320
+
321
+ * Add support for routes like get 'x/y', :to => 'ctrlr#whatever'
322
+ * Allow empty blocks in Rails 3 routes
323
+ * Check initializer for session settings
324
+ * Add line numbers to session setting warnings
325
+ * Add --checks option to list checks
326
+
327
+ ## 0.4.1
328
+
329
+ * Fix reported line numbers when using new Erubis parser
330
+ (Mostly affects Rails 3 apps)
331
+
332
+ ## 0.4.0
333
+
334
+ * Handle Rails XSS protection properly
335
+ * More detection options for rails_xss
336
+ * Add --escape-html option
337
+
338
+ ## 0.3.2
339
+
340
+ * Autodetect Rails 3 applications
341
+ * Turn on auto-escaping for Rails 3 apps
342
+ * Check Model.create() for mass assignment
343
+
344
+ ## 0.3.1
345
+
346
+ * Always output a line number in tabbed output format
347
+ * Restrict characters in category name in tabbed output format to
348
+ word characters and spaces, for Hudson/Jenkins plugin
349
+
350
+ ## 0.3.0
351
+
352
+ * Check for SQL injection in calls using constantize()
353
+ * Check for SQL injection in calls to count_by_sql()
354
+
355
+ ## 0.2.2
356
+
357
+ * Fix version_between? when no Rails version is specified
358
+
359
+ ## 0.2.1
360
+
361
+ * Add code snippet to tab output messages
362
+
363
+ ## 0.2.0
364
+
365
+ * Add check for mail_to vulnerability - CVE-2011-0446
366
+ * Add check for CSRF weakness - CVE-2011-0447
367
+
368
+ ## 0.1.1
369
+
370
+ * Be more permissive with ActiveSupport version
371
+
372
+ ## 0.1.0
373
+
374
+ * Check link_to for XSS (because arguments are not escaped)
375
+ * Process layouts better (although not perfectly yet)
376
+ * Load custom Haml filters if they are in lib/
377
+ * Tab separated output via .tabs output extension
378
+ * Switch to normal versioning scheme
data/README.md CHANGED
@@ -153,10 +153,10 @@ The `-c` option can be used to specify a configuration file to use.
153
153
 
154
154
  The MIT License
155
155
 
156
- Copyright (c) 2010-2012, YELLOWPAGES.COM, LLC
157
-
158
156
  Copyright (c) 2012, Twitter, Inc.
159
157
 
158
+ Copyright (c) 2010-2012, YELLOWPAGES.COM, LLC
159
+
160
160
  Permission is hereby granted, free of charge, to any person obtaining a copy
161
161
  of this software and associated documentation files (the "Software"), to deal
162
162
  in the Software without restriction, including without limitation the rights
@@ -67,10 +67,10 @@ class Brakeman::CallIndex
67
67
  calls
68
68
  end
69
69
 
70
- def remove_template_indexes
70
+ def remove_template_indexes template_name = nil
71
71
  @calls_by_method.each do |name, calls|
72
72
  calls.delete_if do |call|
73
- call[:location][0] == :template
73
+ from_template call, template_name
74
74
  end
75
75
 
76
76
  @methods.delete name.to_s if calls.empty?
@@ -78,7 +78,7 @@ class Brakeman::CallIndex
78
78
 
79
79
  @calls_by_target.each do |name, calls|
80
80
  calls.delete_if do |call|
81
- call[:location][0] == :template
81
+ from_template call, template_name
82
82
  end
83
83
 
84
84
  @targets.delete name.to_s if calls.empty?
@@ -237,4 +237,10 @@ class Brakeman::CallIndex
237
237
  end
238
238
  end
239
239
  end
240
+
241
+ def from_template call, template_name
242
+ return false unless call[:location][0] == :template
243
+ return true if template_name.nil?
244
+ call[:location][1] == template_name
245
+ end
240
246
  end
@@ -31,7 +31,7 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
31
31
 
32
32
  CGI = Sexp.new(:const, :CGI)
33
33
 
34
- FORM_BUILDER = Sexp.new(:call, Sexp.new(:const, :FormBuilder), :new, Sexp.new(:arglist))
34
+ FORM_BUILDER = Sexp.new(:call, Sexp.new(:const, :FormBuilder), :new, Sexp.new(:arglist))
35
35
 
36
36
  #Run check
37
37
  def run_check
@@ -58,8 +58,9 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
58
58
  @known_dangerous << :strip_tags
59
59
  end
60
60
 
61
- matches = tracker.check_initializers :ActiveSupport, :escape_html_entities_in_json=
62
- json_escape_on = matches.detect {|result| true? result[-1].first_arg}
61
+ json_escape_on = false
62
+ initializers = tracker.check_initializers :ActiveSupport, :escape_html_entities_in_json=
63
+ initializers.each {|result| json_escape_on = true?(result[-1].first_arg) }
63
64
 
64
65
  if !json_escape_on or version_between? "0.0.0", "2.0.99"
65
66
  @known_dangerous << :to_json
@@ -107,7 +108,7 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
107
108
  message = "Unescaped user input value"
108
109
  end
109
110
 
110
- warn :template => @current_template,
111
+ warn :template => @current_template,
111
112
  :warning_type => "Cross Site Scripting",
112
113
  :message => message,
113
114
  :code => input.match,
@@ -128,13 +129,13 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
128
129
  message = "Unescaped model attribute"
129
130
  link_path = "cross_site_scripting"
130
131
  if node_type?(out, :call, :attrasgn) && out.method == :to_json
131
- message += " in JSON hash"
132
+ message += " in JSON hash"
132
133
  link_path += "_to_json"
133
134
  end
134
135
 
135
136
  code = find_chain out, match
136
137
  warn :template => @current_template,
137
- :warning_type => "Cross Site Scripting",
138
+ :warning_type => "Cross Site Scripting",
138
139
  :message => message,
139
140
  :code => code,
140
141
  :confidence => confidence,
@@ -203,7 +204,7 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
203
204
  end
204
205
 
205
206
  warn :template => @current_template,
206
- :warning_type => "Cross Site Scripting",
207
+ :warning_type => "Cross Site Scripting",
207
208
  :message => message,
208
209
  :code => exp,
209
210
  :user_input => @matched.match,
@@ -72,6 +72,8 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
72
72
  model[:options][:scope].each do |args|
73
73
  second_arg = args[2]
74
74
 
75
+ next unless sexp? second_arg
76
+
75
77
  if second_arg.node_type == :iter and node_type? second_arg.block, :block, :call
76
78
  process_scope_with_block name, args
77
79
  elsif second_arg.node_type == :call
@@ -109,7 +109,9 @@ module Brakeman::RenderHelper
109
109
  end
110
110
  end
111
111
 
112
- template_env[Sexp.new(:call, nil, variable, Sexp.new(:arglist))] = Sexp.new(:call, Sexp.new(:const, Brakeman::Tracker::UNKNOWN_MODEL), :new, Sexp.new(:arglist))
112
+ collection = get_class_target(options[:collection]) || Brakeman::Tracker::UNKNOWN_MODEL
113
+
114
+ template_env[Sexp.new(:call, nil, variable, Sexp.new(:arglist))] = Sexp.new(:call, Sexp.new(:const, collection), :new, Sexp.new(:arglist))
113
115
  end
114
116
 
115
117
  #Set original_line for values so it is clear
@@ -154,4 +156,16 @@ module Brakeman::RenderHelper
154
156
 
155
157
  options
156
158
  end
159
+
160
+ def get_class_target sexp
161
+ if call? sexp
162
+ get_class_target sexp.target
163
+ else
164
+ begin
165
+ class_name sexp
166
+ rescue
167
+ nil
168
+ end
169
+ end
170
+ end
157
171
  end
@@ -80,7 +80,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
80
80
  when :model
81
81
  rescan_model path
82
82
  when :lib
83
- process_lib path
83
+ rescan_lib path
84
84
  when :config
85
85
  process_config
86
86
  when :initializer
@@ -115,8 +115,9 @@ class Brakeman::Rescanner < Brakeman::Scanner
115
115
  #from the controller
116
116
  tracker.controllers.each do |name, controller|
117
117
  if controller[:file] == path
118
- tracker.templates.keys.each do |template_name|
119
- if template_name.to_s.match /(.+)\.#{name}#/
118
+ tracker.templates.each do |template_name, template|
119
+ next unless template[:caller]
120
+ unless template[:caller].grep(/^#{name}#/).empty?
120
121
  tracker.reset_template template_name
121
122
  end
122
123
  end
@@ -138,24 +139,23 @@ class Brakeman::Rescanner < Brakeman::Scanner
138
139
 
139
140
  rescan = Set.new
140
141
 
141
- rendered_from_controller = /^#{template_name}\.(.+Controller)#(.+)/
142
- rendered_from_view = /^#{template_name}\.Template:(.+)/
142
+ template_matcher = /^Template:(.+)/
143
+ controller_matcher = /^(.+Controller)#(.+)/
144
+ template_name_matcher = /^#{template_name}\./
143
145
 
144
146
  #Search for processed template and process it.
145
147
  #Search for rendered versions of template and re-render (if necessary)
146
148
  tracker.templates.each do |name, template|
147
149
  if template[:file] == path or template[:file].nil?
148
- name = name.to_s
149
-
150
- if name.match(rendered_from_controller)
151
- #Rendered from controller, so reprocess controller
152
-
153
- rescan << [:controller, $1.to_sym, $2.to_sym]
154
- elsif name.match(rendered_from_view)
155
- #Rendered from another template, so reprocess that template
150
+ next unless template[:caller] and name.to_s.match(template_name_matcher)
156
151
 
157
- rescan << [:template, $1.to_sym]
158
- end
152
+ template[:caller].each do |from|
153
+ if from.match(template_matcher)
154
+ rescan << [:template, $1.to_sym]
155
+ elsif from.match(controller_matcher)
156
+ rescan << [:controller, $1.to_sym, $2.to_sym]
157
+ end
158
+ end
159
159
  end
160
160
  end
161
161
 
@@ -189,6 +189,21 @@ class Brakeman::Rescanner < Brakeman::Scanner
189
189
  @reindex << :models
190
190
  end
191
191
 
192
+ def rescan_lib path
193
+ process_lib path if File.exists? path
194
+
195
+ lib = nil
196
+
197
+ tracker.libs.each do |name, library|
198
+ if library[:file] == path
199
+ lib = library
200
+ break
201
+ end
202
+ end
203
+
204
+ rescan_mixin lib if lib
205
+ end
206
+
192
207
  #Handle rescanning when a file is deleted
193
208
  def rescan_deleted_file path, type
194
209
  case type
@@ -214,21 +229,7 @@ class Brakeman::Rescanner < Brakeman::Scanner
214
229
  end
215
230
 
216
231
  def rescan_deleted_controller path
217
- #Remove from controller
218
- tracker.controllers.delete_if do |name, controller|
219
- if controller[:file] == path
220
- template_matcher = /(.+)\.#{name}#/
221
-
222
- #Remove templates rendered from this controller
223
- tracker.templates.keys.each do |template_name|
224
- if template_name.to_s.match template_matcher
225
- tracker.reset_template template_name
226
- end
227
- end
228
-
229
- true
230
- end
231
- end
232
+ tracker.reset_controller path
232
233
  end
233
234
 
234
235
  def rescan_deleted_template path
@@ -255,9 +256,16 @@ class Brakeman::Rescanner < Brakeman::Scanner
255
256
  end
256
257
 
257
258
  def rescan_deleted_lib path
259
+ deleted_lib = nil
260
+
258
261
  tracker.libs.delete_if do |name, lib|
259
- lib[:path] == path
262
+ if lib[:file] == path
263
+ deleted_lib = lib
264
+ true
265
+ end
260
266
  end
267
+
268
+ rescan_mixin deleted_lib if deleted_lib
261
269
  end
262
270
 
263
271
  def rescan_deleted_initializer path
@@ -304,6 +312,51 @@ class Brakeman::Rescanner < Brakeman::Scanner
304
312
  :unknown
305
313
  end
306
314
  end
315
+
316
+ def rescan_mixin lib
317
+ method_names = []
318
+
319
+ [:public, :private, :protected].each do |access|
320
+ lib[access].each do |name, meth|
321
+ method_names << name
322
+ end
323
+ end
324
+
325
+ method_matcher = /##{method_names.join('|')}$/
326
+
327
+ #Rescan controllers that mixed in library
328
+ tracker.controllers.each do |name, controller|
329
+ if controller[:includes].include? lib[:name]
330
+ unless @paths.include? controller[:file]
331
+ rescan_file controller[:file]
332
+ end
333
+ end
334
+ end
335
+
336
+ to_rescan = []
337
+
338
+ #Check if a method from this mixin was used to render a template.
339
+ #This is not precise, because a different controller might have the
340
+ #same method...
341
+ tracker.templates.each do |name, template|
342
+ next unless template[:caller]
343
+
344
+ unless template[:caller].grep(method_matcher).empty?
345
+ name.to_s.match /^([^.]+)/
346
+
347
+ original = tracker.templates[$1.to_sym]
348
+
349
+ if original
350
+ to_rescan << [name, original[:file]]
351
+ end
352
+ end
353
+ end
354
+
355
+ to_rescan.each do |template|
356
+ tracker.reset_template template[0]
357
+ rescan_file template[1]
358
+ end
359
+ end
307
360
  end
308
361
 
309
362
  #Class to make reporting of rescan results simpler to deal with
@@ -381,7 +434,7 @@ New warnings: #{new_warnings.length}
381
434
  w["Confidence"] = Brakeman::Report::TEXT_CONFIDENCE[w["Confidence"]]
382
435
 
383
436
  t << [w["Confidence"], w["Class"], w["Method"], w["Warning Type"], w["Message"]]
384
- end
437
+ end
385
438
  end
386
439
  out << truncate_table(table.to_s)
387
440
  end
@@ -84,7 +84,7 @@ class Brakeman::Tracker
84
84
  end
85
85
  end
86
86
 
87
- #Iterates over each template, yielding the name and the template.
87
+ #Iterates over each template, yielding the name and the template.
88
88
  #Prioritizes templates which have been rendered.
89
89
  def each_template
90
90
  if @processed.nil?
@@ -130,7 +130,7 @@ class Brakeman::Tracker
130
130
  def check_initializers target, method
131
131
  finder = Brakeman::FindCall.new target, method, self
132
132
 
133
- initializers.each do |name, initializer|
133
+ initializers.sort.each do |name, initializer|
134
134
  finder.process_source initializer
135
135
  end
136
136
 
@@ -236,6 +236,7 @@ class Brakeman::Tracker
236
236
  @templates.delete name
237
237
  @processed = nil
238
238
  @rest = nil
239
+ @template_cache.clear
239
240
  end
240
241
 
241
242
  #Clear information related to model
@@ -252,6 +253,28 @@ class Brakeman::Tracker
252
253
  @models.delete model_name
253
254
  end
254
255
 
256
+ def reset_controller path
257
+ #Remove from controller
258
+ @controllers.delete_if do |name, controller|
259
+ if controller[:file] == path
260
+ template_matcher = /^#{name}#/
261
+
262
+ #Remove templates rendered from this controller
263
+ @templates.each do |template_name, template|
264
+ if template[:caller] and not template[:caller].grep(template_matcher).empty?
265
+ reset_template template_name
266
+ @call_index.remove_template_indexes template_name
267
+ end
268
+ end
269
+
270
+ #Remove calls indexed from this controller
271
+ @call_index.remove_indexes_by_class [name]
272
+
273
+ true
274
+ end
275
+ end
276
+ end
277
+
255
278
  #Clear information about routes
256
279
  def reset_routes
257
280
  @routes = {}
@@ -1,3 +1,3 @@
1
1
  module Brakeman
2
- Version = "1.8.1"
2
+ Version = "1.8.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brakeman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 8
9
- - 1
10
- version: 1.8.1
9
+ - 2
10
+ version: 1.8.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Collins
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-24 00:00:00 Z
18
+ date: 2012-10-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activesupport
@@ -190,6 +190,7 @@ extra_rdoc_files: []
190
190
 
191
191
  files:
192
192
  - bin/brakeman
193
+ - CHANGES
193
194
  - WARNING_TYPES
194
195
  - FEATURES
195
196
  - README.md