brakeman 3.7.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +15 -1
  3. data/FEATURES +1 -1
  4. data/bundle/load.rb +9 -9
  5. data/lib/brakeman.rb +55 -17
  6. data/lib/brakeman/call_index.rb +2 -2
  7. data/lib/brakeman/checks/base_check.rb +4 -2
  8. data/lib/brakeman/checks/check_basic_auth.rb +3 -3
  9. data/lib/brakeman/checks/check_basic_auth_timing_attack.rb +1 -1
  10. data/lib/brakeman/checks/check_content_tag.rb +12 -12
  11. data/lib/brakeman/checks/check_create_with.rb +5 -5
  12. data/lib/brakeman/checks/check_cross_site_scripting.rb +8 -8
  13. data/lib/brakeman/checks/check_default_routes.rb +4 -4
  14. data/lib/brakeman/checks/check_deserialize.rb +2 -2
  15. data/lib/brakeman/checks/check_detailed_exceptions.rb +4 -4
  16. data/lib/brakeman/checks/check_digest_dos.rb +2 -2
  17. data/lib/brakeman/checks/check_dynamic_finders.rb +1 -1
  18. data/lib/brakeman/checks/check_escape_function.rb +2 -2
  19. data/lib/brakeman/checks/check_evaluation.rb +1 -1
  20. data/lib/brakeman/checks/check_execute.rb +5 -5
  21. data/lib/brakeman/checks/check_file_access.rb +4 -4
  22. data/lib/brakeman/checks/check_file_disclosure.rb +2 -2
  23. data/lib/brakeman/checks/check_filter_skipping.rb +2 -2
  24. data/lib/brakeman/checks/check_forgery_setting.rb +2 -2
  25. data/lib/brakeman/checks/check_header_dos.rb +1 -1
  26. data/lib/brakeman/checks/check_i18n_xss.rb +2 -2
  27. data/lib/brakeman/checks/check_jruby_xml.rb +2 -4
  28. data/lib/brakeman/checks/check_json_encoding.rb +4 -4
  29. data/lib/brakeman/checks/check_json_parsing.rb +6 -6
  30. data/lib/brakeman/checks/check_link_to.rb +5 -5
  31. data/lib/brakeman/checks/check_link_to_href.rb +37 -31
  32. data/lib/brakeman/checks/check_mail_to.rb +2 -2
  33. data/lib/brakeman/checks/check_mass_assignment.rb +6 -6
  34. data/lib/brakeman/checks/check_mime_type_dos.rb +1 -1
  35. data/lib/brakeman/checks/check_model_attr_accessible.rb +5 -5
  36. data/lib/brakeman/checks/check_model_attributes.rb +4 -4
  37. data/lib/brakeman/checks/check_model_serialize.rb +3 -3
  38. data/lib/brakeman/checks/check_nested_attributes.rb +2 -2
  39. data/lib/brakeman/checks/check_nested_attributes_bypass.rb +1 -1
  40. data/lib/brakeman/checks/check_number_to_currency.rb +5 -5
  41. data/lib/brakeman/checks/check_quote_table_name.rb +2 -2
  42. data/lib/brakeman/checks/check_redirect.rb +2 -2
  43. data/lib/brakeman/checks/check_regex_dos.rb +3 -3
  44. data/lib/brakeman/checks/check_render.rb +4 -4
  45. data/lib/brakeman/checks/check_render_dos.rb +1 -1
  46. data/lib/brakeman/checks/check_render_inline.rb +5 -5
  47. data/lib/brakeman/checks/check_response_splitting.rb +1 -1
  48. data/lib/brakeman/checks/check_route_dos.rb +1 -1
  49. data/lib/brakeman/checks/check_safe_buffer_manipulation.rb +2 -2
  50. data/lib/brakeman/checks/check_sanitize_methods.rb +7 -7
  51. data/lib/brakeman/checks/check_secrets.rb +1 -1
  52. data/lib/brakeman/checks/check_select_tag.rb +2 -2
  53. data/lib/brakeman/checks/check_select_vulnerability.rb +3 -3
  54. data/lib/brakeman/checks/check_send.rb +1 -1
  55. data/lib/brakeman/checks/check_session_manipulation.rb +2 -2
  56. data/lib/brakeman/checks/check_session_settings.rb +3 -3
  57. data/lib/brakeman/checks/check_simple_format.rb +4 -4
  58. data/lib/brakeman/checks/check_single_quotes.rb +3 -3
  59. data/lib/brakeman/checks/check_skip_before_filter.rb +3 -3
  60. data/lib/brakeman/checks/check_sql.rb +9 -9
  61. data/lib/brakeman/checks/check_sql_cves.rb +2 -2
  62. data/lib/brakeman/checks/check_ssl_verify.rb +1 -1
  63. data/lib/brakeman/checks/check_strip_tags.rb +7 -7
  64. data/lib/brakeman/checks/check_symbol_dos.rb +2 -2
  65. data/lib/brakeman/checks/check_symbol_dos_cve.rb +1 -1
  66. data/lib/brakeman/checks/check_translate_bug.rb +3 -3
  67. data/lib/brakeman/checks/check_unsafe_reflection.rb +2 -2
  68. data/lib/brakeman/checks/check_unscoped_find.rb +1 -1
  69. data/lib/brakeman/checks/check_validation_regex.rb +1 -1
  70. data/lib/brakeman/checks/check_weak_hash.rb +6 -6
  71. data/lib/brakeman/checks/check_without_protection.rb +2 -2
  72. data/lib/brakeman/checks/check_xml_dos.rb +1 -1
  73. data/lib/brakeman/checks/check_yaml_parsing.rb +2 -2
  74. data/lib/brakeman/commandline.rb +2 -2
  75. data/lib/brakeman/options.rb +9 -5
  76. data/lib/brakeman/processors/alias_processor.rb +3 -1
  77. data/lib/brakeman/processors/lib/rails2_route_processor.rb +8 -8
  78. data/lib/brakeman/processors/lib/render_helper.rb +3 -3
  79. data/lib/brakeman/report.rb +9 -6
  80. data/lib/brakeman/report/report_base.rb +2 -1
  81. data/lib/brakeman/report/report_text.rb +4 -6
  82. data/lib/brakeman/rescanner.rb +8 -8
  83. data/lib/brakeman/tracker.rb +3 -3
  84. data/lib/brakeman/tracker/collection.rb +1 -1
  85. data/lib/brakeman/util.rb +5 -1
  86. data/lib/brakeman/version.rb +1 -1
  87. data/lib/brakeman/warning.rb +49 -21
  88. metadata +2 -2
