contrast-agent 3.12.0 → 3.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +0 -1
  3. data/.gitignore +1 -1
  4. data/.simplecov +1 -1
  5. data/Rakefile +31 -0
  6. data/ext/build_funchook.rb +0 -2
  7. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -8
  8. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
  9. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -6
  10. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -5
  11. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
  12. data/ext/cs__common/cs__common.c +24 -0
  13. data/ext/cs__common/cs__common.h +3 -0
  14. data/ext/cs__common/extconf.rb +0 -14
  15. data/ext/extconf_common.rb +0 -28
  16. data/lib/contrast.rb +3 -1
  17. data/lib/contrast/agent.rb +14 -2
  18. data/lib/contrast/agent/assess/contrast_event.rb +28 -167
  19. data/lib/contrast/agent/assess/events/source_event.rb +3 -7
  20. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
  21. data/lib/contrast/agent/assess/policy/policy_node.rb +4 -98
  22. data/lib/contrast/agent/assess/policy/propagation_method.rb +1 -2
  23. data/lib/contrast/agent/assess/policy/propagation_node.rb +5 -1
  24. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  25. data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
  26. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +9 -1
  27. data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
  28. data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
  29. data/lib/contrast/agent/assess/policy/propagator/split.rb +2 -2
  30. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -4
  31. data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
  32. data/lib/contrast/agent/assess/policy/source_method.rb +1 -2
  33. data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -10
  34. data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -4
  35. data/lib/contrast/agent/assess/properties.rb +4 -382
  36. data/lib/contrast/agent/assess/property/evented.rb +78 -0
  37. data/lib/contrast/agent/assess/property/tagged.rb +339 -0
  38. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +2 -20
  39. data/lib/contrast/agent/assess/tag.rb +27 -12
  40. data/lib/contrast/agent/at_exit_hook.rb +3 -1
  41. data/lib/contrast/agent/exclusion_matcher.rb +2 -2
  42. data/lib/contrast/agent/inventory/policy/datastores.rb +0 -1
  43. data/lib/contrast/agent/middleware.rb +2 -14
  44. data/lib/contrast/agent/patching/policy/patch.rb +1 -1
  45. data/lib/contrast/agent/patching/policy/policy.rb +3 -3
  46. data/lib/contrast/agent/patching/policy/policy_node.rb +2 -2
  47. data/lib/contrast/agent/protect/policy/rule_applicator.rb +2 -2
  48. data/lib/contrast/agent/protect/rule/base.rb +19 -31
  49. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  50. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -7
  51. data/lib/contrast/agent/protect/rule/xxe.rb +1 -0
  52. data/lib/contrast/agent/reaction_processor.rb +3 -3
  53. data/lib/contrast/agent/request.rb +92 -331
  54. data/lib/contrast/agent/request_context.rb +15 -15
  55. data/lib/contrast/agent/request_handler.rb +1 -1
  56. data/lib/contrast/agent/response.rb +2 -14
  57. data/lib/contrast/agent/scope.rb +1 -1
  58. data/lib/contrast/agent/service_heartbeat.rb +7 -9
  59. data/lib/contrast/agent/static_analysis.rb +1 -1
  60. data/lib/contrast/agent/thread_watcher.rb +49 -0
  61. data/lib/contrast/agent/version.rb +1 -1
  62. data/lib/contrast/agent/worker_thread.rb +24 -0
  63. data/lib/contrast/api.rb +3 -5
  64. data/lib/contrast/api/communication.rb +20 -0
  65. data/lib/contrast/api/communication/connection_status.rb +41 -0
  66. data/lib/contrast/api/communication/messaging_queue.rb +79 -0
  67. data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +9 -18
  68. data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
  69. data/lib/contrast/api/communication/socket.rb +45 -0
  70. data/lib/contrast/api/communication/socket_client.rb +76 -0
  71. data/lib/contrast/api/communication/speedracer.rb +111 -0
  72. data/lib/contrast/api/communication/tcp_socket.rb +31 -0
  73. data/lib/contrast/api/communication/unix_socket.rb +27 -0
  74. data/lib/contrast/api/decorators.rb +10 -0
  75. data/lib/contrast/api/decorators/address.rb +60 -0
  76. data/lib/contrast/api/decorators/application_settings.rb +7 -3
  77. data/lib/contrast/api/decorators/application_update.rb +0 -9
  78. data/lib/contrast/api/decorators/http_request.rb +139 -0
  79. data/lib/contrast/api/decorators/message.rb +75 -0
  80. data/lib/contrast/api/decorators/rasp_rule_sample.rb +28 -0
  81. data/lib/contrast/api/decorators/route_coverage.rb +57 -0
  82. data/lib/contrast/api/decorators/trace_event.rb +99 -0
  83. data/lib/contrast/api/decorators/trace_event_object.rb +57 -0
  84. data/lib/contrast/api/decorators/trace_event_signature.rb +46 -0
  85. data/lib/contrast/api/decorators/trace_taint_range.rb +51 -0
  86. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
  87. data/lib/contrast/api/decorators/user_input.rb +40 -0
  88. data/lib/contrast/components/app_context.rb +0 -7
  89. data/lib/contrast/components/config.rb +4 -9
  90. data/lib/contrast/components/interface.rb +1 -1
  91. data/lib/contrast/components/settings.rb +0 -6
  92. data/lib/contrast/configuration.rb +2 -2
  93. data/lib/contrast/extension/assess.rb +0 -1
  94. data/lib/contrast/extension/assess/assess_extension.rb +1 -2
  95. data/lib/contrast/extension/assess/fiber.rb +1 -1
  96. data/lib/contrast/extension/assess/string.rb +1 -1
  97. data/lib/contrast/extension/inventory.rb +0 -1
  98. data/lib/contrast/framework/base_support.rb +0 -23
  99. data/lib/contrast/framework/manager.rb +0 -9
  100. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
  101. data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -4
  102. data/lib/contrast/framework/rails/support.rb +3 -32
  103. data/lib/contrast/framework/sinatra/patch/base.rb +1 -1
  104. data/lib/contrast/framework/sinatra/support.rb +11 -22
  105. data/lib/contrast/funchook/funchook.rb +45 -0
  106. data/lib/contrast/logger/application.rb +1 -1
  107. data/lib/contrast/logger/format.rb +51 -0
  108. data/lib/contrast/logger/log.rb +16 -9
  109. data/lib/contrast/utils/assess/tracking_util.rb +45 -20
  110. data/lib/contrast/utils/class_util.rb +3 -1
  111. data/lib/contrast/utils/hash_digest.rb +11 -2
  112. data/lib/contrast/utils/invalid_configuration_util.rb +1 -17
  113. data/lib/contrast/utils/inventory_util.rb +2 -7
  114. data/lib/contrast/utils/object_share.rb +0 -1
  115. data/lib/contrast/utils/os.rb +16 -4
  116. data/lib/contrast/utils/stack_trace_utils.rb +0 -1
  117. data/lib/contrast/utils/tag_util.rb +1 -1
  118. data/lib/contrast/utils/thread_tracker.rb +1 -14
  119. data/lib/contrast/utils/timer.rb +1 -17
  120. data/resources/deadzone/policy.json +5 -0
  121. data/ruby-agent.gemspec +4 -4
  122. data/service_executables/VERSION +1 -1
  123. data/service_executables/linux/contrast-service +0 -0
  124. data/service_executables/mac/contrast-service +0 -0
  125. metadata +49 -71
  126. data/funchook/Makefile +0 -29
  127. data/funchook/autom4te.cache/output.0 +0 -4976
  128. data/funchook/autom4te.cache/requests +0 -78
  129. data/funchook/autom4te.cache/traces.0 +0 -364
  130. data/funchook/config.log +0 -490
  131. data/funchook/config.status +0 -1016
  132. data/funchook/configure +0 -4976
  133. data/funchook/src/Makefile +0 -70
  134. data/funchook/src/config.h +0 -101
  135. data/funchook/src/config.h.in +0 -100
  136. data/funchook/src/decoder.o +0 -0
  137. data/funchook/src/distorm.o +0 -0
  138. data/funchook/src/funchook.o +0 -0
  139. data/funchook/src/funchook_io.o +0 -0
  140. data/funchook/src/funchook_syscall.o +0 -0
  141. data/funchook/src/funchook_unix.o +0 -0
  142. data/funchook/src/funchook_x86.o +0 -0
  143. data/funchook/src/instructions.o +0 -0
  144. data/funchook/src/insts.o +0 -0
  145. data/funchook/src/libfunchook.so +0 -0
  146. data/funchook/src/mnemonics.o +0 -0
  147. data/funchook/src/operands.o +0 -0
  148. data/funchook/src/os_func.o +0 -0
  149. data/funchook/src/os_func_unix.o +0 -0
  150. data/funchook/src/prefix.o +0 -0
  151. data/funchook/src/printf_base.o +0 -0
  152. data/funchook/src/textdefs.o +0 -0
  153. data/funchook/src/wstring.o +0 -0
  154. data/funchook/test/Makefile +0 -43
  155. data/funchook/test/funchook_test +0 -0
  156. data/funchook/test/libfunchook_test.so +0 -0
  157. data/funchook/test/test_main.o +0 -0
  158. data/funchook/test/x86_64_test.o +0 -0
  159. data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
  160. data/lib/contrast/agent/socket_client.rb +0 -134
  161. data/lib/contrast/api/connection_status.rb +0 -49
  162. data/lib/contrast/api/socket.rb +0 -43
  163. data/lib/contrast/api/speedracer.rb +0 -188
  164. data/lib/contrast/api/tcp_socket.rb +0 -29
  165. data/lib/contrast/api/unix_socket.rb +0 -25
  166. data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
  167. data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
  168. data/lib/contrast/internal_exception.rb +0 -8
  169. data/lib/contrast/utils/cache.rb +0 -58
  170. data/lib/contrast/utils/service_sender_util.rb +0 -167
  171. data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -65,15 +65,11 @@ module Contrast
