contrast-agent 3.13.0 → 3.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/exe/contrast_service +1 -7
  3. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  4. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  5. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  6. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
  7. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  8. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
  11. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  12. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  13. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  14. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  15. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  16. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
  17. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
  18. data/ext/cs__common/cs__common.c +48 -39
  19. data/ext/cs__common/cs__common.h +16 -21
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  21. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  22. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  23. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  24. data/lib/contrast-agent.rb +1 -1
  25. data/lib/contrast.rb +13 -23
  26. data/lib/contrast/agent.rb +39 -46
  27. data/lib/contrast/agent/assess.rb +12 -12
  28. data/lib/contrast/agent/assess/contrast_event.rb +151 -85
  29. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  30. data/lib/contrast/agent/assess/events/source_event.rb +3 -3
  31. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  32. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  33. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
  34. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  35. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  36. data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
  37. data/lib/contrast/agent/assess/policy/policy_scanner.rb +9 -4
  38. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  39. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
  40. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
  41. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  42. data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
  43. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  45. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  47. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
  48. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  49. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
  50. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  51. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  52. data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
  53. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  54. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  55. data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
  56. data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
  57. data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
  58. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
  59. data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
  60. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  61. data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
  62. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
  65. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  66. data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
  67. data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
  68. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  69. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  70. data/lib/contrast/agent/assess/properties.rb +15 -5
  71. data/lib/contrast/agent/assess/property/evented.rb +7 -20
  72. data/lib/contrast/agent/assess/property/tagged.rb +13 -7
  73. data/lib/contrast/agent/assess/property/updated.rb +131 -0
  74. data/lib/contrast/agent/assess/rule.rb +2 -2
  75. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  76. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  77. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  78. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
  79. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +84 -16
  80. data/lib/contrast/agent/assess/tag.rb +1 -1
  81. data/lib/contrast/agent/assess/tracker.rb +66 -0
  82. data/lib/contrast/agent/at_exit_hook.rb +6 -6
  83. data/lib/contrast/agent/class_reopener.rb +14 -11
  84. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  85. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  86. data/lib/contrast/agent/disable_reaction.rb +1 -1
  87. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  88. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  89. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  90. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  91. data/lib/contrast/agent/middleware.rb +32 -32
  92. data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
  93. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
  94. data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
  95. data/lib/contrast/agent/patching/policy/patch.rb +15 -15
  96. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  97. data/lib/contrast/agent/patching/policy/policy.rb +23 -12
  98. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  99. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  100. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
  101. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  102. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  103. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  104. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  105. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
  106. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  107. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  108. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  109. data/lib/contrast/agent/protect/rule.rb +18 -18
  110. data/lib/contrast/agent/protect/rule/base.rb +4 -3
  111. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  112. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  113. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  114. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  115. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  116. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  117. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  118. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  119. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  120. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  121. data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
  122. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  123. data/lib/contrast/agent/railtie.rb +1 -1
  124. data/lib/contrast/agent/reaction_processor.rb +2 -2
  125. data/lib/contrast/agent/request.rb +45 -43
  126. data/lib/contrast/agent/request_context.rb +10 -6
  127. data/lib/contrast/agent/response.rb +23 -12
  128. data/lib/contrast/agent/rewriter.rb +6 -9
  129. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  130. data/lib/contrast/agent/static_analysis.rb +9 -9
  131. data/lib/contrast/agent/thread.rb +1 -1
  132. data/lib/contrast/agent/thread_watcher.rb +2 -2
  133. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  134. data/lib/contrast/agent/version.rb +1 -1
  135. data/lib/contrast/api.rb +4 -4
  136. data/lib/contrast/api/communication.rb +9 -9
  137. data/lib/contrast/api/communication/messaging_queue.rb +3 -6
  138. data/lib/contrast/api/communication/response_processor.rb +1 -1
  139. data/lib/contrast/api/communication/socket_client.rb +41 -6
  140. data/lib/contrast/api/communication/speedracer.rb +1 -1
  141. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  142. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  143. data/lib/contrast/api/decorators.rb +14 -14
  144. data/lib/contrast/api/decorators/address.rb +20 -19
  145. data/lib/contrast/api/decorators/application_settings.rb +3 -2
  146. data/lib/contrast/api/decorators/application_update.rb +7 -8
  147. data/lib/contrast/api/decorators/http_request.rb +13 -12
  148. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  149. data/lib/contrast/api/decorators/message.rb +4 -2
  150. data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
  151. data/lib/contrast/api/decorators/route_coverage.rb +3 -2
  152. data/lib/contrast/api/decorators/server_features.rb +3 -2
  153. data/lib/contrast/api/decorators/trace_event.rb +28 -25
  154. data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
  155. data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
  156. data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
  157. data/lib/contrast/api/decorators/user_input.rb +4 -4
  158. data/lib/contrast/common_agent_configuration.rb +2 -2
  159. data/lib/contrast/components/agent.rb +2 -2
  160. data/lib/contrast/components/app_context.rb +50 -39
  161. data/lib/contrast/components/config.rb +7 -17
  162. data/lib/contrast/components/contrast_service.rb +10 -10
  163. data/lib/contrast/components/interface.rb +15 -15
  164. data/lib/contrast/components/logger.rb +1 -1
  165. data/lib/contrast/components/scope.rb +3 -3
  166. data/lib/contrast/components/settings.rb +20 -23
  167. data/lib/contrast/config.rb +18 -18
  168. data/lib/contrast/config/application_configuration.rb +5 -2
  169. data/lib/contrast/config/base_configuration.rb +2 -2
  170. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  171. data/lib/contrast/config/service_configuration.rb +8 -0
  172. data/lib/contrast/configuration.rb +93 -52
  173. data/lib/contrast/extension/assess.rb +21 -22
  174. data/lib/contrast/extension/assess/array.rb +18 -11
  175. data/lib/contrast/extension/assess/erb.rb +11 -3
  176. data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
  177. data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
  178. data/lib/contrast/extension/assess/fiber.rb +14 -14
  179. data/lib/contrast/extension/assess/hash.rb +7 -6
  180. data/lib/contrast/extension/assess/kernel.rb +34 -28
  181. data/lib/contrast/extension/assess/marshal.rb +67 -0
  182. data/lib/contrast/extension/assess/regexp.rb +10 -9
  183. data/lib/contrast/extension/assess/string.rb +23 -23
  184. data/lib/contrast/extension/inventory.rb +4 -4
  185. data/lib/contrast/extension/kernel.rb +1 -1
  186. data/lib/contrast/extension/module.rb +1 -1
  187. data/lib/contrast/extension/protect.rb +3 -3
  188. data/lib/contrast/extension/protect/kernel.rb +4 -4
  189. data/lib/contrast/extension/protect/psych.rb +2 -2
  190. data/lib/contrast/framework/base_support.rb +1 -1
  191. data/lib/contrast/framework/manager.rb +10 -11
  192. data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
  193. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  194. data/lib/contrast/framework/rack/support.rb +2 -2
  195. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  196. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
  197. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
  198. data/lib/contrast/framework/rails/patch/support.rb +4 -4
  199. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  200. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  201. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  202. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  203. data/lib/contrast/framework/rails/support.rb +64 -14
  204. data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
  205. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  206. data/lib/contrast/framework/sinatra/support.rb +6 -6
  207. data/lib/contrast/funchook/funchook.rb +1 -1
  208. data/lib/contrast/logger/application.rb +13 -5
  209. data/lib/contrast/logger/format.rb +22 -9
  210. data/lib/contrast/logger/log.rb +17 -10
  211. data/lib/contrast/logger/request.rb +30 -0
  212. data/lib/contrast/tasks/config.rb +1 -1
  213. data/lib/contrast/tasks/service.rb +2 -2
  214. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  215. data/lib/contrast/utils/assess/tracking_util.rb +49 -4
  216. data/lib/contrast/utils/boolean_util.rb +1 -1
  217. data/lib/contrast/utils/class_util.rb +2 -2
  218. data/lib/contrast/utils/duck_utils.rb +0 -10
  219. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  220. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  221. data/lib/contrast/utils/hash_digest.rb +2 -1
  222. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  223. data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
  224. data/lib/contrast/utils/inventory_util.rb +4 -4
  225. data/lib/contrast/utils/io_util.rb +1 -1
  226. data/lib/contrast/utils/os.rb +1 -1
  227. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  228. data/lib/contrast/utils/sha256_builder.rb +2 -2
  229. data/lib/contrast/utils/stack_trace_utils.rb +2 -2
  230. data/lib/contrast/utils/string_utils.rb +11 -6
  231. data/resources/assess/policy.json +31 -22
  232. data/resources/deadzone/policy.json +5 -0
  233. data/ruby-agent.gemspec +21 -19
  234. data/service_executables/VERSION +1 -1
  235. data/service_executables/linux/contrast-service +0 -0
  236. data/service_executables/mac/contrast-service +0 -0
  237. metadata +67 -29
  238. data/lib/contrast/agent/assess/insulator.rb +0 -49
  239. data/lib/contrast/agent/require_state.rb +0 -61
  240. data/lib/contrast/extension/assess/assess_extension.rb +0 -147
  241. data/lib/contrast/utils/freeze_util.rb +0 -32