@@ -21,7 +21,7 @@ class Brakeman::CheckDefaultRoutes < Brakeman::BaseCheck
21
21
  :warning_code => :all_default_routes,
22
22
  :message => "All public methods in controllers are available as actions in routes.rb",
23
23
  :line => tracker.routes[:allow_all_actions].line,
24
- :confidence => CONFIDENCE[:high],
24
+ :confidence => :high,
25
25
  :file => "#{tracker.app_path}/config/routes.rb"
26
26
  end
27
27
  end
@@ -43,7 +43,7 @@ class Brakeman::CheckDefaultRoutes < Brakeman::BaseCheck
43
43
  :warning_code => :controller_default_routes,
44
44
  :message => "Any public method in #{name} can be used as an action for #{verb} requests.",
45
45
  :line => actions[2],
46
- :confidence => CONFIDENCE[:med],
46
+ :confidence => :medium,
47
47
  :file => "#{tracker.app_path}/config/routes.rb"
48
48
  end
49
49
  end
@@ -67,9 +67,9 @@ class Brakeman::CheckDefaultRoutes < Brakeman::BaseCheck
67
67
  end
68
68
 
69
69
  if allow_all_actions? or @actions_allowed_on_controller
70
- confidence = CONFIDENCE[:high]
70
+ confidence = :high
71
71
  else
72
- confidence = CONFIDENCE[:med]
72
+ confidence = :medium
73
73
  end