65
65
  # 2) I'll set the event's source and target to TS values.
66
66
  # 3) Return the highlight or the first source/target as the taint
67
67
  # target.
68
- def determine_taint_target event
68
+ def determine_taint_target event_dtm
69
69
  return unless @policy_node&.targets&.any?
70
70
 
71
- event.source = @policy_node.source_string if @policy_node.source_string
72
- event.target = if @highlight
73
- "P#{ @highlight }"
74
- else
75
- @policy_node.target_string
76
- end
71
+ event_dtm.source = @policy_node.source_string if @policy_node.source_string
72
+ event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
77
73
  @highlight || @policy_node.targets[0]
78
74
  end
79
75
  end
@@ -20,7 +20,7 @@ module Contrast
20
20
  # such that calls to that method will result in a Source Event.
21
21
  #
22
22
  # @param klass [Class] the Class to taint
23
- # @param tainted_columns [Hash<String, Contrast::Agent::Assess::Properties>]
23
+ # @param tainted_columns [Hash{String => Contrast::Agent::Assess::Properties}]
24
24
  # the name of the method to taint, mapped to the properties it
25
25
  # should apply
26
26
  def create_sources klass, tainted_columns
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  cs__scoped_require 'contrast/agent/patching/policy/policy_node'
5
+ cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
5
6
 