@@ -1,8 +1,8 @@
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
- cs__scoped_require 'contrast/agent/assess/policy/policy_node'
5
- cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
4
+ require 'contrast/agent/assess/policy/policy_node'
5
+ require 'contrast/api/decorators/trace_taint_range_tags'
6
6
 
7
7
  module Contrast
8
8
  module Agent
@@ -10,25 +10,25 @@ module Contrast
10
10
  # functionality. Any class under this namespace should be required
11
11
  # here, providing a single point of require for this functionality.
12
12
  module Propagator
13
- cs__scoped_require 'contrast/agent/assess/policy/propagator/base'
13
+ require 'contrast/agent/assess/policy/propagator/base'
14
14
 
15
- cs__scoped_require 'contrast/agent/assess/policy/propagator/append'
16
- cs__scoped_require 'contrast/agent/assess/policy/propagator/center'
17
- cs__scoped_require 'contrast/agent/assess/policy/propagator/custom'
18
- cs__scoped_require 'contrast/agent/assess/policy/propagator/database_write'
19
- cs__scoped_require 'contrast/agent/assess/policy/propagator/insert'
20
- cs__scoped_require 'contrast/agent/assess/policy/propagator/keep'
21
- cs__scoped_require 'contrast/agent/assess/policy/propagator/match_data'
22
- cs__scoped_require 'contrast/agent/assess/policy/propagator/next'
23
- cs__scoped_require 'contrast/agent/assess/policy/propagator/prepend'
24
- cs__scoped_require 'contrast/agent/assess/policy/propagator/remove'
25
- cs__scoped_require 'contrast/agent/assess/policy/propagator/replace'
26
- cs__scoped_require 'contrast/agent/assess/policy/propagator/reverse'
27
- cs__scoped_require 'contrast/agent/assess/policy/propagator/select'
28
- cs__scoped_require 'contrast/agent/assess/policy/propagator/splat'
29
- cs__scoped_require 'contrast/agent/assess/policy/propagator/split'
30
- cs__scoped_require 'contrast/agent/assess/policy/propagator/substitution'
31
- cs__scoped_require 'contrast/agent/assess/policy/propagator/trim'
15
+ require 'contrast/agent/assess/policy/propagator/append'
16
+ require 'contrast/agent/assess/policy/propagator/center'
17
+ require 'contrast/agent/assess/policy/propagator/custom'
18
+ require 'contrast/agent/assess/policy/propagator/database_write'
19
+ require 'contrast/agent/assess/policy/propagator/insert'
20
+ require 'contrast/agent/assess/policy/propagator/keep'
21
+ require 'contrast/agent/assess/policy/propagator/match_data'
22
+ require 'contrast/agent/assess/policy/propagator/next'
23
+ require 'contrast/agent/assess/policy/propagator/prepend'
24
+ require 'contrast/agent/assess/policy/propagator/remove'
25
+ require 'contrast/agent/assess/policy/propagator/replace'
26
+ require 'contrast/agent/assess/policy/propagator/reverse'
27
+ require 'contrast/agent/assess/policy/propagator/select'
28
+ require 'contrast/agent/assess/policy/propagator/splat'
29
+ require 'contrast/agent/assess/policy/propagator/split'
30
+ require 'contrast/agent/assess/policy/propagator/substitution'
31
+ require 'contrast/agent/assess/policy/propagator/trim'
32
32
  end