74
74
 
75
75
  warn :warning_type => "Remote Code Execution",
@@ -36,9 +36,9 @@ class Brakeman::CheckDeserialize < Brakeman::BaseCheck
36
36
  method = result[:call].method
37
37
 
38
38
  if input = has_immediate_user_input?(arg)
39
- confidence = CONFIDENCE[:high]
39
+ confidence = :high
40
40
  elsif input = include_user_input?(arg)
41
- confidence = CONFIDENCE[:med]
41
+ confidence = :medium
42
42
  end
43
43
 
44
44
  if confidence
@@ -18,13 +18,13 @@ class Brakeman::CheckDetailedExceptions < Brakeman::BaseCheck
18
18
  warn :warning_type => "Information Disclosure",
19
19
  :warning_code => :local_request_config,
20
20
  :message => "Detailed exceptions are enabled in production",
21
- :confidence => CONFIDENCE[:high],
21
+ :confidence => :high,
22
22
  :file => "config/environments/production.rb"
23
23
  end
24
24
  end
25
25
 
26
26
  def check_detailed_exceptions
27
- tracker.controllers.each do |name, controller|
27
+ tracker.controllers.each do |_name, controller|
28
28
  controller.methods_public.each do |method_name, definition|
29
29
  src = definition[:src]
30
30
  body = src.body.last
@@ -32,9 +32,9 @@ class Brakeman::CheckDetailedExceptions < Brakeman::BaseCheck
32
32
 
33
33
  if method_name == :show_detailed_exceptions? and not safe? body
34
34
  if true? body
35
- confidence = CONFIDENCE[:high]
35
+ confidence = :high
36
36
  else
37
- confidence = CONFIDENCE[:med]
37
+ confidence = :medium
38
38
  end
39
39
 
40
40
  warn :warning_type => "Information Disclosure",
@@ -19,9 +19,9 @@ class Brakeman::CheckDigestDoS < Brakeman::BaseCheck
19
19
  end
20
20
 
21
21
  if with_http_digest?
22
- confidence = CONFIDENCE[:high]
22
+ confidence = :high
23
23
  else
24
- confidence = CONFIDENCE[:low]
24
+ confidence = :weak
25
25
  end
26
26
 
27
27
  warn :warning_type => "Denial of Service",
@@ -26,7 +26,7 @@ class Brakeman::CheckDynamicFinders < Brakeman::BaseCheck
26
26
  :warning_type => "SQL Injection",
27
27
  :warning_code => :sql_injection_dynamic_finder,
28
28
  :message => "MySQL integer conversion may cause 0 to match any string",
29
- :confidence => CONFIDENCE[:med],
29
+ :confidence => :medium,
30
30
  :user_input => arg
31
31
 
32
32
  break
@@ -10,10 +10,10 @@ class Brakeman::CheckEscapeFunction < Brakeman::BaseCheck
10
10
  def run_check
11
11
  if version_between?('2.0.0', '2.3.13') and RUBY_VERSION < '1.9.0'
12
12
 
13
- warn :warning_type => 'Cross Site Scripting',
13
+ warn :warning_type => 'Cross-Site Scripting',
14
14
  :warning_code => :CVE_2011_2932,
15
15
  :message => 'Versions before 2.3.14 have a vulnerability in escape method when used with Ruby 1.8: CVE-2011-2932',
16
- :confidence => CONFIDENCE[:high],
16
+ :confidence => :high,
17
17
  :gem_info => gemfile_or_environment,
18
18
  :link_path => "https://groups.google.com/d/topic/rubyonrails-security/Vr_7WSOrEZU/discussion"
19
19
  end
@@ -29,7 +29,7 @@ class Brakeman::CheckEvaluation < Brakeman::BaseCheck
29
29
  :message => "User input in eval",
30
30
  :code => result[:call],
31
31
  :user_input => input,
32
- :confidence => CONFIDENCE[:high]
32
+ :confidence => :high
33
33
  end
34
34
  end
35
35
  end