6
7
  module Contrast
7
8
  module Agent
@@ -69,7 +70,7 @@ module Contrast
69
70
  # 1) Split on ','
70
71
  # 2) If 'O', add the source, else it's P (we don't have R sources) and
71
72
  # needs to be converted. P type will either be P:name or P# where #
72
- # is the index of the paramter. Drop the P and store the int as int
73
+ # is the index of the parameter. Drop the P and store the int as int
73
74
  # or name as symbol
74
75
  def generate_sources
75
76
  if source_string
@@ -137,7 +138,8 @@ module Contrast
137
138
  return unless tags
138
139
 
139
140
  tags.each do |tag|
140
- next if VALID_TAGS.include?(tag) || VALID_SOURCE_TAGS.include?(tag)
141
+ next if Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
142
+ Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
141
143
 
142
144
  raise(ArgumentError,
143
145
  "#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
@@ -173,102 +175,6 @@ module Contrast
173
175
  @event_action
174
176
  end
175
177
 
176
- # EventTagTypeDTM
177
- VALID_TAGS = %w[
178
- XML_ENCODED
179
- XML_DECODED
180
- HTML_ENCODED
181
- HTML_DECODED
182
- URL_ENCODED
183
- URL_DECODED
184
- CSS_ENCODED
185
- CSS_DECODED
186
- BASE64_ENCODED
187
- BASE64_DECODED
188
- JAVASCRIPT_ENCODED
189
- JAVASCRIPT_DECODED
190
- JAVA_ENCODED
191
- JAVA_DECODED
192
- CSV_ENCODED
193
- CSV_DECODED
194
- SQL_ENCODED
195
- SQL_DECODED
196
- LDAP_ENCODED
197
- LDAP_DECODED
198
- XPATH_ENCODED
199
- XPATH_DECODED
200
- OS_ENCODED
201
- OS_DECODED
202
- VBSCRIPT_ENCODED
203
- VBSCRIPT_DECODED
204
- POTENTIAL_SANITIZED
205
- POTENTIAL_VALIDATED
206
- NO_CONTROL_CHARS
207
- CUSTOM
208
-
209
- CUSTOM_ENCODED
210
- CUSTOM_ENCODED_CMD_INJECTION
211
- CUSTOM_ENCODED_EXPRESSION_LANGUAGE_INJECTION
212
- CUSTOM_ENCODED_HEADER_INJECTION
213
- CUSTOM_ENCODED_HQL_INJECTION
214
- CUSTOM_ENCODED_LDAP_INJECTION
215
- CUSTOM_ENCODED_LOG_INJECTION
216
- CUSTOM_ENCODED_NOSQL_INJECTION
217
- CUSTOM_ENCODED_PATH_TRAVERSAL
218
- CUSTOM_ENCODED_REDOS
219
- CUSTOM_ENCODED_REFLECTED_XSS
220
- CUSTOM_ENCODED_REFLECTION_INJECTION
221
- CUSTOM_ENCODED_SMTP_INJECTION
222
- CUSTOM_ENCODED_SQL_INJECTION
223
- CUSTOM_ENCODED_SSRF
224
- CUSTOM_ENCODED_STORED_XSS
225
- CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION
226
- CUSTOM_ENCODED_UNSAFE_CODE_EXECUTION
227
- CUSTOM_ENCODED_UNSAFE_READLINE
228
- CUSTOM_ENCODED_UNSAFE_XML_DECODE
229
- CUSTOM_ENCODED_UNTRUSTED_DESERIALIZATION
230
- CUSTOM_ENCODED_UNVALIDATED_FORWARD
231
- CUSTOM_ENCODED_UNVALIDATED_REDIRECT
232
- CUSTOM_ENCODED_XPATH_INJECTION
233
- CUSTOM_ENCODED_XXE
234
- CUSTOM_SECURITY_CONTROL_APPLIED
235
-
236
- CUSTOM_VALIDATED
237
- CUSTOM_VALIDATED_CMD_INJECTION
238
- CUSTOM_VALIDATED_EXPRESSION_LANGUAGE_INJECTION
239
- CUSTOM_VALIDATED_HEADER_INJECTION
240
- CUSTOM_VALIDATED_HQL_INJECTION
241
- CUSTOM_VALIDATED_LDAP_INJECTION
242
- CUSTOM_VALIDATED_LOG_INJECTION
243
- CUSTOM_VALIDATED_NOSQL_INJECTION
244
- CUSTOM_VALIDATED_PATH_TRAVERSAL
245
- CUSTOM_VALIDATED_REDOS
246
- CUSTOM_VALIDATED_REFLECTED_XSS
247
- CUSTOM_VALIDATED_REFLECTION_INJECTION
248
- CUSTOM_VALIDATED_SMTP_INJECTION
249
- CUSTOM_VALIDATED_SQL_INJECTION
250
- CUSTOM_VALIDATED_SSRF
251
- CUSTOM_VALIDATED_STORED_XSS
252
- CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION
253
- CUSTOM_VALIDATED_UNSAFE_CODE_EXECUTION
254
- CUSTOM_VALIDATED_UNSAFE_READLINE
255
- CUSTOM_VALIDATED_UNSAFE_XML_DECODE
256
- CUSTOM_VALIDATED_UNTRUSTED_DESERIALIZATION
257
- CUSTOM_VALIDATED_UNVALIDATED_FORWARD
258
- CUSTOM_VALIDATED_UNVALIDATED_REDIRECT
259
- CUSTOM_VALIDATED_XPATH_INJECTION
260
- CUSTOM_VALIDATED_XXE
261
-
262
- DATABASE_WRITE
263
- ].cs__freeze
264
-
265
- VALID_SOURCE_TAGS = %w[
266
- NO_NEWLINES
267
- UNTRUSTED
268
- CROSS_SITE
269
- LIMITED_CHARS
270
- ].cs__freeze
271
-
272
178
  # The keys used to read from policy.json to create the individual
273
179
  # policy nodes. These are common across node types
274
180
  JSON_SOURCE = 'source'
@@ -203,8 +203,7 @@ module Contrast
203
203
 
204
204
  length = Contrast::Utils::StringUtils.ret_length(target)
205
205
  propagation_node.tags.each do |tag|
206
- span = Contrast::Agent::Assess::AdjustedSpan.new(0, length)
207
- target.cs__properties.add_tag(tag, span)
206
+ target.cs__properties.add_tag(tag, 0...length)
208
207
  end
209
208
  end
210
209
 
@@ -2,6 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  cs__scoped_require 'contrast/agent/assess/policy/policy_node'
5
+ cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
6
+
5
7
  module Contrast
6
8
  module Agent
7
9
  module Assess
@@ -73,7 +75,9 @@ module Contrast
73
75
  return unless untags
74
76
 
75
77
  untags.each do |tag|
76
- raise(ArgumentError, "#{ node_type } #{ id } did not have a valid untag. #{ tag } is not a known value.") unless VALID_TAGS.include?(tag)
78
+ unless Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag)
79
+ raise(ArgumentError, "#{ node_type } #{ id } did not have a valid untag. #{ tag } is not a known value.")
80
+ end
77
81
  raise(ArgumentError, "#{ node_type } #{ id } had the same tag and untag, #{ tag }.") if tags&.include?(tag)
