brakeman-min 4.3.1 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +24 -1
  3. data/README.md +35 -6
  4. data/bin/brakeman +2 -0
  5. data/lib/brakeman.rb +5 -3
  6. data/lib/brakeman/app_tree.rb +15 -1
  7. data/lib/brakeman/call_index.rb +7 -4
  8. data/lib/brakeman/checks.rb +16 -8
  9. data/lib/brakeman/checks/base_check.rb +2 -19
  10. data/lib/brakeman/checks/check_basic_auth_timing_attack.rb +1 -1
  11. data/lib/brakeman/checks/check_content_tag.rb +4 -4
  12. data/lib/brakeman/checks/check_create_with.rb +1 -1
  13. data/lib/brakeman/checks/check_cross_site_scripting.rb +3 -3
  14. data/lib/brakeman/checks/check_default_routes.rb +3 -3
  15. data/lib/brakeman/checks/check_deserialize.rb +1 -1
  16. data/lib/brakeman/checks/check_detailed_exceptions.rb +1 -1
  17. data/lib/brakeman/checks/check_digest_dos.rb +4 -4
  18. data/lib/brakeman/checks/check_escape_function.rb +1 -1
  19. data/lib/brakeman/checks/check_execute.rb +5 -4
  20. data/lib/brakeman/checks/check_file_access.rb +13 -3
  21. data/lib/brakeman/checks/check_file_disclosure.rb +1 -1
  22. data/lib/brakeman/checks/check_filter_skipping.rb +1 -1
  23. data/lib/brakeman/checks/check_forgery_setting.rb +3 -3
  24. data/lib/brakeman/checks/check_header_dos.rb +3 -3
  25. data/lib/brakeman/checks/check_i18n_xss.rb +3 -3
  26. data/lib/brakeman/checks/check_jruby_xml.rb +1 -1
  27. data/lib/brakeman/checks/check_json_encoding.rb +3 -3
  28. data/lib/brakeman/checks/check_json_parsing.rb +8 -11
  29. data/lib/brakeman/checks/check_link_to.rb +3 -3
  30. data/lib/brakeman/checks/check_link_to_href.rb +2 -2
  31. data/lib/brakeman/checks/check_mail_to.rb +3 -3
  32. data/lib/brakeman/checks/check_mime_type_dos.rb +1 -1
  33. data/lib/brakeman/checks/check_model_attributes.rb +4 -4
  34. data/lib/brakeman/checks/check_model_serialize.rb +1 -1
  35. data/lib/brakeman/checks/check_nested_attributes.rb +3 -3
  36. data/lib/brakeman/checks/check_nested_attributes_bypass.rb +1 -1
  37. data/lib/brakeman/checks/check_number_to_currency.rb +4 -4
  38. data/lib/brakeman/checks/check_quote_table_name.rb +2 -2
  39. data/lib/brakeman/checks/check_regex_dos.rb +1 -1
  40. data/lib/brakeman/checks/check_render.rb +2 -2
  41. data/lib/brakeman/checks/check_render_dos.rb +1 -1
  42. data/lib/brakeman/checks/check_render_inline.rb +1 -1
  43. data/lib/brakeman/checks/check_response_splitting.rb +1 -1
  44. data/lib/brakeman/checks/check_route_dos.rb +1 -1
  45. data/lib/brakeman/checks/check_safe_buffer_manipulation.rb +1 -1
  46. data/lib/brakeman/checks/check_sanitize_methods.rb +3 -3
  47. data/lib/brakeman/checks/check_secrets.rb +1 -1
  48. data/lib/brakeman/checks/check_select_tag.rb +1 -1
  49. data/lib/brakeman/checks/check_select_vulnerability.rb +1 -1
  50. data/lib/brakeman/checks/check_session_manipulation.rb +1 -1
  51. data/lib/brakeman/checks/check_session_settings.rb +1 -1
  52. data/lib/brakeman/checks/check_simple_format.rb +2 -2
  53. data/lib/brakeman/checks/check_single_quotes.rb +14 -10
  54. data/lib/brakeman/checks/check_skip_before_filter.rb +2 -2
  55. data/lib/brakeman/checks/check_sprockets_path_traversal.rb +39 -0
  56. data/lib/brakeman/checks/check_sql.rb +1 -1
  57. data/lib/brakeman/checks/check_sql_cves.rb +2 -2
  58. data/lib/brakeman/checks/check_strip_tags.rb +10 -8
  59. data/lib/brakeman/checks/check_symbol_dos.rb +1 -1
  60. data/lib/brakeman/checks/check_symbol_dos_cve.rb +1 -1
  61. data/lib/brakeman/checks/check_translate_bug.rb +7 -7
  62. data/lib/brakeman/checks/check_unsafe_reflection.rb +1 -1
  63. data/lib/brakeman/checks/check_unscoped_find.rb +1 -1
  64. data/lib/brakeman/checks/check_validation_regex.rb +1 -1
  65. data/lib/brakeman/checks/check_weak_hash.rb +18 -19
  66. data/lib/brakeman/checks/check_xml_dos.rb +1 -1
  67. data/lib/brakeman/checks/check_yaml_parsing.rb +1 -1
  68. data/lib/brakeman/format/style.css +8 -0
  69. data/lib/brakeman/messages.rb +220 -0
  70. data/lib/brakeman/options.rb +13 -0
  71. data/lib/brakeman/parsers/template_parser.rb +2 -2
  72. data/lib/brakeman/processors/alias_processor.rb +7 -0
  73. data/lib/brakeman/processors/config_processor.rb +4 -1
  74. data/lib/brakeman/processors/gem_processor.rb +30 -2
  75. data/lib/brakeman/processors/lib/call_conversion_helper.rb +2 -1
  76. data/lib/brakeman/processors/lib/rails3_route_processor.rb +0 -2
  77. data/lib/brakeman/processors/lib/rails4_config_processor.rb +18 -0
  78. data/lib/brakeman/processors/lib/render_helper.rb +5 -0
  79. data/lib/brakeman/processors/lib/render_path.rb +15 -0
  80. data/lib/brakeman/processors/library_processor.rb +1 -1
  81. data/lib/brakeman/report/report_base.rb +17 -161
  82. data/lib/brakeman/report/report_csv.rb +17 -0
  83. data/lib/brakeman/report/report_html.rb +34 -31
  84. data/lib/brakeman/report/report_json.rb +21 -0
  85. data/lib/brakeman/report/report_markdown.rb +13 -6
  86. data/lib/brakeman/report/report_table.rb +157 -0
  87. data/lib/brakeman/report/report_tabs.rb +3 -1
  88. data/lib/brakeman/report/report_text.rb +16 -0
  89. data/lib/brakeman/scanner.rb +5 -1
  90. data/lib/brakeman/tracker/config.rb +1 -1
  91. data/lib/brakeman/util.rb +0 -17
  92. data/lib/brakeman/version.rb +1 -1
  93. data/lib/brakeman/warning.rb +9 -4
  94. data/lib/brakeman/warning_codes.rb +1 -0
  95. metadata +9 -6