@@ -56,9 +56,9 @@ class Brakeman::CheckExecute < Brakeman::BaseCheck
56
56
  if failure and original? result
57
57
 
58
58
  if failure.type == :interp #Not from user input
59
- confidence = CONFIDENCE[:med]
59
+ confidence = :medium
60
60
  else
61
- confidence = CONFIDENCE[:high]
61
+ confidence = :high
62
62
  end
63
63
 
64
64
  warn :result => result,
@@ -79,7 +79,7 @@ class Brakeman::CheckExecute < Brakeman::BaseCheck
79
79
  :warning_code => :command_injection,
80
80
  :message => "Possible command injection in open()",
81
81
  :user_input => match,
82
- :confidence => CONFIDENCE[:high]
82
+ :confidence => :high
83
83
  end
84
84
  end
85
85
  end
@@ -111,9 +111,9 @@ class Brakeman::CheckExecute < Brakeman::BaseCheck
111
111
  exp = result[:call]
112
112
 
113
113
  if input = include_user_input?(exp)
114
- confidence = CONFIDENCE[:high]
114
+ confidence = :high
115
115
  elsif input = dangerous?(exp)
116
- confidence = CONFIDENCE[:med]
116
+ confidence = :medium
117
117
  else
118
118
  return
119
119
  end
@@ -32,18 +32,18 @@ class Brakeman::CheckFileAccess < Brakeman::BaseCheck
32
32
  file_name = call.first_arg
33
33
 
34
34
  if match = has_immediate_user_input?(file_name)
35
- confidence = CONFIDENCE[:high]
35
+ confidence = :high
36
36
  elsif match = has_immediate_model?(file_name)
37
37
  match = Match.new(:model, match)
38
- confidence = CONFIDENCE[:med]
38
+ confidence = :medium
39
39
  elsif tracker.options[:check_arguments] and
40
40
  match = include_user_input?(file_name)
41
41
 
42
42
  #Check for string building in file name
43
43
  if call?(file_name) and (file_name.method == :+ or file_name.method == :<<)
44
- confidence = CONFIDENCE[:high]
44
+ confidence = :high
45
45
  else
46
- confidence = CONFIDENCE[:low]
46
+ confidence = :weak
47
47
  end
48
48
  end
49
49
 
@@ -3,7 +3,7 @@ require 'brakeman/checks/base_check'
3
3
  class Brakeman::CheckFileDisclosure < Brakeman::BaseCheck
4
4
  Brakeman::Checks.add self
5
5
 
6
- @description = "Checks for versions with file existence disclosure vulnerability"
6
+ @description = 'Checks for versions with file existence disclosure vulnerability'
7
7
 
8
8
  def run_check
9
9
  fix_version = case
@@ -23,7 +23,7 @@ class Brakeman::CheckFileDisclosure < Brakeman::BaseCheck
23
23
  warn :warning_type => "File Access",
24
24
  :warning_code => :CVE_2014_7829,
25
25
  :message => "Rails #{rails_version} has a file existence disclosure. Upgrade to #{fix_version} or disable serving static assets",
26
- :confidence => CONFIDENCE[:high],
26
+ :confidence => :high,
27
27
  :gem_info => gemfile_or_environment,
28
28
  :link_path => "https://groups.google.com/d/msg/rubyonrails-security/23fiuwb1NBA/MQVM1-5GkPMJ"
29
29
  end
@@ -13,14 +13,14 @@ class Brakeman::CheckFilterSkipping < Brakeman::BaseCheck
13
13
  warn :warning_type => "Default Routes",
14
14
  :warning_code => :CVE_2011_2929,
15
15
  :message => "Versions before 3.0.10 have a vulnerability which allows filters to be bypassed: CVE-2011-2929",
16
- :confidence => CONFIDENCE[:high],
16
+ :confidence => :high,
17
17
  :gem_info => gemfile_or_environment,
18
18
  :link_path => "https://groups.google.com/d/topic/rubyonrails-security/NCCsca7TEtY/discussion"
19
19
  end
