contrast-agent 3.14.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -15
  3. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  4. data/ext/cs__assess_string/cs__assess_string.c +24 -25
  5. data/ext/cs__assess_string/cs__assess_string.h +3 -1
  6. data/ext/cs__common/cs__common.c +4 -2
  7. data/ext/cs__common/cs__common.h +1 -1
  8. data/lib/contrast.rb +1 -1
  9. data/lib/contrast/agent.rb +4 -12
  10. data/lib/contrast/agent/assess.rb +1 -0
  11. data/lib/contrast/agent/assess/contrast_event.rb +143 -79
  12. data/lib/contrast/agent/assess/events/source_event.rb +1 -1
  13. data/lib/contrast/agent/assess/finalizers/freeze.rb +3 -1
  14. data/lib/contrast/agent/assess/finalizers/hash.rb +45 -1
  15. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
  16. data/lib/contrast/agent/assess/policy/patcher.rb +1 -1
  17. data/lib/contrast/agent/assess/policy/policy.rb +0 -2
  18. data/lib/contrast/agent/assess/policy/policy_node.rb +15 -10
  19. data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -3
  20. data/lib/contrast/agent/assess/policy/preshift.rb +7 -11
  21. data/lib/contrast/agent/assess/policy/propagation_method.rb +50 -33
  22. data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
  23. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  24. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  25. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +5 -3
  26. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
  27. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  28. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +4 -7
  29. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  30. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +8 -5
  31. data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
  32. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  33. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  34. data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
  35. data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
  36. data/lib/contrast/agent/assess/policy/propagator/split.rb +24 -19
  37. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +47 -31
  38. data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
  39. data/lib/contrast/agent/assess/policy/source_method.rb +85 -58
  40. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
  41. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
  42. data/lib/contrast/agent/assess/policy/trigger_method.rb +76 -28
  43. data/lib/contrast/agent/assess/policy/trigger_node.rb +38 -43
  44. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  45. data/lib/contrast/agent/assess/properties.rb +2 -0
  46. data/lib/contrast/agent/assess/property/evented.rb +5 -18
  47. data/lib/contrast/agent/assess/property/tagged.rb +9 -3
  48. data/lib/contrast/agent/assess/property/updated.rb +131 -0
  49. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  50. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
  51. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
  52. data/lib/contrast/agent/assess/tag.rb +1 -1
  53. data/lib/contrast/agent/assess/tracker.rb +66 -0
  54. data/lib/contrast/agent/at_exit_hook.rb +5 -5
  55. data/lib/contrast/agent/class_reopener.rb +7 -5
  56. data/lib/contrast/agent/inventory.rb +15 -0
  57. data/lib/contrast/agent/inventory/dependencies.rb +50 -0
  58. data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
  59. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
  60. data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
  61. data/lib/contrast/agent/middleware.rb +1 -3
  62. data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
  63. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
  64. data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
  65. data/lib/contrast/agent/patching/policy/patch.rb +6 -0
  66. data/lib/contrast/agent/patching/policy/patcher.rb +13 -22
  67. data/lib/contrast/agent/patching/policy/policy.rb +17 -6
  68. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
  69. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
  70. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  71. data/lib/contrast/agent/protect/rule/cmd_injection.rb +9 -25
  72. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  73. data/lib/contrast/agent/request.rb +34 -34
  74. data/lib/contrast/agent/request_handler.rb +1 -1
  75. data/lib/contrast/agent/response.rb +17 -6
  76. data/lib/contrast/agent/rewriter.rb +1 -3
  77. data/lib/contrast/agent/scope.rb +59 -53
  78. data/lib/contrast/agent/static_analysis.rb +7 -7
  79. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  80. data/lib/contrast/agent/version.rb +1 -1
  81. data/lib/contrast/api/communication/messaging_queue.rb +1 -4
  82. data/lib/contrast/api/communication/socket_client.rb +36 -1
  83. data/lib/contrast/api/decorators.rb +3 -0
  84. data/lib/contrast/api/decorators/address.rb +13 -14
  85. data/lib/contrast/api/decorators/application_update.rb +2 -4
  86. data/lib/contrast/api/decorators/library.rb +53 -0
  87. data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
  88. data/lib/contrast/api/decorators/message.rb +1 -0
  89. data/lib/contrast/api/decorators/trace_event.rb +25 -23
  90. data/lib/contrast/common_agent_configuration.rb +2 -1
  91. data/lib/contrast/components/agent.rb +6 -5
  92. data/lib/contrast/components/app_context.rb +49 -38
  93. data/lib/contrast/components/config.rb +30 -48
  94. data/lib/contrast/components/contrast_service.rb +9 -9
  95. data/lib/contrast/components/interface.rb +25 -3
  96. data/lib/contrast/components/inventory.rb +6 -1
  97. data/lib/contrast/components/scope.rb +49 -6
  98. data/lib/contrast/components/settings.rb +23 -23
  99. data/lib/contrast/config/application_configuration.rb +5 -2
  100. data/lib/contrast/config/inventory_configuration.rb +2 -2
  101. data/lib/contrast/config/service_configuration.rb +8 -0
  102. data/lib/contrast/configuration.rb +88 -47
  103. data/lib/contrast/extension/assess.rb +0 -2
  104. data/lib/contrast/extension/assess/array.rb +15 -8
  105. data/lib/contrast/extension/assess/erb.rb +11 -3
  106. data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
  107. data/lib/contrast/extension/assess/exec_trigger.rb +1 -4
  108. data/lib/contrast/extension/assess/fiber.rb +12 -12
  109. data/lib/contrast/extension/assess/hash.rb +5 -6
  110. data/lib/contrast/extension/assess/kernel.rb +28 -23
  111. data/lib/contrast/extension/assess/marshal.rb +11 -6
  112. data/lib/contrast/extension/assess/regexp.rb +8 -7
  113. data/lib/contrast/extension/assess/string.rb +21 -21
  114. data/lib/contrast/extension/protect/kernel.rb +3 -3
  115. data/lib/contrast/framework/base_support.rb +1 -1
  116. data/lib/contrast/framework/manager.rb +3 -3
  117. data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
  118. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  119. data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -11
  120. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +10 -10
  121. data/lib/contrast/framework/rails/patch/support.rb +1 -1
  122. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  123. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  124. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
  125. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  126. data/lib/contrast/framework/rails/support.rb +5 -0
  127. data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
  128. data/lib/contrast/framework/sinatra/support.rb +4 -4
  129. data/lib/contrast/logger/application.rb +11 -3
  130. data/lib/contrast/logger/log.rb +7 -2
  131. data/lib/contrast/utils/assess/tracking_util.rb +48 -3
  132. data/lib/contrast/utils/duck_utils.rb +0 -10
  133. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  134. data/lib/contrast/utils/invalid_configuration_util.rb +20 -21
  135. data/lib/contrast/utils/inventory_util.rb +0 -7
  136. data/lib/contrast/utils/sha256_builder.rb +0 -12
  137. data/lib/contrast/utils/string_utils.rb +10 -5
  138. data/resources/assess/policy.json +31 -22
  139. data/ruby-agent.gemspec +21 -18
  140. data/service_executables/VERSION +1 -1
  141. data/service_executables/linux/contrast-service +0 -0
  142. data/service_executables/mac/contrast-service +0 -0
  143. metadata +71 -30
  144. data/lib/contrast/agent/assess/finalizers/finalize.rb +0 -21
  145. data/lib/contrast/extension/assess/assess_extension.rb +0 -145
  146. data/lib/contrast/utils/boolean_util.rb +0 -30
  147. data/lib/contrast/utils/freeze_util.rb +0 -32
  148. data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -26,7 +26,7 @@ module Contrast