78
82
  end
79
83
  end
@@ -26,7 +26,7 @@ module Contrast
26
26
  end
27
27
 
28
28
  def propagate _propagation_node, _preshift, _target
29
- raise NotImplementedError("Expected Base propagator subclass: #{ cs__class } to implement #propagate")
29
+ raise NoMethodError("Expected Base propagator subclass: #{ cs__class } to implement #propagate")
30
30
  end
31
31
  end
32
32
  end
@@ -35,10 +35,7 @@ module Contrast
35
35
  # Depending what's inserted, we might be wrong. For instance, inserting 'foo'
36
36
  # into 'asdfasdf' could result in 'asdfoofasdf'. we'd be off by one b/c of the 'f'
37
37
  insert_point = target.rindex(source, insert_point)
38
-
39
- overflow = Contrast::Agent::Assess::AdjustedSpan.new(
40
- insert_point,
41
- insert_point + source.length)
38
+ overflow = insert_point...(insert_point + source.length)
42
39
 
43
40
  # handle shifting the inserted range
44
41
  target.cs__properties.shift_tags([overflow])
@@ -14,6 +14,8 @@ module Contrast
14
14
  def square_bracket_tagger propagation_node, preshift, ret, _block
15
15
  if ret.is_a?(Array)
16
16
  ret.each_with_index do |return_value, index|