@@ -25,7 +25,7 @@ class Brakeman::CheckRenderDoS < Brakeman::BaseCheck
25
25
  end
26
26
 
27
27
  def warn_about_text_render
28
- message = "Rails #{rails_version} has a denial of service vulnerability (CVE-2014-0082). Upgrade to Rails version 3.2.17"
28
+ message = msg(msg_version(rails_version), " has a denial of service vulnerability ", msg_cve("CVE-2014-0082"), ". Upgrade to ", msg_version("3.2.17"))
29
29
 
30
30
  warn :warning_type => "Denial of Service",
31
31
  :warning_code => :CVE_2014_0082,
@@ -26,7 +26,7 @@ class Brakeman::CheckRenderInline < Brakeman::CheckCrossSiteScripting
26
26
  warn :result => result,
27
27
  :warning_type => "Cross-Site Scripting",
28
28
  :warning_code => :cross_site_scripting_inline,
29
- :message => "Unescaped #{friendly_type_of input} rendered inline",
29
+ :message => msg("Unescaped ", msg_input(input), " rendered inline"),
30
30
  :user_input => input,
31
31
  :confidence => :high
32
32
  elsif input = has_immediate_model?(render_value)
@@ -12,7 +12,7 @@ class Brakeman::CheckResponseSplitting < Brakeman::BaseCheck
12
12
 