26
26
 
27
27
  action = properties['action']
28
28
  write_marker = write?(action, *args)
29
- possible_write = write_marker && possible_write(write_marker)
29
+ possible_write = write_marker && possible_write?(write_marker)
30
30
  path_traversal_rule(path, possible_write, object, method)
31
31
 
32
32
  # If the action was copy, we need to handle the write half of it.
@@ -48,7 +48,7 @@ module Contrast
48
48
 
49
49
  private
50
50
 
51
- def possible_write input
51
+ def possible_write? input
52
52
  input.cs__respond_to?(:to_s) &&
53
53
  input.to_s.include?(Contrast::Utils::ObjectShare::WRITE_FLAG)
54
54
  end
@@ -62,7 +62,7 @@ module Contrast
62
62
  return true if action == WRITE
63
63
 
64
64
  write_marker = args.length > 1 ? args[1] : nil
65
- write_marker && possible_write(write_marker)
65
+ write_marker && possible_write?(write_marker)
66
66
  end
67
67
 
68
68
  def path_traversal_rule path, possible_write, object, method
@@ -83,6 +83,7 @@ module Contrast
83
83
  tmp = CS__SAFER_REL_PATHS.map { |r| "#{ pwd }/#{ r }" }
84
84
  gems = ENV['GEM_PATH']