20
20
  end
21
21
 
22
22
  def uses_arbitrary_actions?
23
- tracker.routes.each do |name, actions|
23
+ tracker.routes.each do |_name, actions|
24
24
  if actions.include? :allow_all_actions
25
25
  return true
26
26
  end
@@ -29,7 +29,7 @@ class Brakeman::CheckForgerySetting < Brakeman::BaseCheck
29
29
  :warning_type => "Cross-Site Request Forgery",
30
30
  :warning_code => :csrf_not_protected_by_raising_exception,
31
31
  :message => "protect_from_forgery should be configured with 'with: :exception'",
32
- :confidence => CONFIDENCE[:med],
32
+ :confidence => :medium,
33
33
  :file => controller.file
34
34
  }
35
35
 
@@ -50,7 +50,7 @@ class Brakeman::CheckForgerySetting < Brakeman::BaseCheck
50
50
  opts = {
51
51
  :controller => :ApplicationController,
52
52
  :warning_type => "Cross-Site Request Forgery",
53
- :confidence => CONFIDENCE[:high]
53
+ :confidence => :high
54
54
  }.merge opts
55
55
 
56
56
  warn opts
@@ -18,7 +18,7 @@ class Brakeman::CheckHeaderDoS < Brakeman::BaseCheck
18
18
  warn :warning_type => "Denial of Service",
19
19
  :warning_code => :CVE_2013_6414,
20
20
  :message => message,
21
- :confidence => CONFIDENCE[:med],
21
+ :confidence => :medium,
22
22
  :gem_info => gemfile_or_environment,
23
23
  :link_path => "https://groups.google.com/d/msg/ruby-security-ann/A-ebV4WxzKg/KNPTbX8XAQUJ"
24
24
  end
@@ -18,10 +18,10 @@ class Brakeman::CheckI18nXSS < Brakeman::BaseCheck
18
18
  return
19
19
  end
20
20
 
21
- warn :warning_type => "Cross Site Scripting",
21
+ warn :warning_type => "Cross-Site Scripting",
22
22
  :warning_code => :CVE_2013_4491,
23
23
  :message => message,
24
- :confidence => CONFIDENCE[:med],
24
+ :confidence => :medium,
25
25
  :gem_info => gemfile_or_environment(:i18n),
26
26
  :link_path => "https://groups.google.com/d/msg/ruby-security-ann/pLrh6DUw998/bLFEyIO4k_EJ"
27
27
  end
@@ -23,15 +23,13 @@ class Brakeman::CheckJRubyXML < Brakeman::BaseCheck
23
23
  tracker.check_initializers(:"ActiveSupport::XmlMini", :backend=).each do |result|
24
24
  arg = result.call.first_arg
25
25
 
26
- if string? arg and arg.value == "REXML"
27
- return
28
- end
26
+ return if string? arg and arg.value == "REXML"
29
27
  end
30
28
 
31
29
  warn :warning_type => "File Access",
32
30
  :warning_code => :CVE_2013_1856,
33
31
  :message => "Rails #{rails_version} with JRuby has a vulnerability in XML parser: upgrade to #{fix_version} or patch",
34
- :confidence => CONFIDENCE[:high],
32
+ :confidence => :high,
35
33
  :gem_info => gemfile_or_environment,
36
34
  :link => "https://groups.google.com/d/msg/rubyonrails-security/KZwsQbYsOiI/5kUV7dSCJGwJ"
37
35
  end
@@ -16,12 +16,12 @@ class Brakeman::CheckJSONEncoding < Brakeman::BaseCheck
16
16
  end
17
17
 
18
18
  if tracker.find_call(:methods => [:to_json, :encode]).any?
19
- confidence = CONFIDENCE[:high]
19
+ confidence = :high
20
20
  else
21
- confidence = CONFIDENCE[:med]
21
+ confidence = :medium
22
22
  end
23
23
 
24
- warn :warning_type => "Cross Site Scripting",
24
+ warn :warning_type => "Cross-Site Scripting",
25
25
  :warning_code => :CVE_2015_3226,