13
13
  warn :warning_type => "Response Splitting",
14
14
  :warning_code => :CVE_2011_3186,
15
- :message => "Versions before 2.3.14 have a vulnerability content type handling allowing injection of headers: CVE-2011-3186",
15
+ :message => msg("Rails versions before 2.3.14 have a vulnerability content type handling allowing injection of headers ", msg_cve("CVE-2011-3186")),
16
16
  :confidence => :medium,
17
17
  :gem_info => gemfile_or_environment,
18
18
  :link_path => "https://groups.google.com/d/topic/rubyonrails-security/b_yTveAph2g/discussion"
@@ -16,7 +16,7 @@ class Brakeman::CheckRouteDoS < Brakeman::BaseCheck
16
16
  end
17
17
 
18
18
  if controller_wildcards?
19
- message = "Rails #{rails_version} has a denial of service vulnerability with :controller routes (CVE-2015-7581). Upgrade to Rails #{fix_version}"
19
+ message = msg(msg_version(rails_version), " has a denial of service vulnerability with ", msg_code(":controller"), " routes ", msg_cve("CVE-2015-7581"), ". Upgrade to ", msg_version(fix_version))
20
20
 
21
21
  warn :warning_type => "Denial of Service",
22
22
  :warning_code => :CVE_2015_7581,
@@ -20,7 +20,7 @@ class Brakeman::CheckSafeBufferManipulation < Brakeman::BaseCheck
20
20
  return
21
21
  end
22
22
 
23
- message = "Rails #{rails_version} has a vulnerabilty in SafeBuffer. Upgrade to #{suggested_version} or apply patches."
23
+ message = msg(msg_version(rails_version), " has a vulnerability in ", msg_code("SafeBuffer"), ". Upgrade to ", msg_version(suggested_version), " or apply patches")
24
24
 
25
25
  warn :warning_type => "Cross-Site Scripting",
26
26
  :warning_code => :safe_buffer_vuln,
@@ -44,7 +44,7 @@ class Brakeman::CheckSanitizeMethods < Brakeman::BaseCheck
44
44
  next if duplicate? result
45
45
  add_result result
46
46
 
47
- message = "Rails #{rails_version} has a vulnerability in #{method}: upgrade to #{@fix_version} or patch"
47
+ message = msg(msg_version(rails_version), " has a vulnerability in ", msg_code(method), ". Upgrade to ", msg_version(@fix_version), " or patch")
48
48
 
49
49
  warn :result => result,
50
50
  :warning_type => "Cross-Site Scripting",
@@ -70,7 +70,7 @@ class Brakeman::CheckSanitizeMethods < Brakeman::BaseCheck
70
70
 
71
71
  def check_cve_2018_8048
72
72
  if loofah_vulnerable_cve_2018_8048?
73
- message = "Loofah #{tracker.config.gem_version(:loofah)} is vulnerable (CVE-2018-8048). Upgrade to 2.1.2"
73
+ message = msg(msg_version(tracker.config.gem_version(:loofah), "loofah gem"), " is vulnerable (CVE-2018-8048). Upgrade to 2.1.2")
74
74
 
75
75
  if tracker.find_call(:target => false, :method => :sanitize).any?
76
76
  confidence = :high
@@ -94,7 +94,7 @@ class Brakeman::CheckSanitizeMethods < Brakeman::BaseCheck
94
94
  end
95
95
 
96
96
  def warn_sanitizer_cve cve, link, upgrade_version
97
- message = "rails-html-sanitizer #{tracker.config.gem_version(:'rails-html-sanitizer')} is vulnerable (#{cve}). Upgrade to #{upgrade_version}"
97
+ message = msg(msg_version(tracker.config.gem_version(:'rails-html-sanitizer'), "rails-html-sanitizer"), " is vulnerable ", msg_cve(cve), ". Upgrade to ", msg_version(upgrade_version, "rails-html-sanitizer"))
98
98
 
99
99
  if tracker.find_call(:target => false, :method => :sanitize).any?
100
100
  confidence = :high
@@ -24,7 +24,7 @@ class Brakeman::CheckSecrets < Brakeman::BaseCheck
24
24
 
25
25
  warn :warning_code => :secret_in_source,
