brakeman 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,7 +39,7 @@ To specify an output file for the results:
39
39
 
40
40
  brakeman -o output_file
41
41
 
42
- The output format is determined by the file extension or by using the `-f` option. Current options are: `text`, `html`, `csv`, and `tabs`.
42
+ The output format is determined by the file extension or by using the `-f` option. Current options are: `text`, `html`, `tabs`, `json` and `csv`.
43
43
 
44
44
  To suppress informational warnings and just output the report:
45
45
 
@@ -103,7 +103,7 @@ Brakeman will raise warnings on models that use `attr_protected`. To suppress th
103
103
 
104
104
  # Warning information
105
105
 
106
- See WARNING_TYPES for more information on the warnings reported by this tool.
106
+ See WARNING\_TYPES for more information on the warnings reported by this tool.
107
107
 
108
108
  # Warning context
109
109
 
@@ -140,6 +140,7 @@ The `-c` option can be used to specify a configuration file to use.
140
140
  The MIT License
141
141
 
142
142
  Copyright (c) 2010-2012, YELLOWPAGES.COM, LLC
143
+
143
144
  Copyright (c) 2012, Twitter, Inc.
144
145
 
145
146
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/bin/brakeman CHANGED
@@ -8,6 +8,9 @@ require 'brakeman/version'
8
8
 
9
9
  trap("INT") do
10
10
  $stderr.puts "\nInterrupted - exiting."
11
+ if RUBY_VERSION.include? "1.9"
12
+ $stderr.puts Thread.current.backtrace
13
+ end
11
14
  exit!
12
15
  end
13
16
 
@@ -21,6 +21,7 @@ class Brakeman::BaseCheck < SexpProcessor
21
21
  @string_interp = false
22
22
  @current_set = nil
23
23
  @current_template = @current_module = @current_class = @current_method = nil
24
+ @mass_assign_disabled = nil
24
25
  self.strict = false
25
26
  self.auto_shift_type = false
26
27
  self.require_empty = false
@@ -119,23 +120,42 @@ class Brakeman::BaseCheck < SexpProcessor
119
120
 
120
121
  #Checks if mass assignment is disabled globally in an initializer.
121
122
  def mass_assign_disabled?
123
+ return @mass_assign_disabled unless @mass_assign_disabled.nil?
124
+
125
+ @mass_assign_disabled = false
126
+
122
127
  if version_between?("3.1.0", "4.0.0") and
123
128
  tracker.config[:rails][:active_record] and
124
129
  tracker.config[:rails][:active_record][:whitelist_attributes] == Sexp.new(:true)
125
130
 
126
- return true
131
+ @mass_assign_disabled = true
127
132
  else
128
133
  matches = tracker.check_initializers(:"ActiveRecord::Base", :send)
134
+
129
135
  if matches.empty?
130
- false
136
+ matches = tracker.check_initializers([], :attr_accessible)
137
+
138
+ matches.each do |result|
139
+ if result[1] == :ActiveRecord and result[2] == :Base
140
+ arg = result[-1][3][1]
141
+
142
+ if arg.nil? or node_type? arg, :nil
143
+ @mass_assign_disabled = true
144
+ break
145
+ end
146
+ end
147
+ end
131
148
  else
132
149
  matches.each do |result|
133
- if result[3][3] == Sexp.new(:arg_list, Sexp.new(:lit, :attr_accessible), Sexp.new(:nil))
134
- return true
150
+ if result[-1][3] == Sexp.new(:arglist, Sexp.new(:lit, :attr_accessible), Sexp.new(:nil))
151
+ @mass_assign_disabled = true
152
+ break
135
153
  end
136
154
  end
137
155
  end
138
156
  end
157
+
158
+ @mass_assign_disabled
139
159
  end
140
160
 
141
161
  #This is to avoid reporting duplicates. Checks if the result has been
@@ -54,7 +54,7 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
54
54
  @ignore_methods << :auto_link
55
55
  end
56
56
 
57
- if tracker.config[:rails3]
57
+ if tracker.options[:rails3]
58
58
  @ignore_methods << :select
59
59
  end
60
60
 
@@ -24,6 +24,22 @@ class Brakeman::BaseProcessor < SexpProcessor
24
24
  @current_template = @current_module = @current_class = @current_method = nil
25
25
  end
26
26
 