26
26
  :message => message,
27
27
  :confidence => confidence,
@@ -40,7 +40,7 @@ class Brakeman::CheckJSONEncoding < Brakeman::BaseCheck
40
40
  s(:args),
41
41
  s(:self))))))
42
42
 
43
- tracker.initializers.any? do |name, initializer|
43
+ tracker.initializers.any? do |_name, initializer|
44
44
  initializer == workaround
45
45
  end
46
46
  end
@@ -30,7 +30,7 @@ class Brakeman::CheckJSONParsing < Brakeman::BaseCheck
30
30
  warn :warning_type => "Remote Code Execution",
31
31
  :warning_code => :CVE_2013_0333,
32
32
  :message => message,
33
- :confidence => CONFIDENCE[:high],
33
+ :confidence => :high,
34
34
  :gem_info => gem_info,
35
35
  :link_path => "https://groups.google.com/d/topic/rubyonrails-security/1h2DR63ViGo/discussion"
36
36
  end
@@ -71,11 +71,11 @@ class Brakeman::CheckJSONParsing < Brakeman::BaseCheck
71
71
  (version >= "1.5.5" and version < "1.6.0")
72
72
 
73
73
  warning_type = "Denial of Service"
74
- confidence = CONFIDENCE[:med]
74
+ confidence = :medium
75
75
  message = "#{name} gem version #{version} has a symbol creation vulnerablity: upgrade to "
76
76
 
77
77
  if version >= "1.7.0"
78
- confidence = CONFIDENCE[:high]
78
+ confidence = :high
79
79
  warning_type = "Remote Code Execution"
80
80
  message = "#{name} gem version #{version} has a remote code vulnerablity: upgrade to 1.7.7"
81
81
  elsif version >= "1.6.0"
@@ -83,12 +83,12 @@ class Brakeman::CheckJSONParsing < Brakeman::BaseCheck
83
83
  elsif version >= "1.5.0"
84
84
  message << "1.5.5"
85
85
  else
86
- confidence = CONFIDENCE[:low]
86
+ confidence = :weak
87
87
  message << "1.5.5"
88
88
  end
89
89
 
90
- if confidence == CONFIDENCE[:med] and uses_json_parse?
91
- confidence = CONFIDENCE[:high]
90
+ if confidence == :medium and uses_json_parse?
91
+ confidence = :high
92
92
  end
93
93
 
94
94
  warn :warning_type => warning_type,
@@ -70,7 +70,7 @@ class Brakeman::CheckLinkTo < Brakeman::CheckCrossSiteScripting
70
70
 
71
71
  message = "Unescaped #{friendly_type_of input} in link_to"
72
72
 
73
- warn_xss(result, message, input, CONFIDENCE[:high])
73
+ warn_xss(result, message, input, :high)
74
74
  end
75
75
 
76
76
  # Check if we should warn about the specified method
@@ -81,8 +81,8 @@ class Brakeman::CheckLinkTo < Brakeman::CheckCrossSiteScripting
81
81
  method = match.method
82
82
  return false if IGNORE_MODEL_METHODS.include? method
83
83
 
84
- confidence = CONFIDENCE[:med]
85
- confidence = CONFIDENCE[:high] if likely_model_attribute? match
84
+ confidence = :medium
85
+ confidence = :high if likely_model_attribute? match
86
86
  warn_xss(result, "Unescaped model attribute in link_to", match, confidence)
87
87
  end
88
88
 
@@ -93,14 +93,14 @@ class Brakeman::CheckLinkTo < Brakeman::CheckCrossSiteScripting
93
93
 
94
94
  message = "Unescaped #{friendly_type_of matched} in link_to"
95
95
 
96
- warn_xss(result, message, @matched, CONFIDENCE[:med])
96
+ warn_xss(result, message, @matched, :medium)
97
97
  end
98
98
 
99
99
  # Create a warn for this xss
100
100
  def warn_xss(result, message, user_input, confidence)
101
101
  add_result(result)
102
102
  warn :result => result,