17
+ next unless return_value
18
+
17
19
  target_matchdata_index = if preshift.args[0].is_a?(Range)
18
20
  arg_range = preshift.args[0]
19
21
  arg_range.to_a.empty? ? index + 1 : arg_range.to_a[index]
@@ -32,6 +34,8 @@ module Contrast
32
34
 
33
35
  def captures_tagger propagation_node, preshift, ret, _block
34
36
  ret.each_with_index do |return_value, index|
37
+ next unless return_value
38
+
35
39
  targetted_index = index + 1
36
40
  square_bracket_single(targetted_index, preshift, return_value, propagation_node)
37
41
  end
@@ -40,6 +44,8 @@ module Contrast
40
44
 
41
45
  def to_a_tagger propagation_node, preshift, ret, _block
42
46
  ret.each_with_index do |return_value, index|
47
+ next unless return_value
48
+
43
49
  square_bracket_single(index, preshift, return_value, propagation_node)
44
50
  end
45
51
  ret
@@ -47,6 +53,8 @@ module Contrast
47
53
 
48
54
  def values_at_tagger propagation_node, preshift, ret, _block
49
55
  ret.each_with_index do |return_value, return_index|
56
+ next unless return_value
57
+
50
58
  original_group_arg_index = preshift.args[return_index]