33
33
  end
34
34
  end
@@ -16,6 +16,9 @@ module Contrast
16
16
  # copy tags from the param to the target in chunks of param size or less
17
17
  # if param is appended in space less than param length
18
18
  def propagate propagation_node, preshift, target
19
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
20
+ return unless properties
21
+
19
22
  sources = propagation_node.sources
20
23
  source1 = find_source(sources[0], preshift)
21
24
  # Some appends have two args. If they don't this is probably something
@@ -25,25 +28,25 @@ module Contrast
25
28
  # if the object and the return are the same length just copy the tags
26
29
  # from the object(since nothing from args was added to return)
27
30
  if source1.length == target.length
28
- target.cs__copy_from(source1, 0, propagation_node.untags)
31
+ properties.copy_from(source1, target, 0, propagation_node.untags)
29
32
  else
30
33
  # find original in the target, copy tags to the new position in
31
34
  # target
32
35
  original_start_index = target.index(source1)
33
- target.cs__copy_from(source1, original_start_index, propagation_node.untags)
36
+ properties.copy_from(source1, target, original_start_index, propagation_node.untags)
34
37
 
35
38
  start = original_start_index + source1.length
36
39
  while start < target.length
37
- target.cs__copy_from(source2, start, propagation_node.untags)
40
+ properties.copy_from(source2, target, start, propagation_node.untags)
38
41
  start += source2.length