26
26
  :warning_type => "Authentication",
27
- :message => "Hardcoded value for #{name} in source code",
27
+ :message => msg("Hardcoded value for ", msg_code(name), " in source code"),
28
28
  :confidence => :medium,
29
29
  :file => constant.file,
30
30
  :line => constant.line
@@ -21,7 +21,7 @@ class Brakeman::CheckSelectTag < Brakeman::BaseCheck
21
21
 
22
22
  @ignore_methods = Set[:escapeHTML, :escape_once, :h].merge tracker.options[:safe_methods]
23
23
 
24
- @message = "Upgrade to Rails #{suggested_version}, #{rails_version} select_tag is vulnerable (CVE-2012-3463)"
24
+ @message = msg("Upgrade to ", msg_version(suggested_version), ". In ", msg_version(rails_version), " ", msg_code("select_tag"), " is vulnerable ", msg_cve("CVE-2012-3463"))
25
25
 
26
26
  calls = tracker.find_call(:target => nil, :method => :select_tag).select do |result|
27
27
  result[:location][:type] == :template
@@ -23,7 +23,7 @@ class Brakeman::CheckSelectVulnerability < Brakeman::BaseCheck
23
23
  return
24
24
  end
25
25
 
26
- @message = "Upgrade to Rails #{suggested_version}, #{rails_version} select() helper is vulnerable"
26
+ @message = msg("Upgrade to ", msg_version(suggested_version), ". In ", msg_version(rails_version), " ", msg_code("select"), " helper is vulnerable")
27
27
 
28
28
  calls = tracker.find_call(:target => nil, :method => :select).select do |result|
29
29
  result[:location][:type] == :template
@@ -26,7 +26,7 @@ class Brakeman::CheckSessionManipulation < Brakeman::BaseCheck
26
26
  warn :result => result,
27
27
  :warning_type => "Session Manipulation",
28
28
  :warning_code => :session_key_manipulation,
29
- :message => "#{friendly_type_of(input).capitalize} used as key in session hash",
29
+ :message => msg(msg_input(input), " used as key in session hash"),
30
30
  :code => result[:call],
31
31
  :user_input => input,
32
32
  :confidence => confidence
@@ -123,7 +123,7 @@ class Brakeman::CheckSessionSettings < Brakeman::BaseCheck
123
123
  return
124
124
  end
125
125
 
126
- if secrets["production"] and secret = secrets["production"]["secret_key_base"]
126
+ if secrets && secrets["production"] and secret = secrets["production"]["secret_key_base"]
127
127
  unless secret.include? "<%="
128
128
  line = yaml.lines.find_index { |l| l.include? secret } + 1
129
129
 
@@ -16,7 +16,7 @@ class Brakeman::CheckSimpleFormat < Brakeman::CheckCrossSiteScripting
16
16
  end
17
17
 
18
18
  def generic_warning
19
- message = "Rails #{rails_version} has a vulnerability in simple_format (CVE-2013-6416). Upgrade to Rails version 4.0.2"
19
+ message = msg(msg_version(rails_version), " has a vulnerability in ", msg_code("simple_format"), " ", msg_cve("CVE-2013-6416"), ". Upgrade to ", msg_version("4.0.2"))
20
20
 
21
21
  warn :warning_type => "Cross-Site Scripting",
22
22
  :warning_code => :CVE_2013_6416,
@@ -50,7 +50,7 @@ class Brakeman::CheckSimpleFormat < Brakeman::CheckCrossSiteScripting
50
50
  warn :result => result,
51
51
  :warning_type => "Cross-Site Scripting",
52
52
  :warning_code => :CVE_2013_6416_call,
53
- :message => "Values passed to simple_format are not safe in Rails #{rails_version}",
53
+ :message => msg("Values passed to ", msg_code("simple_format"), " are not safe in ", msg_version(rails_version)),
54
54
  :confidence => :high,
55
55
  :link_path => "https://groups.google.com/d/msg/ruby-security-ann/5ZI1-H5OoIM/ZNq4FoR2GnIJ",
56
56
  :user_input => match
@@ -16,17 +16,21 @@ class Brakeman::CheckSingleQuotes < Brakeman::BaseCheck
16
16
  def run_check