85
85
  tmp += gems.split(Contrast::Utils::ObjectShare::COLON) if gems
86
+ tmp.map!(&:downcase)
86
87
  tmp
87
88
  else
88
89
  []
@@ -27,7 +27,7 @@ module Contrast
27
27
  def apply_rule__io method, _exception, _properties, object, args
28
28
  need_rewind = false
29
29
  potential_xml = args[0]
30
- return unless potential_xml&.respond_to?(:rewind)
30
+ return unless potential_xml.cs__respond_to?(:rewind)
31
31
 
32
32
  xml = potential_xml.read
33
33
  need_rewind = true
@@ -1,7 +1,6 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/agent/at_exit_hook'
5
4
  require 'contrast/agent/protect/rule/base_service'
6
5
  require 'contrast/utils/stack_trace_utils'
7
6
  require 'contrast/utils/object_share'
@@ -45,11 +44,6 @@ module Contrast
45
44
  raise Contrast::SecurityException.new(
46
45
  self,
47
46
  "Command Injection rule triggered. Call to #{ classname }.#{ method } blocked.")
48
- ensure
49
- # Kernel#exec replaces the current process and does not go through
50
- # at_exit hooks. Kernel#` runs as a subshell - messages appended
51
- # here do not seem to be present in the original process.
52
- Contrast::Agent::AtExitHook.on_exit if %i[exec `].include?(method.to_sym)
53
47
  end
54
48
 
55
49
  def build_attack_with_match context, input_analysis_result, result, candidate_string, **kwargs
@@ -104,37 +98,27 @@ module Contrast
104
98
 
105
99
  def report_command_execution context, command, **kwargs
106
100
  return unless report_any_command_execution?
107
- return nil if protect_excluded_by_code?
101
+ return if protect_excluded_by_code?
108
102
 
109
103
  build_attack_with_match(context, nil, nil, command, **kwargs)
110
104
  end
111
105
 
112
106
  def find_probable_attacker context, potential_attack_string, ia_results, **kwargs
113
- result = nil
114
- if chained_command?(potential_attack_string) # this is probably an attack
115
- most_likely = nil
116
- ia_results.each do |input_analysis_result|
117
- next unless chained_command?(input_analysis_result.value)
118
-
119
- most_likely = input_analysis_result
120
- break
121
- end
122
- end
123
- return result unless most_likely
107
+ return unless chained_command?(potential_attack_string)
108
+
109
+ likely_attacker = ia_results.find { |input_analysis_result| chained_command?(input_analysis_result.value) }
110
+ return unless likely_attacker
124
111
 
125
- result ||= build_attack_with_match(
112
+ build_attack_with_match(
126
113
  context,
127
- most_likely,
128
- result,
114
+ likely_attacker,
115
+ nil,
129
116
  potential_attack_string,
130
117
  **kwargs)
131
- result
132
118
  end
133
119
 
134
120
  def chained_command? command
135
- return true if CHAINED_COMMAND_CHARS.match(command)
136
-
137
- false
121
+ CHAINED_COMMAND_CHARS.match(command)
138
122
  end
139
123
 
140
124
  # Part of the Hardening for Command Injection detection is the
@@ -16,6 +16,7 @@ module Contrast
16
16
  def start_line_comment? char, index, query
17
17
  if char == Contrast::Utils::ObjectShare::SLASH &&
18
18
  query[index + 1] == Contrast::Utils::ObjectShare::SLASH
19
+
19
20
  return true
20
21
  end
21
22
 
@@ -46,42 +46,42 @@ module Contrast
46
46
  # Should also handle the ;jsessionid.
47
47
  def normalized_uri
48
48
  @_normalized_uri ||= begin
49
- path = rack_request.path
50
- uri = path.split(Contrast::Utils::ObjectShare::SEMICOLON)[0] # remove ;jsessionid
51
- uri = uri.split(Contrast::Utils::ObjectShare::QUESTION_MARK)[0] # remove ?query_string=
52
- uri.gsub(INNER_REST_TOKEN, INNER_NUMBER_MARKER) # replace interior tokens
53
- uri.gsub(LAST_REST_TOKEN, LAST_NUMBER_MARKER) # replace last token
54
- end
49
+ path = rack_request.path
50
+ uri = path.split(Contrast::Utils::ObjectShare::SEMICOLON)[0] # remove ;jsessionid
51
+ uri = uri.split(Contrast::Utils::ObjectShare::QUESTION_MARK)[0] # remove ?query_string=
52
+ uri.gsub(INNER_REST_TOKEN, INNER_NUMBER_MARKER) # replace interior tokens
53
+ uri.gsub(LAST_REST_TOKEN, LAST_NUMBER_MARKER) # replace last token
54
+ end
55
55
  end
56
56
 
57
57
  def document_type
58
58
  @_document_type ||= begin
59
- if /xml/i.match?(content_type) || body&.start_with?('<?xml')
60
- :XML
61
- elsif /json/i.match?(content_type) || body&.match?(/\s*[{\[]/)
62
- :JSON
63
- else
64
- :NORMAL
65
- end
66
- end
59
+ if /xml/i.match?(content_type) || body&.start_with?('<?xml')
60
+ :XML
61
+ elsif /json/i.match?(content_type) || body&.match?(/\s*[{\[]/)
62
+ :JSON
63
+ else
64
+ :NORMAL
65
+ end
66
+ end
67
67
  end
68
68
 
69
69
  # Header keys upcased and any underscores replaced with dashes
70
70
  def headers
71
71
  @_headers ||= begin
72
- with_contrast_scope do
73
- hash = {}
74
- env.each do |key, value|
75
- next unless key
76
-
77
- name = key.to_s
78
- next unless name.start_with?(Contrast::Utils::ObjectShare::HTTP_SCORE)
79
-
80
- hash[Contrast::Utils::StringUtils.normalized_key(name)] = value
81
- end
82
- hash
83
- end
84
- end
72
+ with_contrast_scope do
73
+ hash = {}
74
+ env.each do |key, value|
75
+ next unless key
76
+
77
+ name = key.to_s
78
+ next unless name.start_with?(Contrast::Utils::ObjectShare::HTTP_SCORE)
79
+
80
+ hash[Contrast::Utils::StringUtils.normalized_key(name)] = value
81
+ end
82
+ hash
83
+ end
84
+ end
85
85
  end
86
86
 
87
87
  def body
@@ -121,13 +121,13 @@ module Contrast
121
121
 
122
122
  def file_names
123
123
  @_file_names ||= begin
124
- names = {}
125
- parsed_data = Rack::Multipart.parse_multipart(rack_request.env)
126
- traverse_parsed_multipart(parsed_data, names)
127
- rescue StandardError => _e
128
- logger.warn('Unable to parse multipart request!')
129
- {}
130
- end
124
+ names = {}
125
+ parsed_data = Rack::Multipart.parse_multipart(rack_request.env)
126
+ traverse_parsed_multipart(parsed_data, names)
127
+ rescue StandardError => _e
128
+ logger.warn('Unable to parse multipart request!')
129
+ {}
130
+ end
131
131
  end
132
132
 
133
133
  def hash_id
@@ -18,7 +18,7 @@ module Contrast
18
18
  end
19
19
 
20
20
  def send_activity_messages
21
- Contrast::Utils::GemfileReader.instance.generate_library_usage(context.activity)
21
+ Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage(context.activity)
22
22
  [context.server_activity, context.activity, context.observed_route].each do |message|
23
23
  Contrast::Agent.messaging_queue.send_event_eventually(message)
24
24
  end
@@ -44,14 +44,9 @@ module Contrast
44
44
  context_response = Contrast::Api::Dtm::HttpResponse.new
45
45
  context_response.response_code = response_code.to_i
46
46
  headers&.each_pair do |key, value|
47
- k = Contrast::Utils::StringUtils.force_utf8(key)
48
- v = Contrast::Utils::StringUtils.force_utf8(value)
49
- context_response.response_headers[k] = v
47
+ append_pair(context_response.normalized_response_headers, key, value)
50
48
  end
51
- context_response.parsed_response_headers = true
52
-
53
49
  context_response.response_body_binary = Contrast::Utils::StringUtils.force_utf8(body)
54
- context_response.parsed_response_body = false
55
50
 
56
51
  doc_type = document_type
57
52
  context_response.document_type = doc_type if doc_type
@@ -97,6 +92,22 @@ module Contrast
97
92
 
98
93
  private
99
94
 
95
+ # From the dtm for normalized_response_headers:
96
+ # Key is UPPERCASE_UNDERSCORE
97
+ #
98
+ # Example: Content-Type: text/html; charset=utf-8
99
+ # "CONTENT_TYPE" => Content-Type,["text/html; charset=utf8"]
100
+ def append_pair map, key, value
101
+ return unless key && value
102
+ return if value.is_a?(Hash)
103
+
104
+ safe_key = Contrast::Utils::StringUtils.force_utf8(key)
105
+ hash_key = Contrast::Utils::StringUtils.normalized_key(safe_key)
106
+ map[hash_key] ||= Contrast::Api::Dtm::Pair.new
107
+ map[hash_key].key = safe_key
108
+ map[hash_key].values << Contrast::Utils::StringUtils.force_utf8(value)
109
+ end
110
+
100
111
  HTTP_PREFIX = /^[Hh][Tt][Tt][Pp][_-]/i.cs__freeze
101
112
 
102
113
  # Given some holder of the content of the response's body, extract that
@@ -61,9 +61,7 @@ module Contrast
61
61
  status ||= Contrast::Agent::Patching::Policy::PatchStatus.get_status(mod)
62
62
  status.failed_rewrite!
63
63
  ensure
64
- with_contrast_scope do
65
- opener&.commit_patches
66
- end
64
+ opener&.commit_patches
67
65
  logger.trace('Rewriting complete',
68
66
  module: module_data.name,
69
67
  result: Contrast::Agent::Patching::Policy::PatchStatus.get_status(
@@ -15,67 +15,73 @@ module Contrast
15
15
  # Instead, we should say "If I'm already doing Contrast things, don't track
16
16
  # this"
17
17
  class Scope
18
- # The following %i[] list is the authoritative list
19
- # of scopes. If you define a new symbol here, you'll
20
- # get scope methods:
21
- # %i[monkey] ->
22
- # enter_monkey_scope!
23
- # exit_monkey_scope!
24
- # in_monkey_scope?
25
- # with_monkey_scope { special_monkey_function }
26
18
  SCOPE_LIST = %i[contrast deserialization].cs__freeze
27
19
 
28
- iv_list = SCOPE_LIST.map { |name| :"@#{ name }_scope" }
29
- define_method 'initialize' do
30
- iv_list.each do |iv_sym|
31
- instance_variable_set(iv_sym, 0)
32
- end
20
+ def initialize
21
+ instance_variable_set(:@contrast_scope, 0)
22
+ instance_variable_set(:@deserialization_scope, 0)
33
23
  end
34
24
 
35
- SCOPE_LIST.each do |name|
36
- iv_sym = :"@#{ name }_scope"
25
+ def in_contrast_scope?
26
+ instance_variable_get(:@contrast_scope).positive?
27
+ end
37
28
 
38
- define_method "in_#{ name }_scope?" do
39
- instance_variable_get(iv_sym).positive?
40
- end
29
+ def in_deserialization_scope?
30
+ instance_variable_get(:@deserialization_scope).positive?
31
+ end
41
32
 
42
- enter_method_sym = :"enter_#{ name }_scope!"
43
- define_method enter_method_sym do
44
- level = instance_variable_get(iv_sym)
45
- instance_variable_set(iv_sym, level + 1)
46
- end
33
+ def enter_contrast_scope!
34
+ level = instance_variable_get(:@contrast_scope)
35
+ instance_variable_set(:@contrast_scope, level + 1)
36
+ end
47
37
 
48
- exit_method_sym = :"exit_#{ name }_scope!"
49
- define_method exit_method_sym do
50
- # by design, can go below zero.
51
- # every exit/enter pair (regardless of series)
52
- # should cancel each other out.
53
- #
54
- # so we prefer this sequence:
55
- # scope = 0
56
- # exit = -1
57
- # enter = 0
58
- # enter = 1
59
- # exit = 0
60
- # scope = 0
61
- #
62
- # over this sequence:
63
- # scope = 0
64
- # exit = 0
65
- # enter = 1
66
- # enter = 2
67
- # exit = 1
68
- # scope = 1
69
- level = instance_variable_get(iv_sym)
70
- instance_variable_set(iv_sym, level - 1)
71
- end
38
+ def enter_deserialization_scope!
39
+ level = instance_variable_get(:@deserialization_scope)
40
+ instance_variable_set(:@deserialization_scope, level + 1)
41
+ end
72
42
 
73
- define_method "with_#{ name }_scope" do |*_args, &block|
74
- send enter_method_sym
75
- block.call
76
- ensure
77
- send exit_method_sym
78
- end
43
+ # Scope Exits...
44
+ # by design, can go below zero.
45
+ # every exit/enter pair (regardless of series)
46
+ # should cancel each other out.
47
+ #
48
+ # so we prefer this sequence:
49
+ # scope = 0
50
+ # exit = -1
51
+ # enter = 0
52
+ # enter = 1
53
+ # exit = 0
54
+ # scope = 0
55
+ #
56
+ # over this sequence:
57
+ # scope = 0
58
+ # exit = 0
59
+ # enter = 1
60
+ # enter = 2
61
+ # exit = 1
62
+ # scope = 1
63
+ def exit_contrast_scope!
64
+ level = instance_variable_get(:@contrast_scope)
65
+ instance_variable_set(:@contrast_scope, level - 1)
66
+ end
67
+
68
+ def exit_deserialization_scope!
69
+ level = instance_variable_get(:@deserialization_scope)
70
+ instance_variable_set(:@deserialization_scope, level - 1)
71
+ end
72
+
73
+ def with_contrast_scope
74
+ enter_contrast_scope!
75
+ yield
76
+ ensure
77
+ exit_contrast_scope!
78
+ end
79
+
80
+ def with_deserialization_scope
81
+ enter_deserialization_scope!
82
+ yield
83
+ ensure
84
+ exit_deserialization_scope!
79
85
  end
80
86
 
81
87
  # Dynamic versions of the above.
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/interface'
5
- require 'contrast/utils/gemfile_reader'
5
+ require 'contrast/agent/inventory'
6
6
  require 'contrast/api/decorators/application_update'
7
7
 
8
8
  module Contrast
@@ -17,12 +17,12 @@ module Contrast
17
17
  # report the already-loaded gems.
18
18
  def catchup
19
19
  @_catchup ||= begin
20
- with_contrast_scope do
21
- Contrast::Utils::GemfileReader.instance.map_loaded_classes
22
- send_inventory_message
23
- true
24
- end
25
- end
20
+ with_contrast_scope do
21
+ Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.catchup
22
+ send_inventory_message
23
+ true
24
+ end
25
+ end
26
26
  rescue StandardError => e
27
27
  logger.warn('Unable to run post-initialization static analysis', e)
28
28
  end
@@ -35,7 +35,7 @@ module Contrast
35
35
  path = tracepoint_event.path
36
36
  return if path&.include?('contrast')
37
37
 
38
- Contrast::Utils::InventoryUtil.inventory_class(path) if path
38
+ Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.associate_file(path) if path
39
39
  Contrast::Agent::Patching::Policy::Patcher.patch_specific_module(loaded_module)
40
40
  Contrast::Agent::Assess::Policy::RewriterPatch.rewrite_interpolation(loaded_module)
41
41
  Contrast::Agent::Assess::Policy::PolicyScanner.scan(tracepoint_event)
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Contrast
5
5
  module Agent
6
- VERSION = '3.14.0'
6
+ VERSION = '4.2.0'
7
7
  end
8
8
  end
@@ -67,10 +67,7 @@ module Contrast
67
67
  def preprocess_event event
68
68
  return unless event.is_a?(Contrast::Api::Dtm::Activity)
69
69
 
70
- # So set their tags
71
- event.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
72
-
73
- # and see if they're even enabled
70
+ # See if they're even enabled
74
71
  event.findings.delete_if { |finding| ASSESS.rule_disabled?(finding.rule_id) }
75
72
  end
76
73
  end