39
42
  next unless start > target.length
40
43
 
41
- target.cs__properties.tags_at(start - source2.length).each do |tag|
44
+ properties.tags_at(start - source2.length).each do |tag|
42
45
  tag.update_end(target.length)
43
46
  end
44
47
  end
45
48
  end
46
- target.cs__properties.cleanup_tags
49
+ properties.cleanup_tags
47
50
  end
48
51
  end
49
52
  end
@@ -22,7 +22,7 @@ module Contrast
22
22
  end
23
23
 
24
24
  def tracked_value? value
25
- Contrast::Utils::DuckUtils.quacks_to?(value, :cs__tracked?) && value.cs__tracked?
25
+ Contrast::Agent::Assess::Tracker.tracked?(value)
26
26
  end
27
27
 
28
28
  def propagate _propagation_node, _preshift, _target
@@ -12,19 +12,22 @@ module Contrast
12
12
  class Center < Contrast::Agent::Assess::Policy::Propagator::Base
13
13
  class << self
14
14
  def propagate propagation_node, preshift, target
15
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
16
+ return unless properties
17
+
15
18
  sources = propagation_node.sources
16
19
  source1 = find_source(sources[0], preshift)
17
20
 
18
21
  if source1.length == target.length
19
- target.cs__copy_from(source1, 0, propagation_node.untags)
20
- target.cs__properties.cleanup_tags
22
+ properties.copy_from(source1, target, 0, propagation_node.untags)
23
+ properties.cleanup_tags
21
24
  return
22
25
  end
23
26
 
24
27
  # find original in the target, copy tags to the new position in target
25
28
  original_start_index = target[0..target.length / 2 + 1].rindex(source1)
26
29
  original_start_index ||= 1
27
- target.cs__copy_from(source1, original_start_index, propagation_node.untags)
30
+ properties.copy_from(source1, target, original_start_index, propagation_node.untags)
28
31
 
29
32
  return unless sources[1]
30
33
 
@@ -54,12 +57,13 @@ module Contrast
54
57
  end
55
58
 
56
59
  def iterate_tags target, propagation_node, source, start, stop
60
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
57
61
  while start < stop
58
- target.cs__copy_from(source, start, propagation_node.untags)
62
+ properties.copy_from(source, target, start, propagation_node.untags)
59
63
  start += source.length
60
64
  next unless start > stop
61
65
 
62
- target.cs__properties.tags_at(start - source.length).each do |tag|
66
+ properties.tags_at(start - source.length).each do |tag|
63
67
  tag.update_end(stop)
64
68
  end
65
69
  end
@@ -1,7 +1,7 @@
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
- cs__scoped_require 'contrast/extension/module'
4
+ require 'contrast/extension/module'
5
5
 
6
6
  module Contrast
7
7
  module Agent
@@ -1,7 +1,7 @@
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
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Agent
@@ -31,12 +31,15 @@ module Contrast
31
31
  next unless value
32
32
  next if known_tainted&.include?(key)
33
33
 