17
17
  return if uses_rack_escape?
18
18
 
19
- case
20
- when version_between?('2.0.0', '2.3.14')
21
- message = "All Rails 2.x versions do not escape single quotes (CVE-2012-3464)"
22
- when version_between?('3.0.0', '3.0.16')
23
- message = "Rails #{rails_version} does not escape single quotes (CVE-2012-3464). Upgrade to 3.0.17"
24
- when version_between?('3.1.0', '3.1.7')
25
- message = "Rails #{rails_version} does not escape single quotes (CVE-2012-3464). Upgrade to 3.1.8"
26
- when version_between?('3.2.0', '3.2.7')
27
- message = "Rails #{rails_version} does not escape single quotes (CVE-2012-3464). Upgrade to 3.2.8"
19
+ if version_between? '2.0.0', '2.3.14'
20
+ message = msg("All Rails 2.x versions do not escape single quotes ", msg_cve("CVE-2012-3464"))
28
21
  else
29
- return
22
+ message = msg(msg_version(rails_version), " does not escape single quotes ", msg_cve("CVE-2012-3464"), ". Upgrade to ")
23
+
24
+ case
25
+ when version_between?('3.0.0', '3.0.16')
26
+ message << msg_version('3.0.17')
27
+ when version_between?('3.1.0', '3.1.7')
28
+ message << msg_version('3.1.8')
29
+ when version_between?('3.2.0', '3.2.7')
30
+ message << msg_version('3.2.8')
31
+ else
32
+ return
33
+ end
30
34
  end
31
35
 
32
36
  warn :warning_type => "Cross-Site Scripting",
@@ -26,7 +26,7 @@ class Brakeman::CheckSkipBeforeFilter < Brakeman::BaseCheck
26
26
  warn :class => controller.name, #ugh this should be a controller warning, too
27
27
  :warning_type => "Cross-Site Request Forgery",
28
28
  :warning_code => :csrf_blacklist,
29
- :message => "Use whitelist (:only => [..]) when skipping CSRF check",
29
+ :message => msg("Use whitelist (", msg_code(":only => [..]"), ") when skipping CSRF check"),
30
30
  :code => filter,
31
31
  :confidence => :medium,
32
32
  :file => controller.file
@@ -35,7 +35,7 @@ class Brakeman::CheckSkipBeforeFilter < Brakeman::BaseCheck
35
35
  warn :controller => controller.name,
36
36
  :warning_code => :auth_blacklist,
37
37
  :warning_type => "Authentication",
38
- :message => "Use whitelist (:only => [..]) when skipping authentication",
38
+ :message => msg("Use whitelist (", msg_code(":only => [..]"), ") when skipping authentication"),
39
39
  :code => filter,
40
40
  :confidence => :medium,
41
41
  :link => "authentication_whitelist",
@@ -0,0 +1,39 @@
1
+ class Brakeman::CheckSprocketsPathTraversal < Brakeman::BaseCheck
2
+ Brakeman::Checks.add self
3
+
4
+ @description = "Checks for CVE-2018-3760"
5
+
6
+ def run_check
7
+ sprockets_version = tracker.config.gem_version(:sprockets)
8
+
9
+ return unless sprockets_version
10
+ return if has_workaround?
11
+
12
+ case
13
+ when version_between?("0.0.0", "2.12.4", sprockets_version)
14
+ upgrade_version = "2.12.5"
15
+ confidence = :weak
16
+ when version_between?("3.0.0", "3.7.1", sprockets_version)
17
+ upgrade_version = "3.7.2"
18
+ confidence = :high
19
+ when version_between?("4.0.0.beta1", "4.0.0.beta7", sprockets_version)
20
+ upgrade_version = "4.0.0.beta8"
21
+ confidence = :high
22
+ else
23
+ return
24
+ end
25
+
26
+ message = msg(msg_version(sprockets_version, "sprockets"), " has a path traversal vulnerability ", msg_cve("CVE-2018-3760"), ". Upgrade to ", msg_version(upgrade_version, "sprockets"), " or newer")
27
+
28
+ warn :warning_type => "Path Traversal",
29
+ :warning_code => :CVE_2018_3760,
30
+ :message => message,
31
+ :confidence => confidence,
32
+ :gem_info => gemfile_or_environment(:sprockets),
33
+ :link_path => "https://groups.google.com/d/msg/rubyonrails-security/ft_J--l55fM/7roDfQ50BwAJ"
34
+ end
35
+
36
+ def has_workaround?
37
+ false? (tracker.config.rails[:assets] and tracker.config.rails[:assets][:compile])
38
+ end
39
+ end
@@ -247,7 +247,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
247
247
  warn :result => result,