103
- :warning_type => "Cross Site Scripting",
103
+ :warning_type => "Cross-Site Scripting",
104
104
  :warning_code => :xss_link_to,
105
105
  :message => message,
106
106
  :user_input => user_input,
@@ -36,7 +36,7 @@ class Brakeman::CheckLinkToHref < Brakeman::CheckLinkTo
36
36
  @matched = false
37
37
  url_arg = process call.second_arg
38
38
 
39
- if call? url_arg and url_arg.method == :url_for
39
+ if check_argument? url_arg
40
40
  url_arg = url_arg.first_arg
41
41
  end
42
42
 
@@ -48,47 +48,53 @@ class Brakeman::CheckLinkToHref < Brakeman::CheckLinkTo
48
48
  unless duplicate? result or call_on_params? url_arg or ignore_interpolation? url_arg, input.match
49
49
  add_result result
50
50
  warn :result => result,
51
- :warning_type => "Cross Site Scripting",
51
+ :warning_type => "Cross-Site Scripting",
52
52
  :warning_code => :xss_link_to_href,
53
53
  :message => message,
54
54
  :user_input => input,
55
- :confidence => CONFIDENCE[:high],
55
+ :confidence => :high,
56
56
  :link_path => "link_to_href"
57
57
  end
58
- elsif has_immediate_model? url_arg or model_find_call? url_arg
58
+ elsif not tracker.options[:ignore_model_output] and input = has_immediate_model?(url_arg)
59
+ return if ignore_model_call? url_arg, input or duplicate? result
60
+ add_result result
61
+
62
+ message = "Potentially unsafe model attribute in link_to href"
63
+
64
+ warn :result => result,
65
+ :warning_type => "Cross-Site Scripting",
66
+ :warning_code => :xss_link_to_href,
67
+ :message => message,
68
+ :user_input => input,
69
+ :confidence => :weak,
70
+ :link_path => "link_to_href"
71
+ end
72
+ end
59
73
 
60
- # Decided NOT warn on models. polymorphic_path is called it a model is
61
- # passed to link_to (which passes it to url_for)
74
+ def check_argument? url_arg
75
+ return unless call? url_arg
62
76
 
63
- elsif array? url_arg
64
- # Just like models, polymorphic path/url is called if the argument is
65
- # an array
77
+ target = url_arg.target
78
+ method = url_arg.method
66
79
 
67
- elsif hash? url_arg
80
+ method == :url_for or
81
+ method == :h or
82
+ cgi_escaped? target, method
83
+ end
68
84
 
69
- # url_for uses the key/values pretty carefully and I don't see a risk.
70
- # IF you have default routes AND you accept user input for :controller
71
- # and :only_path, then MAYBE you could trigger a javascript:/data:
72
- # attack.
85
+ def ignore_model_call? url_arg, exp
86
+ return true unless call? exp
73
87
 
74
- elsif @matched
75
- if @matched.type == :model and not tracker.options[:ignore_model_output]
76
- message = "Unsafe model attribute in link_to href"
77
- elsif @matched.type == :params and not call_on_params? @matched.match
78
- message = "Unsafe parameter value in link_to href"
79
- end
88
+ target = exp.target
89
+ method = exp.method
80
90
 
81
- if message and not duplicate? result and not ignore_interpolation? url_arg, @matched.match
82
- add_result result
83
- warn :result => result,
84
- :warning_type => "Cross Site Scripting",
85
- :warning_code => :xss_link_to_href,
86
- :message => message,
87
- :user_input => @matched,
88
- :confidence => CONFIDENCE[:med],
89
- :link_path => "link_to_href"
90
- end
91
- end
91
+ return true unless model_find_call? target
92
+
93
+ return true unless method.to_s =~ /url|uri|link|page|site/
94
+
95
+ ignore_call? target, method or
96
+ IGNORE_MODEL_METHODS.include? method or
97
+ ignore_interpolation? url_arg, exp
92
98
  end
93
99
 
94
100
  #Ignore situations where the href is an interpolated string