34
+ properties = Contrast::Agent::Assess::Tracker.properties(value)
35
+ next unless properties
36
+
34
37
  # TODO: RUBY-540 handle sanitization, handle nested objects
35
38
  Contrast::Agent::Assess::Policy::PropagationMethod.apply_tags(propagation_node, value)
36
- value.cs__properties.build_event(propagation_node, value, preshift.object, target, preshift.args)
39
+ properties.build_event(propagation_node, value, preshift.object, target, preshift.args)
37
40
  next unless tracked_value?(value)
38
41
 
39
- tainted_columns[key] = value.cs__properties
42
+ tainted_columns[key] = properties
40
43
  end
41
44
  end
42
45
 
@@ -45,7 +48,6 @@ module Contrast
45
48
  if known_tainted
46
49
  known_tainted.concat(tainted_columns.keys)
47
50
  else
48
- class_type.send(:include, Contrast::Extension::Assess::AssessExtension) unless class_type < Contrast::Extension::Assess::AssessExtension
49
51
  ASSESS.tainted_columns[class_name] = tainted_columns.keys
50
52
  end
51
53
 
@@ -16,7 +16,10 @@ module Contrast
16
16
  # Unlike additive propagation, this currently only supports one source
17
17
  # We assume that insert changes the preshift target
18
18
  def propagate propagation_node, preshift, target
19
- source = find_source(propagation_node.sources[0], preshift)
19
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
20
+ return unless properties
21
+
22
+ source = find_source(propagation_node.sources[1], preshift)
20
23
 
21
24
  patcher_target = propagation_node.targets[0]
22
25
  preshift_target = case patcher_target
@@ -38,10 +41,10 @@ module Contrast
38
41
  overflow = insert_point...(insert_point + source.length)
39
42
 
40
43
  # handle shifting the inserted range
41
- target.cs__properties.shift_tags([overflow])
44
+ properties.shift_tags([overflow])
42
45
 
43
- target.cs__copy_from(source, insert_point, propagation_node.untags)
44
- target.cs__properties.cleanup_tags
46
+ properties.copy_from(source, target, insert_point, propagation_node.untags)
47
+ properties.cleanup_tags
45
48
  end
46
49
  end
47
50
  end
@@ -14,8 +14,11 @@ module Contrast
14
14
  # Keep means the tags just pass from the source to the target
15
15
  # as is.
16
16
  def propagate propagation_node, preshift, target
17
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
18
+ return unless properties
19
+
17
20
  source = find_source(propagation_node.sources[0], preshift)
18
- target.cs__copy_from(source, 0, propagation_node.untags)
21
+ properties.copy_from(source, target, 0, propagation_node.untags)
19
22
  end
20
23
  end
21
24
  end
@@ -12,7 +12,8 @@ module Contrast
12
12
  class MatchData < Contrast::Agent::Assess::Policy::Propagator::Base
13
13
  class << self
14
14
  def square_bracket_tagger propagation_node, preshift, ret, _block
15
- if ret.is_a?(Array)
15
+ case ret
16
+ when Array
16
17
  ret.each_with_index do |return_value, index|
17
18
  next unless return_value
18
19
 
@@ -24,7 +25,7 @@ module Contrast
24
25
  end
25
26
  square_bracket_single(target_matchdata_index, preshift, return_value, propagation_node)
26
27
  end
27
- elsif ret.is_a?(String)
28
+ when String
28
29
  target_matchdata_index = preshift.args[0]
29
30
  square_bracket_single(target_matchdata_index, preshift, ret, propagation_node)
30
31
  end
@@ -66,18 +67,15 @@ module Contrast
66
67
  def square_bracket_single argument_index, preshift, return_value, propagation_node
67
68
  original_start_index = preshift.object.begin(argument_index)
68
69
  original_end_index = preshift.object.end(argument_index)
69
- original_properties = preshift.object.cs__properties
70
+ original_properties = Contrast::Agent::Assess::Tracker.properties(preshift.object)
70
71
  applicable_tags = original_properties.tags_at_range(original_start_index...original_end_index)
71
72
  return if applicable_tags.empty?
72
73
 
74
+ return_properties = Contrast::Agent::Assess::Tracker.properties(return_value)
73
75
  applicable_tags.each do |tag_name, tag_ranges|
74
- return_value.cs__properties.set_tags(tag_name, tag_ranges)
76
+ return_properties.set_tags(tag_name, tag_ranges)
75
77
  end