248
248
  :warning_type => "SQL Injection",
249
249
  :warning_code => :sql_injection_limit_offset,
250
- :message => "Upgrade to Rails >= 2.1.2 to escape :limit and :offset. Possible SQL injection",
250
+ :message => msg("Upgrade to Rails >= 2.1.2 to escape ", msg_code(":limit"), " and ", msg_code("offset"), ". Possible SQL injection"),
251
251
  :confidence => confidence
252
252
  end
253
253
  end
@@ -78,7 +78,7 @@ class Brakeman::CheckSQLCVEs < Brakeman::BaseCheck
78
78
 
79
79
  warn :warning_type => 'SQL Injection',
80
80
  :warning_code => code,
81
- :message => "Rails #{rails_version} contains a SQL injection vulnerability (#{cve}). Upgrade to #{upgrade_version}",
81
+ :message => msg(msg_version(rails_version), " contains a SQL injection vulnerability ", msg_cve(cve), ". Upgrade to ", msg_version(upgrade_version)),
82
82
  :confidence => :high,
83
83
  :gem_info => gemfile_or_environment,
84
84
  :link_path => link
@@ -98,7 +98,7 @@ class Brakeman::CheckSQLCVEs < Brakeman::BaseCheck
98
98
 
99
99
  warn :warning_type => 'SQL Injection',
100
100
  :warning_code => :CVE_2014_0080,
101
- :message => "Rails #{rails_version} contains a SQL injection vulnerability (CVE-2014-0080) with PostgreSQL. Upgrade to 4.0.3",
101
+ :message => msg(msg_version(rails_version), " contains a SQL injection vulnerability ", msg_cve("CVE-2014-0080"), " with PostgreSQL. Upgrade to ", msg_version("4.0.3")),
102
102
  :confidence => :high,
103
103
  :gem_info => gemfile_or_environment(:pg),
104
104
  :link_path => "https://groups.google.com/d/msg/rubyonrails-security/Wu96YkTUR6s/pPLBMZrlwvYJ"
@@ -25,9 +25,9 @@ class Brakeman::CheckStripTags < Brakeman::BaseCheck
25
25
  def cve_2011_2931
26
26
  if version_between?('2.0.0', '2.3.12') or version_between?('3.0.0', '3.0.9')
27
27
  if rails_version =~ /^3/
28
- message = "Versions before 3.0.10 have a vulnerability in strip_tags (CVE-2011-2931)"
28
+ message = msg("Versions before 3.0.10 have a vulnerability in ", msg_code("strip_tags"), " ", msg_cve("CVE-2011-2931"))
29
29
  else
30
- message = "Versions before 2.3.13 have a vulnerability in strip_tags (CVE-2011-2931)"
30
+ message = msg("Versions before 2.3.13 have a vulnerability in ", msg_code("strip_tags"), " ", msg_cve("CVE-2011-2931"))
31
31
  end
32
32
 
33
33
  warn :warning_type => "Cross-Site Scripting",
@@ -40,15 +40,17 @@ class Brakeman::CheckStripTags < Brakeman::BaseCheck
40
40
  end
41
41
 
42
42
  def cve_2012_3465
43
+ message = msg(msg_version(rails_version), " has a vulnerability in ", msg_code("strip_tags"), " ", msg_cve("CVE-2012-3465"), ". Upgrade to ")
44
+
43
45
  case
44
46
  when (version_between?('2.0.0', '2.3.14') and tracker.config.escape_html?)
45
- message = "All Rails 2.x versions have a vulnerability in strip_tags (CVE-2012-3465)"
47
+ message = msg("All Rails 2.x versions have a vulnerability in ", msg_code("strip_tags"), " ", msg_cve("CVE-2012-3465"))
46
48
  when version_between?('3.0.10', '3.0.16')