51
59
  square_bracket_single(original_group_arg_index, preshift, return_value, propagation_node)
52
60
  end
@@ -59,7 +67,7 @@ module Contrast
59
67
  original_start_index = preshift.object.begin(argument_index)
60
68
  original_end_index = preshift.object.end(argument_index)
61
69
  original_properties = preshift.object.cs__properties
62
- applicable_tags = original_properties.tags_at_range(Contrast::Agent::Assess::AdjustedSpan.new(original_start_index, original_end_index))
70
+ applicable_tags = original_properties.tags_at_range(original_start_index...original_end_index)
63
71
  return if applicable_tags.empty?
64
72
 
65
73
  applicable_tags.each do |tag_name, tag_ranges|
@@ -32,7 +32,7 @@ module Contrast
32
32
  target_idx = 0
33
33
 
34
34
  remove_ranges = []
35
- current_range = nil
35
+ start = nil
36
36
 
37
37
  # loop over the target, the result of the delete
38
38
  # every range of characters that it differs from the source
@@ -44,13 +44,12 @@ module Contrast
44
44
  source_char = source_chars[source_idx]
45
45
  if target_char == source_char
46
46
  target_idx += 1
47
- if current_range
48
- current_range.stop = source_idx
49
- remove_ranges << current_range
50
- current_range = nil
47
+ if start
48
+ remove_ranges << (start...source_idx)
49
+ start = nil
51
50
  end
52
51
  else
53
- current_range ||= Contrast::Agent::Assess::AdjustedSpan.new(source_idx)
52
+ start ||= source_idx
54
53
  end
55
54
  source_idx += 1
56
55
  end
@@ -58,11 +57,7 @@ module Contrast
58
57
  # once we're done looping over the target, anything left
59
58
  # over is extra from the source that was deleted. tags
60
59
  # applying to it need to be removed.
61
- if source_idx != source_chars.length
62
- remove_ranges << Contrast::Agent::Assess::AdjustedSpan.new(
63
- source_idx,
64
- source_chars.length)
65
- end
60
+ remove_ranges << (source_idx...source_chars.length) if source_idx != source_chars.length
66
61
 