76
- preshift.object.cs__properties.events.each do |event|
77
- return_value.cs__properties.add_event(event)
78
- end
79
- return_value.cs__properties.build_event(
80
- propagation_node, return_value, preshift.object, return_value, preshift.args)
78
+ return_properties.build_event(propagation_node, return_value, preshift.object, return_value, preshift.args)
81
79
  end
82
80
  end
83
81
  end
@@ -15,23 +15,25 @@ module Contrast
15
15
  # String has some silly methods like next. Basically, this flips a
16
16
  # character in a predictable manner
17
17
  def propagate propagation_node, preshift, target
18
- source = find_source(propagation_node.sources[0], preshift)
18
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
19
+ return unless properties
19
20
 
20
- target.cs__copy_from(source, 0, propagation_node.untags)
21
+ source = find_source(propagation_node.sources[0], preshift)
22
+ properties.copy_from(source, target, 0, propagation_node.untags)
21
23
 
22
24
  # this means the char that was shifted overflowed and created new
23
25
  # chars (i.e 'z' "wraps" to create 'aa' )
24
26
  unless target.length == source.length
25
- target.cs__copy_from(source, 0, propagation_node.untags)
27
+ properties.copy_from(source, target, 0, propagation_node.untags)
26
28
 
27
29
  first_difference = (0...source.length).find { |i| source[i] != target[i] } || source.length
28
30
 
29
- target.cs__properties.tags_at(first_difference).each do |tag|
31
+ properties.tags_at(first_difference).each do |tag|
30
32
  tag.shift_end(target.length - source.length)
31
33
  end
32
34
  end
33
35
 
34
- target.cs__properties.cleanup_tags
36
+ properties.cleanup_tags
35
37
  end
36
38
  end
37
39
  end
@@ -14,9 +14,14 @@ module Contrast
14
14
  # For the source, prepend its tags to the target. It's basically the
15
15
  # opposite of append. :-P
16
16
  def propagate propagation_node, preshift, target
17
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
18
+ return unless properties
19
+
17
20
  sources = propagation_node.sources
21
+ # source1 is the copy of the thing being prepended to
18
22
  source1 = find_source(sources[0], preshift)
19
23
 
24
+ # source2 is the copy of the thing being prepended
20
25
  source2 = sources[1] ? find_source(sources[1], preshift) : source1
21
26
 
22
27
  original_start_index = target.rindex(source1) || 0
@@ -24,22 +29,25 @@ module Contrast
24
29
  # tags from the object(since nothing from args was added to
25
30
  # return)
26
31
  if source1.length == target.length
27
- target.cs__copy_from(source1, 0, propagation_node.untags)
32
+ properties.copy_from(source1, target, 0, propagation_node.untags)
28
33
  else
29
34
  # find original in the target, copy tags to the new position in target
30
- target.cs__copy_from(source1, original_start_index, propagation_node.untags)
35
+ properties.copy_from(source1, target, original_start_index, propagation_node.untags)
36
+ # then we add the tags from the thing prepended to the start
37
+ # of the target
31
38
  start = 0
32
39
  while start < original_start_index
33
- target.cs__copy_from(source2, start, propagation_node.untags)
40
+ properties.copy_from(source2, target, start, propagation_node.untags)
34
41
  start += source2.length
35
42
  next unless start > original_start_index
36
43
 
37
- target.cs__properties.tags_at(start - source2.length).each do |tag|
44
+ properties.tags_at(start - source2.length).each do |tag|
38
45
  tag.update_end(original_start_index)
39
46
  end
40
47
  end
41
48
  end
42
- target.cs__properties.cleanup_tags
49
+ # and finally merge the tags if any overlap.
50
+ properties.cleanup_tags
43
51
  end
44
52
  end
45
53
  end
@@ -17,15 +17,19 @@ module Contrast
17
17
  # Once the tag is applied, remove the section that was removed by the delete.
18
18
  # Unlike additive propagation, this currently only supports one source
19
19
  def propagate propagation_node, preshift, target
20
- source = find_source(propagation_node.sources[0], preshift)
21
-
22
- target.cs__copy_from(source, 0, propagation_node.untags)
20
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
21
+ return unless properties
23
22
 