27
+ def process_class exp
28
+ current_class = @current_class
29
+ @current_class = class_name exp[1]
30
+ process exp[3]
31
+ @current_class = current_class
32
+ exp
33
+ end
34
+
35
+ def process_module exp
36
+ current_module = @current_module
37
+ @current_module = class_name exp[1]
38
+ process exp[2]
39
+ @current_module = current_module
40
+ exp
41
+ end
42
+
27
43
  #Process a new scope. Removes expressions that are set to nil.
28
44
  def process_scope exp
29
45
  exp = exp.dup
@@ -219,8 +235,13 @@ class Brakeman::BaseProcessor < SexpProcessor
219
235
 
220
236
  #Look for render :action, ... or render "action", ...
221
237
  if string? args[1] or symbol? args[1]
222
- type = :action
223
- value = args[1]
238
+ if @current_template and @tracker.options[:rails3]
239
+ type = :partial
240
+ value = args[1]
241
+ else
242
+ type = :action
243
+ value = args[1]
244
+ end
224
245
  elsif args[1].is_a? Symbol or args[1].is_a? String
225
246
  type = :action
226
247
  value = Sexp.new(:lit, args[1].to_sym)
@@ -28,7 +28,7 @@ class Brakeman::ControllerProcessor < Brakeman::BaseProcessor
28
28
 
29
29
  name = class_name(exp[1])
30
30
  if @current_module
31
- name = (@current_module + "::" + name.to_s).to_sym
31
+ name = (@current_module.to_s + "::" + name.to_s).to_sym
32
32
  end