67
62
  # handle deleting the removed ranges
68
63
  target.cs__properties.delete_tags_at_ranges(remove_ranges)
@@ -50,19 +50,19 @@ module Contrast
50
50
  length = args[1] || 1
51
51
  # (void) negative range
52
52
  arg += source.length if arg.negative?
53
- Contrast::Agent::Assess::AdjustedSpan.new(arg, arg + length)
53
+ arg...(arg + length)
54
54
  end
55
55
 
56
56
  def handle_string arg, source
57
57
  idx = source.index(arg)
58
- Contrast::Agent::Assess::AdjustedSpan.new(idx, idx + arg.length)
58
+ idx...(idx + arg.length)
59
59
  end
60
60
 
61
61
  def handle_regexp args, arg, source
62
62
  match_data = arg.match(source)
63
63
  # nil has the same meaning as 0. use full match
64
64
  group = args[1] || 0
65
- Contrast::Agent::Assess::AdjustedSpan.new(match_data.begin(group), match_data.end(group))
65
+ match_data.begin(group)...match_data.end(group)
66
66
  end
67
67
 
68
68
  def handle_range arg, source
@@ -74,7 +74,7 @@ module Contrast
74
74
  finish += source.length if finish.negative?
75
75
  finish += 1 unless arg.exclude_end?
76
76
 
77
- Contrast::Agent::Assess::AdjustedSpan.new(start, finish)
77
+ start...finish
78
78
  end
79
79
 
80
80
  def determine_select_range source, args
@@ -52,7 +52,7 @@ module Contrast
52
52
  current_index = 0
53
53
  target.each do |elem|
54
54
  elem_length = elem.length
55
- range = Contrast::Agent::Assess::AdjustedSpan.new(current_index, current_index + elem_length)
55
+ range = current_index...(current_index + elem_length)
56
56
  tags = source.cs__properties.tags_at_range(range)
57
57
 
58
58
  elem.cs__properties.clear_tags
@@ -139,7 +139,7 @@ module Contrast
139
139
  def instrument_string_split
140
140
  if @_instrument_string_split.nil?
141
141
  @_instrument_string_split = begin
142
- cs__scoped_require 'cs__assess_yield_track/cs__assess_yield_track' if AGENT.patch_yield?
142
+ cs__scoped_require 'cs__assess_yield_track/cs__assess_yield_track' if AGENT.patch_yield? && Funchook.available?
143
143
  true
144
144
  rescue StandardError => e
145
145
  logger.error('Error loading split rb_yield patch', e)
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  cs__scoped_require 'contrast/components/interface'
5
+ cs__scoped_require 'contrast/utils/duck_utils'
5
6
 
6
7
  module Contrast
7
8
  module Agent
@@ -109,7 +110,7 @@ module Contrast
109
110
  last_idx = idx ? idx + 1 : nil
110
111
  start_index = idx
111
112
  end_index = idx + incoming.length
112
- ranges << Contrast::Agent::Assess::AdjustedSpan.new(start_index, end_index)
113
+ ranges << (start_index...end_index)
113
114
  break unless global
114
115
  end
115
116
  ret.cs__properties.delete_tags_at_ranges(ranges)
@@ -133,12 +134,11 @@ module Contrast
133
134
  end
134
135
 
135
136
  def pattern_gsub preshift, ret
136
- return unless ret
137
+ return unless Contrast::Utils::DuckUtils.trackable?(ret)
137
138
 
138
139
  source = preshift.object
139
140
  source.cs__properties.tag_keys.each do |key|
140
- span = Contrast::Agent::Assess::AdjustedSpan.new(0, 1)
141
- ret.cs__properties.add_tag(key, span)
141
+ ret.cs__properties.add_tag(key, 0...1)
142
142
  end
143
143
  end
144
144
 
@@ -28,23 +28,19 @@ module Contrast
28
28
  else
29
29
  remove_ranges = []
30
30
  ret_chars = ret.chars