47
- message = "Rails #{rails_version} has a vulnerability in strip_tags (CVE-2012-3465). Upgrade to 3.0.17"
49
+ message << msg_version('3.0.17')
48
50
  when version_between?('3.1.0', '3.1.7')
49
- message = "Rails #{rails_version} has a vulnerability in strip_tags (CVE-2012-3465). Upgrade to 3.1.8"
51
+ message << msg_version('3.1.8')
50
52
  when version_between?('3.2.0', '3.2.7')
51
- message = "Rails #{rails_version} has a vulnerability in strip_tags (CVE-2012-3465). Upgrade to 3.2.8"
53
+ message << msg_version('3.2.8')
52
54
  else
53
55
  return
54
56
  end
@@ -69,13 +71,13 @@ class Brakeman::CheckStripTags < Brakeman::BaseCheck
69
71
  confidence = :medium
70
72
  end
71
73
 
72
- message = "rails-html-sanitizer 1.0.2 is vulnerable (CVE-2015-7579). Upgrade to 1.0.3"
74
+ message = msg(msg_version("1.0.2", "rails-html-sanitizer"), " is vulnerable (CVE-2015-7579). Upgrade to ", msg_version("1.0.3", "rails-html-sanitizer"))
73
75
 
74
76
  warn :warning_type => "Cross-Site Scripting",
75
77
  :warning_code => :CVE_2015_7579,
76
78
  :message => message,
77
79
  :confidence => confidence,
78
- :gem_info => gemfile_or_environment,
80
+ :gem_info => gemfile_or_environment(:"rails-html-sanitizer"),
79
81
  :link_path => "https://groups.google.com/d/msg/rubyonrails-security/OU9ugTZcbjc/PjEP46pbFQAJ"
80
82
 
81
83
  end
@@ -38,7 +38,7 @@ class Brakeman::CheckSymbolDoS < Brakeman::BaseCheck
38
38
  return if safe_parameter? input.match
39
39
  return if symbolizing_attributes? input
40
40
 
41
- message = "Symbol conversion from unsafe string (#{friendly_type_of input})"
41
+ message = msg("Symbol conversion from unsafe string in ", msg_input(input))
42
42
 
43
43
  warn :result => result,
44
44
  :warning_type => "Denial of Service",
@@ -20,7 +20,7 @@ class Brakeman::CheckSymbolDoSCVE < Brakeman::BaseCheck
20
20
  if fix_version && active_record_models.any?
21
21
  warn :warning_type => "Denial of Service",
22
22
  :warning_code => :CVE_2013_1854,
23
- :message => "Rails #{rails_version} has a denial of service vulnerability in ActiveRecord: upgrade to #{fix_version} or patch",
23
+ :message => msg(msg_version(rails_version), " has a denial of service vulnerability in ActiveRecord. Upgrade to ", msg_version(fix_version), " or patch"),
24
24
  :confidence => :medium,
25
25
  :gem_info => gemfile_or_environment,
26
26
  :link => "https://groups.google.com/d/msg/rubyonrails-security/jgJ4cjjS8FE/BGbHRxnDRTIJ"
@@ -18,15 +18,15 @@ class Brakeman::CheckTranslateBug < Brakeman::BaseCheck
18
18
  :medium
19
19
  end
20
20
 
21
- description = "have a vulnerability in the translate helper with keys ending in _html"
21
+ description = [" has a vulnerability in the translate helper with keys ending in ", msg_code("_html")]
22
22
 
23
23
  message = if rails_version =~ /^3\.1/
24
- "Versions before 3.1.2 #{description}."
25
- elsif rails_version =~ /^3\.0/
26
- "Versions before 3.0.11 #{description}."
27
- else
28
- "Rails 2.3.x using the rails_xss plugin #{description}."
29
- end
24
+ msg(msg_version(rails_version), *description, ". Upgrade to ", msg_version("3.1.2"))
25
+ elsif rails_version =~ /^3\.0/
26
+ msg(msg_version(rails_version), *description, ". Upgrade to ", msg_version("3.0.11"))
27
+ else
28
+ msg("Rails 2.3.x using the rails_xss plugin", *description)
29
+ end
30
30
 