33
33
  @controller = { :name => name,
34
34
  :parent => class_name(exp[2]),
@@ -96,7 +96,7 @@ class Brakeman::FindCall < Brakeman::BaseProcessor
96
96
  if @current_template
97
97
  @calls << Sexp.new(:result, @current_template, exp).line(exp.line)
98
98
  else
99
- @calls << Sexp.new(:result, @current_class, @current_method, exp).line(exp.line)
99
+ @calls << Sexp.new(:result, @current_module, @current_class, @current_method, exp).line(exp.line)
100
100
  end
101
101
 
102
102
  end
@@ -49,6 +49,7 @@ module Brakeman::RenderHelper
49
49
  #Processes a template, adding any instance variables
50
50
  #to its environment.
51
51
  def process_template name, args, called_from = nil
52
+ Brakeman.debug "Rendering #{name} (#{called_from})"
52
53
  #Get scanned source for this template
53
54
  name = name.to_s.gsub(/^\//, "")
54
55
  template = @tracker.templates[name.to_sym]
@@ -229,6 +229,7 @@ class Brakeman::Scanner
229
229
  Brakeman.notify "Processing data flow in controllers..."
230
230
 
231
231
  tracker.controllers.each do |name, controller|
232
+ Brakeman.debug "Processing #{name}"
232
233
  if @report_progress
233
234
  $stderr.print " #{current}/#{total} controllers processed\r"
234
235
  current += 1
@@ -266,6 +267,7 @@ class Brakeman::Scanner
266
267
  total = template_files.length
267
268
 
268
269
  template_files.each do |path|
270
+ Brakeman.debug "Processing #{path}"
269
271
  if @report_progress
270
272
  $stderr.print " #{count}/#{total} files processed\r"
271
273
  count += 1
@@ -280,6 +282,7 @@ class Brakeman::Scanner
280
282
  Brakeman.notify "Processing data flow in templates..."
281
283
 
282
284
  tracker.templates.keys.dup.each do |name|
285
+ Brakeman.debug "Processing #{name}"
283
286
  if @report_progress
284
287
  count += 1
285
288
  $stderr.print " #{count}/#{total} templates processed\r"
@@ -352,6 +355,7 @@ class Brakeman::Scanner
352
355
  current = 0
353
356
 
354
357
  model_files.each do |f|
358
+ Brakeman.debug "Processing #{f}"
355
359
  if @report_progress
356
360
  $stderr.print " #{current}/#{total} files processed\r"
357
361
  current += 1
@@ -448,11 +452,6 @@ class Brakeman::Rails2XSSErubis < ::Erubis::Eruby
448
452
  #src << "@output_buffer = ActiveSupport::SafeBuffer.new;"
449
453
  end
450
454
 
451
- def add_text(src, text)
452
- return if text.empty?
453
- src << "@output_buffer.safe_concat('" << escape_text(text) << "');"
454
- end
455
-
456
455
  #This is different from rails_xss - fixes some line number issues
457
456
  def add_text(src, text)
458
457
  if text == "\n"
@@ -1,3 +1,3 @@
1
1
  module Brakeman
2
- Version = "1.5.0"
2
+ Version = "1.5.1"
3
3
  end
metadata CHANGED
@@ -1,134 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: brakeman
3
- version: !ruby/object:Gem::Version
4
- hash: 3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 5
9
- - 0
10
- version: 1.5.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Justin Collins
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-03-02 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &72282300 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: i18n
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *72282300
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &72282080 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: ruby2ruby
50
34
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *72282080
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby2ruby
38
+ requirement: &72281550 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
40
+ requirements:
54
41
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 11
57
- segments:
58
- - 1
59
- - 2
60
- version: "1.2"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.2'
61
44
  type: :runtime
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: ruport
65
45
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *72281550
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruport
49
+ requirement: &72280450 !ruby/object:Gem::Requirement
67
50
  none: false
68
- requirements:
51
+ requirements:
69
52
  - - ~>
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 1
74
- - 6
75
- version: "1.6"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
76
55
  type: :runtime
77
- version_requirements: *id004
78
- - !ruby/object:Gem::Dependency
79
- name: erubis
80
56
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *72280450
58
+ - !ruby/object:Gem::Dependency
59
+ name: erubis
60
+ requirement: &72280190 !ruby/object:Gem::Requirement
82
61
  none: false
83
- requirements:
62
+ requirements:
84
63
  - - ~>
85
- - !ruby/object:Gem::Version
86
- hash: 15
87
- segments:
88
- - 2
89
- - 6
90
- version: "2.6"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.6'
91
66
  type: :runtime
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: haml
95
67
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *72280190
69
+ - !ruby/object:Gem::Dependency
70
+ name: haml
71
+ requirement: &72279750 !ruby/object:Gem::Requirement
97
72
  none: false
98
- requirements:
73
+ requirements:
99
74
  - - ~>
100
- - !ruby/object:Gem::Version
101
- hash: 7
102
- segments:
103
- - 3
104
- - 0
105
- version: "3.0"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.0'
106
77
  type: :runtime
107
- version_requirements: *id006
108
- - !ruby/object:Gem::Dependency
109
- name: sass
110
78
  prerelease: false
111
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *72279750
80
+ - !ruby/object:Gem::Dependency
81
+ name: sass
82
+ requirement: &72279400 !ruby/object:Gem::Requirement
112
83
  none: false
113
- requirements:
84
+ requirements:
114
85
  - - ~>
115
- - !ruby/object:Gem::Version
116
- hash: 7
117
- segments:
118
- - 3
119
- - 0
120
- version: "3.0"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
121
88
  type: :runtime
122
- version_requirements: *id007
123
- description: Brakeman detects security vulnerabilities in Ruby on Rails applications via static analysis.
89
+ prerelease: false
90
+ version_requirements: *72279400
91
+ description: Brakeman detects security vulnerabilities in Ruby on Rails applications
92
+ via static analysis.
124
93
  email:
125
- executables:
94
+ executables:
126
95
  - brakeman
127
96
  extensions: []
128
-
129
97
  extra_rdoc_files: []
130
-
131
- files:
98
+ files:
132
99
  - bin/brakeman
133
100
  - WARNING_TYPES
134
101
  - FEATURES
@@ -208,36 +175,26 @@ files:
208
175
  - lib/brakeman/format/style.css
209
176
  homepage: http://brakemanscanner.org
210
177
  licenses: []
211
-
212
178
  post_install_message:
213
179
  rdoc_options: []
214
-
215
- require_paths:
180
+ require_paths:
216
181
  - lib
217
- required_ruby_version: !ruby/object:Gem::Requirement
182
+ required_ruby_version: !ruby/object:Gem::Requirement
218
183
  none: false
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- hash: 3
223
- segments:
224
- - 0
225
- version: "0"
226
- required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
227
189
  none: false
228
- requirements:
229
- - - ">="
230
- - !ruby/object:Gem::Version
231
- hash: 3
232
- segments:
233
- - 0
234
- version: "0"
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
235
194
  requirements: []
236
-
237
195
  rubyforge_project:
238
196
  rubygems_version: 1.8.15
239
197
  signing_key:
240
198
  specification_version: 3
241
199
  summary: Security vulnerability scanner for Ruby on Rails.
242
200
  test_files: []
243
-