/
test_rails31.rb
556 lines (491 loc) · 15.2 KB
/
test_rails31.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
62
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
abort "Please run using test/test.rb" unless defined? BrakemanTester
Rails31 = BrakemanTester.run_scan "rails3.1", "Rails 3.1", :rails3 => true
class Rails31Tests < Test::Unit::TestCase
include BrakemanTester::FindWarning
include BrakemanTester::CheckExpected
def report
Rails31
end
def expected
@expected ||= {
:model => 0,
:template => 11,
:controller => 1,
:warning => 44 }
end
def test_without_protection
assert_warning :type => :warning,
:warning_type => "Mass Assignment",
:line => 47,
:message => /^Unprotected mass assignment/,
:confidence => 0,
:file => /users_controller\.rb/
end
def test_redirect_to_model_attribute
assert_warning :type => :warning,
:warning_type => "Redirect",
:line => 98,
:message => /^Possible\ unprotected\ redirect/,
:confidence => 0,
:file => /users_controller\.rb/
end
def test_redirect_with_model_instance
assert_no_warning :type => :warning,
:warning_type => "Redirect",
:line => 67,
:message => /^Possible unprotected redirect/,
:confidence => 2,
:file => /users_controller\.rb/
end
def test_redirect_to_find_by
assert_no_warning :type => :warning,
:warning_type => "Redirect",
:line => 102,
:message => /^Possible\ unprotected\ redirect/,
:confidence => 0,
:file => /users_controller\.rb/
end
def test_whitelist_attributes
assert_no_warning :type => :model,
:warning_type => "Attribute Restriction",
:message => /^Mass assignment is not restricted using attr_accessible/,
:confidence => 0
end
#Such as
#http_basic_authenticate_with :name => "dhh", :password => "secret"
def test_basic_auth_with_password
assert_warning :type => :controller,
:warning_type => "Basic Auth",
:line => 6,
:message => /^Basic authentication password stored in source code/,
:confidence => 0,
:file => /users_controller\.rb/
end
def test_translate_bug
assert_warning :type => :warning,
:warning_type => "Cross Site Scripting",
:message => /^Versions before 3.1.2 have a vulnerability/,
:confidence => 0,
:file => /Gemfile/
end
def test_rails_cve_2012_2660
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:message => /CVE-2012-2660/,
:confidence => 0,
:file => /Gemfile/
end
def test_rails_cve_2012_2661
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:message => /CVE-2012-2661/,
:confidence => 0,
:file => /Gemfile/
end
def test_rails_cve_2012_2695
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:message => /CVE-2012-2695/,
:confidence => 0,
:file => /Gemfile/
end
def test_sql_injection_scope_lambda
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 4,
:message => /^Possible SQL injection near line 4: where/,
:confidence => 0,
:file => /user\.rb/
end
def test_sql_injection_scope
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 10,
:message => /^Possible SQL injection near line 10: scope\(:phooey, :conditions =>/,
:confidence => 0,
:file => /user\.rb/
end
def test_sql_injection_scope_where
assert_no_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 6,
:message => /^Possible SQL injection near line 6: where/,
:confidence => 1,
:file => /user\.rb/
end
def test_sql_injection_scope_lambda_hash
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 8,
:message => /^Possible SQL injection/,
:confidence => 1,
:file => /user\.rb/
end
def test_sql_injection_scope_multiline_lambda_where
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 22,
:message => /^Possible\ SQL\ injection/,
:confidence => 1,
:file => /user\.rb/
end
def test_sql_injection_in_order_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 4,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /user\.rb/
end
def test_sql_injection_in_group_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 10,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_group_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 11,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_lock_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 67,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_lock_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 68,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_having
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 16,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_having_array
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 25,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_joins
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 34,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_joins_array
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 40,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_order_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 4,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_order
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 5,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_select_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 48,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_select
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 49,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_from_param
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 58,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_from
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 59,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_local_interpolation
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 93,
:message => /^Possible\ SQL\ injection/,
:confidence => 1,
:file => /product\.rb/
end
def test_sql_injection_interpolated_where
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 80,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_interpolated_where_array
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 81,
:message => /^Possible\ SQL\ injection/,
:confidence => 1,
:file => /product\.rb/
end
def test_sql_injection_string_concat_select
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 50,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_string_concat_having
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 26,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_with_conditional
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 98,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_method_args
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 106,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_with_if_statements
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 130,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_calculate
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 139,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_minimum
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 140,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_maximum
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 141,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_average
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 142,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_sum
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 143,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_sql_injection_in_select
assert_warning :type => :warning,
:warning_type => "SQL Injection",
:line => 151,
:message => /^Possible\ SQL\ injection/,
:confidence => 0,
:file => /product\.rb/
end
def test_select_vulnerability
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 2,
:message => /^Upgrade to Rails 3.1.4, 3.1.0 select\(\) helper is vulnerable/,
:confidence => 1,
:file => /edit\.html\.erb/
end
def test_string_buffer_manipulation_bug
assert_warning :type => :warning,
:warning_type => "Cross Site Scripting",
:message => /^Rails 3.1.0 has a vulnerabilty in SafeBuffer. Upgrade to 3.1.4/,
:confidence => 1,
:file => /Gemfile/
end
def test_cross_site_request_forgery
assert_warning :type => :warning,
:warning_type => "Cross-Site Request Forgery",
:line => 93,
:message => /^Use\ whitelist\ \(:only\ =>\ \[\.\.\]\)\ when\ skipp/,
:confidence => 1,
:file => /users_controller\.rb/
end
def test_controller_mixin
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped parameter value near line 1: params\[:bad\]/,
:confidence => 0,
:file => /users\/mixin_template\.html\.erb/
end
def test_controller_mixin_default_render
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped parameter value near line 1: params\[:bad\]/,
:confidence => 0,
:file => /users\/mixin_default\.html\.erb/
end
def test_get_in_resources_block
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/a\.html\.erb/
end
def test_get_in_controller_block
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/b\.html\.erb/
end
def test_post_with_just_hash_in_controller_block
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/c\.html\.erb/
end
def test_put_to_in_controller_block
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/d\.html\.erb/
end
def test_match_to_route
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/e\.html\.erb/
end
def test_delete_in_resources_block
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/f\.html\.erb/
end
def test_route_hash_shorthand
assert_warning :type => :template,
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:file => /\/g\.html\.erb/
end
def test_file_access_indirect_user_input
assert_warning :type => :warning,
:warning_type => "File Access",
:line => 106,
:message => /^Parameter\ value\ used\ in\ file\ name/,
:confidence => 2,
:file => /users_controller\.rb/
end
def test_file_access_in_string_interpolation
assert_warning :type => :warning,
:warning_type => "File Access",
:line => 107,
:message => /^Cookie\ value\ used\ in\ file\ name/,
:confidence => 0,
:file => /users_controller\.rb/
end
def test_file_access_direct_user_input
assert_warning :type => :warning,
:warning_type => "File Access",
:line => 108,
:message => /^Parameter\ value\ used\ in\ file\ name/,
:confidence => 0,
:file => /users_controller\.rb/
end
def test_file_access_model_attribute
assert_warning :type => :warning,
:warning_type => "File Access",
:line => 109,
:message => /^Model attribute\ value\ used\ in\ file\ name/,
:confidence => 1,
:file => /users_controller\.rb/
end
end