31
31
  warn :warning_type => "Cross-Site Scripting",
32
32
  :warning_code => :translate_vuln,
@@ -37,7 +37,7 @@ class Brakeman::CheckUnsafeReflection < Brakeman::BaseCheck
37
37
  end
38
38
 
39
39
  if confidence
40
- message = "Unsafe reflection method #{method} called with #{friendly_type_of input}"
40
+ message = msg("Unsafe reflection method ", msg_code(method), " called with ", msg_input(input))
41
41
 
42
42
  warn :result => result,
43
43
  :warning_type => "Remote Code Execution",
@@ -37,7 +37,7 @@ class Brakeman::CheckUnscopedFind < Brakeman::BaseCheck
37
37
  warn :result => result,
38
38
  :warning_type => "Unscoped Find",
39
39
  :warning_code => :unscoped_find,
40
- :message => "Unscoped call to #{result[:target]}##{result[:method]}",
40
+ :message => msg("Unscoped call to ", msg_code("#{result[:target]}##{result[:method]}")),
41
41
  :code => result[:call],
42
42
  :confidence => :weak,
43
43
  :user_input => input
@@ -89,7 +89,7 @@ class Brakeman::CheckValidationRegex < Brakeman::BaseCheck
89
89
  warn :model => @current_model,
90
90
  :warning_type => "Format Validation",
91
91
  :warning_code => :validation_regex,
92
- :message => "Insufficient validation for '#{get_name validator}' using #{regex.inspect}. Use \\A and \\z as anchors",
92
+ :message => msg("Insufficient validation for ", msg_code(get_name validator), " using ", msg_code(regex.inspect), ". Use ", msg_code("\\A"), " and ", msg_code("\\z"), " as anchors"),
93
93
  :line => value.line,
94
94
  :confidence => :high
95
95
  end
@@ -39,20 +39,19 @@ class Brakeman::CheckWeakHash < Brakeman::BaseCheck
39
39
  confidence = :medium
40
40
  end
41
41
 
42
+ message = msg("Weak hashing algorithm used")
42
43
 
43
- alg = case call.target.last
44
- when :MD5
45
- " (MD5)"
46
- when :SHA1
47
- " (SHA1)"
48
- else
49
- ""
50
- end
44
+ case call.target.last
45
+ when :MD5
46
+ message << ": " << msg_lit("MD5")
47
+ when :SHA1
48
+ message << ": " << msg_lit("SHA1")
49
+ end
51
50
 
52
51
  warn :result => result,
53
52
  :warning_type => "Weak Hash",
54
53
  :warning_code => :weak_hash_digest,
55
- :message => "Weak hashing algorithm#{alg} used",
54
+ :message => message,
56
55
  :confidence => confidence,
57
56
  :user_input => input
58
57
  end
@@ -62,19 +61,19 @@ class Brakeman::CheckWeakHash < Brakeman::BaseCheck
62
61
 
63
62
  call = result[:call]
64
63
 
65
- alg = case call.third_arg.last
66
- when :MD5
67
- 'MD5'
68
- when :SHA1
69
- 'SHA1'
70
- else
71
- return
72
- end
64
+ message = msg("Weak hashing algorithm used in HMAC")
65
+
66
+ case call.third_arg.last
67
+ when :MD5
68
+ message << ": " << msg_lit("MD5")
69
+ when :SHA1
70
+ message << ": " << msg_lit("SHA1")
71
+ end
73
72
 
74
73
  warn :result => result,
75
74
  :warning_type => "Weak Hash",
76
75
  :warning_code => :weak_hash_hmac,
77
- :message => "Weak hashing algorithm (#{alg}) used in HMAC",
76
+ :message => message,
78
77
  :confidence => :medium
79
78
  end
80
79
 
@@ -90,7 +89,7 @@ class Brakeman::CheckWeakHash < Brakeman::BaseCheck
90
89
  warn :result => result,
91
90
  :warning_type => "Weak Hash",
92
91
  :warning_code => :weak_hash_digest,
93
- :message => "Weak hashing algorithm (#{alg}) used",
92
+ :message => msg("Weak hashing algorithm used: ", msg_lit(alg)),
94
93
  :confidence => :medium
95
94
  end
96
95
  end