23
+ source = find_source(propagation_node.sources[0], preshift)
24
+ properties.copy_from(source, target, 0, propagation_node.untags)
24
25
  source_chars = source.is_a?(String) ? source.chars : source.string.chars
25
26
  handle_removal(source_chars, target)
26
27
  end
27
28
 
28
29
  def handle_removal source_chars, target
30
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
31
+ return unless properties
32
+
29
33
  source_idx = 0
30
34
 
31
35
  target_chars = target.chars
@@ -60,7 +64,7 @@ module Contrast
60
64
  remove_ranges << (source_idx...source_chars.length) if source_idx != source_chars.length
61
65
 
62
66
  # handle deleting the removed ranges
63
- target.cs__properties.delete_tags_at_ranges(remove_ranges)
67
+ properties.delete_tags_at_ranges(remove_ranges)
64
68
  end
65
69
  end
66
70
  end
@@ -14,9 +14,12 @@ module Contrast
14
14
  # Replace means we're replacing the target w/ the source. Anything
15
15
  # on the source should be passed to the target.
16
16
  def propagate propagation_node, preshift, target
17
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
18
+ return unless properties
19
+
17
20
  source = find_source(propagation_node.sources[0], preshift)
18
- target.cs__properties.clear_tags
19
- target.cs__copy_from(source, 0, propagation_node.untags)
21
+ properties.clear_tags
22
+ properties.copy_from(source, target, 0, propagation_node.untags)
20
23
  end
21
24
  end
22
25
  end
@@ -13,13 +13,15 @@ module Contrast
13
13
  class Reverse < Contrast::Agent::Assess::Policy::Propagator::Base
14
14
  class << self
15
15
  def propagate propagation_node, preshift, target
16
- source = find_source(propagation_node.sources[0], preshift)
16
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
17
+ return unless properties
17
18
 
18
- target.cs__copy_from(source, 0, propagation_node.untags)
19
+ source = find_source(propagation_node.sources[0], preshift)
20
+ properties.copy_from(source, target, 0, propagation_node.untags)
19
21
 
20
22
  length = target.length
21
- target.cs__properties.tag_keys.each do |key|
22
- tags = target.cs__properties.fetch_tag(key)
23
+ properties.tag_keys.each do |key|
24
+ tags = properties.fetch_tag(key)
23
25
  tags.each do |tag|
24
26
  new_end = length - tag.start_idx
25
27
  new_start = new_end - tag.length
@@ -27,7 +29,7 @@ module Contrast
27
29
  end
28
30
  end
29
31
 
30
- target.cs__properties.cleanup_tags
32
+ properties.cleanup_tags
31
33
  end
32
34
  end
33
35
  end
@@ -14,6 +14,9 @@ module Contrast
14
14
  class Select
15
15
  class << self
16
16
  def select_tagger patcher, preshift, ret, _block
17
+ properties = Contrast::Agent::Assess::Tracker.properties(ret)
18
+ return unless properties
19
+
17
20
  source = preshift.object
18
21
  args = preshift.args
19
22
 
@@ -21,12 +24,15 @@ module Contrast
21
24
  # Additionally, an empty string is returned when the starting index for
22
25
  # a character range is at the end of the string. Let's just skip that
23
26
  # and only track a string that has length
24
- return unless source.cs__tracked? && ret && !ret.empty?
27
+ unless ret &&
28
+ !ret.empty? &&
29
+ Contrast::Agent::Assess::Tracker.tracked?(source)
25
30
 
26
- source.cs__properties.events.each do |event|
27
- ret.cs__properties.events << event
31
+ return
28
32
  end
29
- ret.cs__properties.build_event(
33
+
34
+ source_properties = Contrast::Agent::Assess::Tracker.properties(source)
35
+ properties.build_event(
30
36
  patcher,
31
37
  ret,
32
38
  source,
@@ -36,10 +42,10 @@ module Contrast
36
42
  range = determine_select_range(source, args)
37
43
  return unless range
38
44
 
39
- tags = source.cs__properties.tags_at_range(range)
40
- ret.cs__properties.clear_tags
45
+ tags = source_properties.tags_at_range(range)
46
+ properties.clear_tags
41
47
  tags.each_pair do |key, value|
42
- ret.cs__properties.set_tags(key, value)
48
+ properties.set_tags(key, value)
43
49
  end
44
50
  ret
45
51
  end