31
- curr_span = nil
31
+ start = nil
32
32
  source_chars.each_with_index do |char, idx|
33
33
  if ret_chars[idx] == char
34
- next unless curr_span
34
+ next unless start
35
35
 
36
- curr_span.stop = idx
37
- remove_ranges << curr_span
38
- curr_span = nil
36
+ remove_ranges << (start...idx)
37
+ start = nil
39
38
  else
40
- curr_span ||= Contrast::Agent::Assess::AdjustedSpan.new(idx)
39
+ start ||= idx
41
40
  end
42
41
  end
43
42
  # account for the last char being different
44
- if curr_span
45
- curr_span.stop = source_chars.length
46
- remove_ranges << curr_span
47
- end
43
+ remove_ranges << (start...source_chars.length) if start
48
44
  ret.cs__properties.delete_tags_at_ranges(remove_ranges, false)
49
45
  end
50
46
 
@@ -12,7 +12,6 @@ cs__scoped_require 'set'
12
12
 
13
13
  cs__scoped_require 'contrast/utils/object_share'
14
14
  cs__scoped_require 'contrast/utils/sha256_builder'
15
- cs__scoped_require 'contrast/agent/assess/adjusted_span'
16
15
  cs__scoped_require 'contrast/agent/assess/policy/source_validation/source_validation'
17
16
 
18
17
  cs__scoped_require 'contrast/components/interface'
@@ -170,7 +169,7 @@ module Contrast
170
169
  next unless Contrast::Agent::Assess::Policy::SourceValidation.valid?(tag, source_type, source_name)
171
170
 
172
171
  length = Contrast::Utils::StringUtils.ret_length(target)
173
- target.cs__properties.add_tag(tag, Contrast::Agent::Assess::AdjustedSpan.new(0, length))
172
+ target.cs__properties.add_tag(tag, 0...length)
174
173
  target.cs__properties.add_properties(source_node.properties)
175
174
  logger.trace('Source detected',
176
175
  node_id: source_node.id,
@@ -18,7 +18,7 @@ module Contrast
18
18
  # it was not, a Finding report is issued to the Service
19
19
  module TriggerMethod
20
20
  include Contrast::Components::Interface
21
- access_component :analysis, :logging, :settings
21
+ access_component :analysis, :logging
22
22
 
23
23
  # The level of TeamServer compliance our traces meet
24
24
  CURRENT_FINDING_VERSION = 2
@@ -89,14 +89,12 @@ module Contrast
89
89
 
90
90
  finding = Contrast::Api::Dtm::Finding.new
91
91
  finding.rule_id = Contrast::Utils::StringUtils.protobuf_safe_string(trigger_node.rule_id)
92
- finding.session_id = SETTINGS.session_id
93
92
  finding.version = CURRENT_FINDING_VERSION
94
93
 
95
94
  build_from_source(finding, source)
96
95
  trigger_event = Contrast::Agent::Assess::Events::EventFactory.build(trigger_node, source, object, ret, args).to_dtm_event
97
96
  finding.events << trigger_event
98
97
  build_hash(finding, source)
99
- build_tags(context)
100
98
  finding.routes << context.route if context.route
101
99
  context.activity.findings << finding
102
100
  logger.trace('Finding created',
@@ -230,7 +228,7 @@ module Contrast
230
228
  else
231
229
  logger.warn('Trigger source is of unknown type. Unable to inspect.',
232
230
  node_id: trigger_node.id,
233
- source_id: target.__id__,
231
+ source_id: source.__id__,
234
232
  source_type: source.cs__class.to_s)
235
233
  logger.trace(source.to_s[0..99])
236
234
  end
@@ -265,12 +263,6 @@ module Contrast
265
263
  finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash_code)
266
264
  finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
267
265
  end
268
-
269
- def build_tags context
270
- return unless ASSESS.tags
271
-
272
- context.activity.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
273
- end
274
266
  end
275
267
  end
276
268
  end