contrast-agent 3.10.2 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (388) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +0 -1
  3. data/.flayignore +1 -0
  4. data/.gitignore +1 -1
  5. data/.simplecov +5 -2
  6. data/Rakefile +31 -0
  7. data/ext/build_funchook.rb +13 -19
  8. data/ext/cs__assess_active_record_named/cs__active_record_named.c +12 -14
  9. data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
  10. data/ext/cs__assess_active_record_named/extconf.rb +3 -0
  11. data/ext/cs__assess_array/cs__assess_array.c +5 -6
  12. data/ext/cs__assess_array/cs__assess_array.h +1 -0
  13. data/ext/cs__assess_array/extconf.rb +3 -0
  14. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +13 -11
  15. data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
  16. data/ext/cs__assess_basic_object/extconf.rb +3 -0
  17. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +6 -11
  18. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +3 -4
  19. data/ext/cs__assess_fiber_track/extconf.rb +3 -0
  20. data/ext/cs__assess_hash/cs__assess_hash.c +40 -17
  21. data/ext/cs__assess_hash/cs__assess_hash.h +4 -6
  22. data/ext/cs__assess_hash/extconf.rb +3 -0
  23. data/ext/cs__assess_kernel/cs__assess_kernel.c +11 -9
  24. data/ext/cs__assess_kernel/cs__assess_kernel.h +1 -0
  25. data/ext/cs__assess_kernel/extconf.rb +3 -0
  26. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +3 -6
  27. data/ext/cs__assess_marshal_module/extconf.rb +3 -0
  28. data/ext/cs__assess_module/cs__assess_module.c +16 -14
  29. data/ext/cs__assess_module/cs__assess_module.h +3 -0
  30. data/ext/cs__assess_module/extconf.rb +3 -0
  31. data/ext/cs__assess_regexp/cs__assess_regexp.c +13 -9
  32. data/ext/cs__assess_regexp/cs__assess_regexp.h +1 -0
  33. data/ext/cs__assess_regexp/extconf.rb +3 -0
  34. data/ext/cs__assess_string/cs__assess_string.c +5 -8
  35. data/ext/cs__assess_string/cs__assess_string.h +2 -1
  36. data/ext/cs__assess_string/extconf.rb +3 -0
  37. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +3 -8
  38. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +3 -3
  39. data/ext/cs__assess_string_interpolation26/extconf.rb +3 -0
  40. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -5
  41. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +1 -2
  42. data/ext/cs__assess_yield_track/extconf.rb +3 -0
  43. data/ext/cs__common/cs__common.c +104 -1
  44. data/ext/cs__common/cs__common.h +37 -0
  45. data/ext/cs__common/extconf.rb +3 -16
  46. data/ext/cs__contrast_patch/cs__contrast_patch.h +1 -6
  47. data/ext/cs__contrast_patch/extconf.rb +3 -0
  48. data/ext/cs__protect_kernel/cs__protect_kernel.c +23 -12
  49. data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
  50. data/ext/cs__protect_kernel/extconf.rb +3 -0
  51. data/ext/extconf_common.rb +3 -29
  52. data/lib/contrast.rb +4 -2
  53. data/lib/contrast/agent.rb +46 -31
  54. data/lib/contrast/agent/assess.rb +1 -11
  55. data/lib/contrast/agent/assess/contrast_event.rb +39 -224
  56. data/lib/contrast/agent/assess/events/event_factory.rb +25 -0
  57. data/lib/contrast/agent/assess/events/source_event.rb +79 -0
  58. data/lib/contrast/agent/assess/insulator.rb +0 -4
  59. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
  60. data/lib/contrast/agent/assess/policy/patcher.rb +6 -2
  61. data/lib/contrast/agent/assess/policy/policy_node.rb +5 -106
  62. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -2
  63. data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/propagation_method.rb +69 -35
  65. data/lib/contrast/agent/assess/policy/propagation_node.rb +7 -2
  66. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  67. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  68. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  69. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
  70. data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
  71. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +88 -0
  72. data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
  73. data/lib/contrast/agent/assess/policy/propagator/select.rb +35 -22
  74. data/lib/contrast/agent/assess/policy/propagator/split.rb +28 -8
  75. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +6 -4
  76. data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
  77. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +37 -26
  78. data/lib/contrast/agent/assess/policy/source_method.rb +21 -22
  79. data/lib/contrast/agent/assess/policy/source_node.rb +0 -15
  80. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
  81. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
  82. data/lib/contrast/agent/assess/policy/trigger_method.rb +29 -52
  83. data/lib/contrast/agent/assess/policy/trigger_node.rb +23 -11
  84. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -31
  85. data/lib/contrast/agent/assess/properties.rb +4 -380
  86. data/lib/contrast/agent/assess/property/evented.rb +78 -0
  87. data/lib/contrast/agent/assess/property/tagged.rb +339 -0
  88. data/lib/contrast/agent/assess/rule/base.rb +1 -20
  89. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +6 -7
  90. data/lib/contrast/agent/assess/rule/redos.rb +4 -5
  91. data/lib/contrast/agent/assess/tag.rb +51 -26
  92. data/lib/contrast/agent/at_exit_hook.rb +18 -13
  93. data/lib/contrast/agent/class_reopener.rb +23 -8
  94. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  95. data/lib/contrast/agent/disable_reaction.rb +3 -4
  96. data/lib/contrast/agent/exclusion_matcher.rb +9 -50
  97. data/lib/contrast/agent/inventory/policy/datastores.rb +53 -0
  98. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  99. data/lib/contrast/agent/middleware.rb +95 -266
  100. data/lib/contrast/agent/module_data.rb +2 -1
  101. data/lib/contrast/agent/patching/policy/after_load_patch.rb +13 -3
  102. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +59 -47
  103. data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
  104. data/lib/contrast/agent/patching/policy/module_policy.rb +0 -25
  105. data/lib/contrast/agent/patching/policy/patch.rb +97 -23
  106. data/lib/contrast/agent/patching/policy/patcher.rb +28 -30
  107. data/lib/contrast/agent/patching/policy/policy.rb +10 -10
  108. data/lib/contrast/agent/patching/policy/policy_node.rb +5 -13
  109. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -5
  110. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
  111. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
  112. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
  113. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
  114. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
  115. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
  116. data/lib/contrast/agent/protect/policy/policy.rb +6 -6
  117. data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
  118. data/lib/contrast/agent/protect/rule.rb +0 -5
  119. data/lib/contrast/agent/protect/rule/base.rb +38 -68
  120. data/lib/contrast/agent/protect/rule/base_service.rb +4 -2
  121. data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -15
  122. data/lib/contrast/agent/protect/rule/default_scanner.rb +0 -13
  123. data/lib/contrast/agent/protect/rule/deserialization.rb +2 -0
  124. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +4 -9
  125. data/lib/contrast/agent/protect/rule/no_sqli.rb +4 -4
  126. data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
  127. data/lib/contrast/agent/protect/rule/sqli.rb +5 -4
  128. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -0
  129. data/lib/contrast/agent/protect/rule/xss.rb +2 -0
  130. data/lib/contrast/agent/protect/rule/xxe.rb +11 -4
  131. data/lib/contrast/agent/railtie.rb +3 -8
  132. data/lib/contrast/agent/reaction_processor.rb +7 -7
  133. data/lib/contrast/agent/request.rb +93 -339
  134. data/lib/contrast/agent/request_context.rb +27 -30
  135. data/lib/contrast/agent/request_handler.rb +35 -0
  136. data/lib/contrast/agent/response.rb +22 -100
  137. data/lib/contrast/agent/rewriter.rb +22 -10
  138. data/lib/contrast/agent/rule_set.rb +49 -0
  139. data/lib/contrast/agent/scope.rb +1 -7
  140. data/lib/contrast/agent/service_heartbeat.rb +9 -12
  141. data/lib/contrast/agent/static_analysis.rb +41 -0
  142. data/lib/contrast/agent/thread.rb +1 -1
  143. data/lib/contrast/agent/thread_watcher.rb +49 -0
  144. data/lib/contrast/agent/tracepoint_hook.rb +1 -5
  145. data/lib/contrast/agent/version.rb +1 -1
  146. data/lib/contrast/agent/worker_thread.rb +24 -0
  147. data/lib/contrast/api.rb +4 -6
  148. data/lib/contrast/api/communication.rb +20 -0
  149. data/lib/contrast/api/communication/connection_status.rb +41 -0
  150. data/lib/contrast/api/communication/messaging_queue.rb +79 -0
  151. data/lib/contrast/api/communication/response_processor.rb +77 -0
  152. data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
  153. data/lib/contrast/api/communication/socket.rb +45 -0
  154. data/lib/contrast/api/communication/socket_client.rb +76 -0
  155. data/lib/contrast/api/communication/speedracer.rb +111 -0
  156. data/lib/contrast/api/communication/tcp_socket.rb +31 -0
  157. data/lib/contrast/api/communication/unix_socket.rb +27 -0
  158. data/lib/contrast/api/decorators.rb +24 -0
  159. data/lib/contrast/api/decorators/address.rb +60 -0
  160. data/lib/contrast/api/decorators/application_settings.rb +41 -0
  161. data/lib/contrast/api/decorators/application_update.rb +57 -0
  162. data/lib/contrast/api/decorators/http_request.rb +139 -0
  163. data/lib/contrast/api/decorators/input_analysis.rb +17 -0
  164. data/lib/contrast/api/decorators/message.rb +75 -0
  165. data/lib/contrast/api/decorators/rasp_rule_sample.rb +28 -0
  166. data/lib/contrast/api/decorators/route_coverage.rb +57 -0
  167. data/lib/contrast/api/decorators/server_features.rb +24 -0
  168. data/lib/contrast/api/decorators/trace_event.rb +99 -0
  169. data/lib/contrast/api/decorators/trace_event_object.rb +57 -0
  170. data/lib/contrast/api/decorators/trace_event_signature.rb +46 -0
  171. data/lib/contrast/api/decorators/trace_taint_range.rb +51 -0
  172. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
  173. data/lib/contrast/api/decorators/user_input.rb +40 -0
  174. data/lib/contrast/components/agent.rb +34 -24
  175. data/lib/contrast/components/app_context.rb +39 -39
  176. data/lib/contrast/components/assess.rb +25 -15
  177. data/lib/contrast/components/config.rb +11 -14
  178. data/lib/contrast/components/contrast_service.rb +23 -71
  179. data/lib/contrast/components/heap_dump.rb +12 -8
  180. data/lib/contrast/components/interface.rb +16 -23
  181. data/lib/contrast/components/inventory.rb +5 -1
  182. data/lib/contrast/components/logger.rb +3 -68
  183. data/lib/contrast/components/protect.rb +40 -4
  184. data/lib/contrast/components/sampling.rb +22 -11
  185. data/lib/contrast/components/scope.rb +2 -52
  186. data/lib/contrast/components/settings.rb +36 -23
  187. data/lib/contrast/config/base_configuration.rb +1 -0
  188. data/lib/contrast/config/default_value.rb +1 -0
  189. data/lib/contrast/config/protect_rule_configuration.rb +0 -14
  190. data/lib/contrast/config/protect_rules_configuration.rb +0 -1
  191. data/lib/contrast/configuration.rb +2 -2
  192. data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -16
  193. data/lib/contrast/extension/assess/array.rb +77 -0
  194. data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +28 -24
  195. data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -8
  196. data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
  197. data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +7 -9
  198. data/lib/contrast/extension/assess/fiber.rb +113 -0
  199. data/lib/contrast/extension/assess/hash.rb +39 -0
  200. data/lib/contrast/extension/assess/kernel.rb +110 -0
  201. data/lib/contrast/extension/assess/regexp.rb +84 -0
  202. data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +19 -11
  203. data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
  204. data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -3
  205. data/lib/contrast/extension/kernel.rb +54 -0
  206. data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
  207. data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
  208. data/lib/contrast/extension/protect/kernel.rb +44 -0
  209. data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
  210. data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
  211. data/lib/contrast/framework/base_support.rb +28 -19
  212. data/lib/contrast/framework/manager.rb +57 -15
  213. data/lib/contrast/framework/platform_version.rb +1 -0
  214. data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
  215. data/lib/contrast/framework/rack/patch/support.rb +24 -0
  216. data/lib/contrast/framework/rack/support.rb +22 -0
  217. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +41 -0
  218. data/lib/contrast/framework/rails/patch/assess_configuration.rb +102 -0
  219. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
  220. data/lib/contrast/framework/rails/patch/support.rb +67 -0
  221. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
  222. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
  223. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
  224. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
  225. data/lib/contrast/framework/rails/support.rb +86 -0
  226. data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
  227. data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
  228. data/lib/contrast/framework/sinatra/support.rb +98 -0
  229. data/lib/contrast/funchook/funchook.rb +45 -0
  230. data/lib/contrast/logger/application.rb +80 -0
  231. data/lib/contrast/logger/format.rb +51 -0
  232. data/lib/contrast/logger/log.rb +149 -0
  233. data/lib/contrast/logger/time.rb +50 -0
  234. data/lib/contrast/tasks/config.rb +54 -0
  235. data/lib/contrast/tasks/service.rb +3 -13
  236. data/lib/contrast/utils/assess/sampling_util.rb +4 -9
  237. data/lib/contrast/utils/assess/tracking_util.rb +51 -20
  238. data/lib/contrast/utils/boolean_util.rb +2 -2
  239. data/lib/contrast/utils/class_util.rb +24 -3
  240. data/lib/contrast/utils/gemfile_reader.rb +7 -5
  241. data/lib/contrast/utils/hash_digest.rb +13 -13
  242. data/lib/contrast/utils/heap_dump_util.rb +12 -11
  243. data/lib/contrast/utils/invalid_configuration_util.rb +3 -19
  244. data/lib/contrast/utils/inventory_util.rb +4 -9
  245. data/lib/contrast/utils/io_util.rb +1 -11
  246. data/lib/contrast/utils/job_servers_running.rb +6 -4
  247. data/lib/contrast/utils/object_share.rb +1 -29
  248. data/lib/contrast/utils/os.rb +16 -28
  249. data/lib/contrast/utils/stack_trace_utils.rb +85 -182
  250. data/lib/contrast/utils/string_utils.rb +18 -2
  251. data/lib/contrast/utils/tag_util.rb +12 -2
  252. data/lib/contrast/utils/thread_tracker.rb +1 -14
  253. data/lib/contrast/utils/timer.rb +1 -57
  254. data/resources/assess/policy.json +42 -71
  255. data/resources/inventory/policy.json +2 -2
  256. data/resources/protect/policy.json +15 -15
  257. data/ruby-agent.gemspec +14 -7
  258. data/service_executables/VERSION +1 -1
  259. data/service_executables/linux/contrast-service +0 -0
  260. data/service_executables/mac/contrast-service +0 -0
  261. metadata +153 -164
  262. data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +0 -63
  263. data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +0 -29
  264. data/ext/cs__assess_regexp_track/extconf.rb +0 -2
  265. data/funchook/Makefile +0 -29
  266. data/funchook/autom4te.cache/output.0 +0 -4976
  267. data/funchook/autom4te.cache/requests +0 -78
  268. data/funchook/autom4te.cache/traces.0 +0 -364
  269. data/funchook/config.log +0 -490
  270. data/funchook/config.status +0 -1016
  271. data/funchook/configure +0 -4976
  272. data/funchook/src/Makefile +0 -70
  273. data/funchook/src/config.h +0 -101
  274. data/funchook/src/config.h.in +0 -100
  275. data/funchook/src/decoder.o +0 -0
  276. data/funchook/src/distorm.o +0 -0
  277. data/funchook/src/funchook.o +0 -0
  278. data/funchook/src/funchook_io.o +0 -0
  279. data/funchook/src/funchook_syscall.o +0 -0
  280. data/funchook/src/funchook_unix.o +0 -0
  281. data/funchook/src/funchook_x86.o +0 -0
  282. data/funchook/src/instructions.o +0 -0
  283. data/funchook/src/insts.o +0 -0
  284. data/funchook/src/libfunchook.so +0 -0
  285. data/funchook/src/mnemonics.o +0 -0
  286. data/funchook/src/operands.o +0 -0
  287. data/funchook/src/os_func.o +0 -0
  288. data/funchook/src/os_func_unix.o +0 -0
  289. data/funchook/src/prefix.o +0 -0
  290. data/funchook/src/printf_base.o +0 -0
  291. data/funchook/src/textdefs.o +0 -0
  292. data/funchook/src/wstring.o +0 -0
  293. data/funchook/test/Makefile +0 -43
  294. data/funchook/test/funchook_test +0 -0
  295. data/funchook/test/libfunchook_test.so +0 -0
  296. data/funchook/test/test_main.o +0 -0
  297. data/funchook/test/x86_64_test.o +0 -0
  298. data/lib/contrast/agent/assess/adjusted_span.rb +0 -25
  299. data/lib/contrast/agent/assess/frozen_properties.rb +0 -41
  300. data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
  301. data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
  302. data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -73
  303. data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -132
  304. data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
  305. data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
  306. data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
  307. data/lib/contrast/agent/feature_state.rb +0 -376
  308. data/lib/contrast/agent/logger_manager.rb +0 -116
  309. data/lib/contrast/agent/protect/rule/csrf.rb +0 -118
  310. data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -103
  311. data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
  312. data/lib/contrast/agent/settings_state.rb +0 -152
  313. data/lib/contrast/agent/socket_client.rb +0 -128
  314. data/lib/contrast/api/connection_status.rb +0 -49
  315. data/lib/contrast/api/socket.rb +0 -43
  316. data/lib/contrast/api/speedracer.rb +0 -184
  317. data/lib/contrast/api/tcp_socket.rb +0 -31
  318. data/lib/contrast/api/unix_socket.rb +0 -25
  319. data/lib/contrast/delegators.rb +0 -9
  320. data/lib/contrast/delegators/application_update.rb +0 -32
  321. data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
  322. data/lib/contrast/extensions/framework/rack/request.rb +0 -24
  323. data/lib/contrast/extensions/framework/rack/response.rb +0 -23
  324. data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
  325. data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
  326. data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -53
  327. data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
  328. data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
  329. data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
  330. data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
  331. data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
  332. data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
  333. data/lib/contrast/extensions/ruby_core/assess/fiber.rb +0 -124
  334. data/lib/contrast/extensions/ruby_core/assess/hash.rb +0 -22
  335. data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -95
  336. data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
  337. data/lib/contrast/extensions/ruby_core/assess/regexp.rb +0 -206
  338. data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -73
  339. data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
  340. data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -52
  341. data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
  342. data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -72
  343. data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -60
  344. data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -83
  345. data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -123
  346. data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -65
  347. data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -143
  348. data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
  349. data/lib/contrast/framework/rails_support.rb +0 -88
  350. data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
  351. data/lib/contrast/framework/sinatra_support.rb +0 -94
  352. data/lib/contrast/framework/view_technologies_descriptor.rb +0 -20
  353. data/lib/contrast/internal_exception.rb +0 -8
  354. data/lib/contrast/utils/cache.rb +0 -69
  355. data/lib/contrast/utils/comment_range.rb +0 -19
  356. data/lib/contrast/utils/data_store_util.rb +0 -23
  357. data/lib/contrast/utils/environment_util.rb +0 -81
  358. data/lib/contrast/utils/performs_logging.rb +0 -152
  359. data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
  360. data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
  361. data/lib/contrast/utils/random_util.rb +0 -22
  362. data/lib/contrast/utils/service_response_util.rb +0 -110
  363. data/lib/contrast/utils/service_sender_util.rb +0 -106
  364. data/lib/contrast/utils/sinatra_helper.rb +0 -55
  365. data/resources/csrf/inject.js +0 -44
  366. data/resources/factory-bot-spec/spec_helper.rb +0 -30
  367. data/resources/rubocops/kernel/catch_cop.rb +0 -37
  368. data/resources/rubocops/kernel/require_cop.rb +0 -37
  369. data/resources/rubocops/kernel/require_relative_cop.rb +0 -33
  370. data/resources/rubocops/module/autoload_cop.rb +0 -37
  371. data/resources/rubocops/module/const_defined_cop.rb +0 -37
  372. data/resources/rubocops/module/const_get_cop.rb +0 -37
  373. data/resources/rubocops/module/const_set_cop.rb +0 -37
  374. data/resources/rubocops/module/constants_cop.rb +0 -37
  375. data/resources/rubocops/module/name_cop.rb +0 -37
  376. data/resources/rubocops/object/class_cop.rb +0 -37
  377. data/resources/rubocops/object/freeze_cop.rb +0 -37
  378. data/resources/rubocops/object/frozen_cop.rb +0 -37
  379. data/resources/rubocops/object/is_a_cop.rb +0 -37
  380. data/resources/rubocops/object/method_cop.rb +0 -37
  381. data/resources/rubocops/object/respond_to_cop.rb +0 -37
  382. data/resources/rubocops/object/singleton_class_cop.rb +0 -37
  383. data/resources/rubocops/regexp/spelling_cop.rb +0 -44
  384. data/resources/rubocops/thread/new_cop.rb +0 -39
  385. data/resources/ruby-spec/ancestors_spec.rb +0 -70
  386. data/resources/ruby-spec/modulo_spec.rb +0 -831
  387. data/resources/ruby-spec/parameters_spec.rb +0 -261
  388. data/resources/ruby-spec/ruby_spec_spec_helper.rb +0 -35
@@ -13,23 +13,59 @@ module Contrast
13
13
  include Contrast::Components::ComponentBase
14
14
  include Contrast::Components::Interface
15
15
 
16
- access_component :settings
16
+ access_component :config, :settings
17
17
 
18
18
  def enabled?
19
- state.protect_enabled?
19
+ # config overrides if forcibly set
20
+ return false if forcibly_disabled?
21
+ return true if forcibly_enabled?
22
+
23
+ SETTINGS.protect_enabled?
20
24
  end
21
25
 
22
- def forcibly_disabled?
23
- state.protect_forcibly_disabled?
26
+ def rule_config
27
+ CONFIG.root.protect.rules
24
28
  end
25
29
 
26
30
  def rules
27
31
  SETTINGS.protect_rules
28
32
  end
29
33
 
34
+ def rule_mode rule_id
35
+ CONFIG.root.protect.rules[rule_id]&.mode || SETTINGS.modes_by_id[rule_id] || :NO_ACTION
36
+ end
37
+
30
38
  def rule name
31
39
  SETTINGS.protect_rules[name]
32
40
  end
41
+
42
+ def report_any_command_execution?
43
+ if @_report_any_command_execution.nil?
44
+ ctrl = rule_config[Contrast::Agent::Protect::Rule::CmdInjection::NAME]
45
+ @_report_any_command_execution = true?(ctrl.disable_system_commands)
46
+ end
47
+ @_report_any_command_execution
48
+ end
49
+
50
+ def report_custom_code_sysfile_access?
51
+ if @_report_custom_code_sysfile_access.nil?
52
+ ctrl = rule_config[Contrast::Agent::Protect::Rule::PathTraversal::NAME]
53
+ @_report_custom_code_sysfile_access = true?(ctrl.detect_custom_code_accessing_system_files)
54
+ end
55
+ @_report_custom_code_sysfile_access
56
+ end
57
+
58
+ def forcibly_disabled?
59
+ @_forcibly_disabled = false?(CONFIG.root.protect.enable) if @_forcibly_disabled.nil?
60
+ @_forcibly_disabled
61
+ end
62
+
63
+ private
64
+
65
+ def forcibly_enabled?
66
+ @_forcibly_enabled = true?(CONFIG.root.protect.enable) if @_forcibly_enabled.nil?
67
+ @_forcibly_enabled
68
+ end
33
69
  end
34
70
 
35
71
  COMPONENT_INTERFACE = Interface.new
@@ -9,7 +9,7 @@ module Contrast
9
9
  DEFAULT_SAMPLING_BASELINE = 5
10
10
  DEFAULT_SAMPLING_REQUEST_FREQUENCY = 5
11
11
  DEFAULT_SAMPLING_RESPONSE_FREQUENCY = 25
12
- DEFAULT_SAMPLING_WINDOW_MS = 180_000 # 3 minutes, arbitrary value from Java agent
12
+ DEFAULT_SAMPLING_WINDOW_MS = 180_000
13
13
  end
14
14
 
15
15
  module ClassMethods #:nodoc:
@@ -17,18 +17,29 @@ module Contrast
17
17
  include Constants
18
18
  include Contrast::Components::Interface
19
19
 
20
- access_component :config
20
+ access_component :config, :settings
21
21
 
22
- def sampling_control settings = @sampling_features
23
- cas = CONFIG.root.assess&.sampling
22
+ def sampling_enabled?
23
+ sampling_control[:enabled]
24
+ end
25
+
26
+ def sampling_control
27
+ @_sampling_control ||= begin
28
+ cas = CONFIG.root.assess&.sampling
29
+ settings = SETTINGS&.assess_state&.[](:sampling_settings)
30
+ {
31
+ enabled: true?([cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED].reject(&:nil?)[0]),
32
+ baseline: [cas&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE].map(&:to_i).find(&:positive?),
33
+ request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY].map(&:to_i).find(&:positive?),
34
+ response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
35
+ window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS].map(&:to_i).find(&:positive?)
36
+ }
37
+ end
38
+ end
24
39
 
25
- {
26
- enabled: true?([cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED] .reject(&:nil?).first),
27
- baseline: [cas&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE] .map(&:to_i).find(&:positive?),
28
- request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY] .map(&:to_i).find(&:positive?),
29
- response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
30
- window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS] .map(&:to_i).find(&:positive?)
31
- }
40
+ # Used to reset sampling when settings from TeamServer change
41
+ def reset_sampling_control
42
+ @_sampling_control = nil
32
43
  end
33
44
  end
34
45
 
@@ -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 'monitor'
5
4
  cs__scoped_require 'fiber'
5
+ cs__scoped_require 'monitor'
6
6
  cs__scoped_require 'contrast/agent/scope'
7
7
 
8
8
  # This is the Scope component.
@@ -54,7 +54,7 @@ module Contrast
54
54
  end
55
55
  end
56
56
 
57
- # TODO: https://contrast.atlassian.net/browse/RUBY-290
57
+ # TODO: RUBY-572
58
58
  #
59
59
  # Current behavior is to no-op if we're not "in a request context".
60
60
  # Our C functions were previously checking to see if we had a scope, because
@@ -84,53 +84,3 @@ module Contrast
84
84
  end
85
85
  end
86
86
  end
87
-
88
- # This is a reasonable place for the Kernel#catch hook to live.
89
- # No current plans for component re-design, but if we had some kind of
90
- # "do this when a component is hooked in" thing, this would live there.
91
- # For now, it's over-engineering to live anywhere else. -ajm
92
- module Kernel # :nodoc:
93
- alias_method :cs__catch, :catch
94
-
95
- # In the event of a `throw`, we need to override `catch`
96
- # to save & restore scope state:
97
- #
98
- # scope_level == 0
99
- #
100
- # catch(:abc) do
101
- # with_contrast_scope do
102
- # throw :abc # will leak
103
- # end
104
- # end
105
- #
106
- # scope_level == 1
107
- #
108
- # Frankly, this isn't how scope should be used. This is in place of
109
- # proper `ensure` blocks within the instrumentation call stack.
110
- # This will actually /create/ scope leaks if you're doing something like:
111
- #
112
- # catch(:ohno) do
113
- # enter scope
114
- # end
115
- #
116
- # abc()
117
- #
118
- # exit scope
119
- #
120
- # i.e. if you intend to change net scope across a catch block boundary.
121
-
122
- private
123
-
124
- def catch *args, &block
125
- # Save current scope level
126
- scope_level = Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_get(:@contrast_scope)
127
-
128
- # Run original catch with block.
129
- retval = cs__catch(*args, &block)
130
-
131
- # Restore scope.
132
- Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_set(:@contrast_scope, scope_level)
133
-
134
- retval
135
- end
136
- end
@@ -23,11 +23,6 @@ module Contrast
23
23
  # this statefulness
24
24
  attr_reader :tainted_columns # This can probably go into assess_state?
25
25
 
26
- # a vulnerability like padding oracle is exploited across
27
- # multiple requests, as a timing attack. these attempts must be
28
- # accumulated, in order to recognize the pattern and block the attack.
29
- attr_reader :accumulator_settings
30
-
31
26
  # These three 'state' variables represent atomic config/setting state,
32
27
  # outside of things like rule defs.
33
28
 
@@ -40,8 +35,7 @@ module Contrast
40
35
 
41
36
  def protect_state
42
37
  @protect_state ||= { # rubocop:disable Naming/MemoizedInstanceVariableName
43
- enabled: false,
44
- accumulator_settings: Contrast::Api::Settings::AccumulatorSettings.new
38
+ enabled: false
45
39
  }
46
40
  end
47
41
 
@@ -58,8 +52,7 @@ module Contrast
58
52
  # So, between this block and rules, that's setting state.
59
53
  PROTECT_STATE_ATTRS = %i[].cs__freeze
60
54
  ASSESS_STATE_ATTRS = %i[sampling_features].cs__freeze
61
- APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules session_id].cs__freeze
62
- STATE_ATTRS = PROTECT_STATE_ATTRS | ASSESS_STATE_ATTRS | APPLICATION_STATE_ATTRS
55
+ APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules].cs__freeze
63
56
 
64
57
  # Meta-define an accessor for each state attribute.
65
58
  begin
@@ -86,6 +79,40 @@ module Contrast
86
79
  reset_state
87
80
  end
88
81
 
82
+ def protect_enabled?
83
+ @_protect_enabled = !!protect_state[:enabled] if @_protect_enabled.nil?
84
+ @_protect_enabled
85
+ end
86
+
87
+ def assess_enabled?
88
+ @_assess_enabled = !!assess_state[:enabled] if @_assess_enabled.nil?
89
+ @_assess_enabled
90
+ end
91
+
92
+ def code_exclusions
93
+ exclusion_matchers.select(&:code?)
94
+ end
95
+
96
+ def update_from_server_features server_features
97
+ # protect
98
+ begin
99
+ @_protect_enabled = nil
100
+ protect_state[:enabled] = server_features.protect_enabled?
101
+ end
102
+
103
+ # assess
104
+ begin
105
+ @_assess_enabled = nil
106
+ assess_state[:enabled] = server_features.assess_enabled?
107
+ assess_state[:sampling_settings] = server_features.assess.sampling
108
+ Contrast::Utils::Assess::SamplingUtil.instance.update
109
+ end
110
+ end
111
+
112
+ def update_from_application_settings application_settings
113
+ application_state.merge!(application_settings.application_state_translation)
114
+ end
115
+
89
116
  # Wipe state to zero.
90
117
  def reset_state
91
118
  @assess_rules = {}
@@ -101,7 +128,6 @@ module Contrast
101
128
  def build_assess_rules
102
129
  @assess_rules = {}
103
130
 
104
- Contrast::Agent::Assess::Rule::Csrf.new
105
131
  Contrast::Agent::Assess::Rule::Redos.new
106
132
  end
107
133
 
@@ -118,19 +144,6 @@ module Contrast
118
144
  Contrast::Agent::Protect::Rule::UnsafeFileUpload.new
119
145
  Contrast::Agent::Protect::Rule::Xss.new
120
146
  Contrast::Agent::Protect::Rule::Xxe.new
121
-
122
- # Beta Rules
123
- Contrast::Agent::Protect::Rule::Csrf.new
124
- end
125
-
126
- def protect_rule name
127
- @protect_rules[name]
128
- end
129
-
130
- # these are less 'settings' and more 'how do I behave.'
131
- # relocate to Agent or Assess/Protect.
132
- def protect_rule_mode rule_id
133
- CONFIG.root.protect.rules[rule_id]&.mode || modes_by_id[rule_id] || :NO_ACTION
134
147
  end
135
148
  end
136
149
 
@@ -15,6 +15,7 @@ module Contrast
15
15
  BOOLEANS = [true, false].cs__freeze
16
16
 
17
17
  attr_reader :map
18
+
18
19
  alias_method :to_hash, :map
19
20
  def_delegators :@map, :empty?, :key?,
20
21
  :delete,
@@ -8,6 +8,7 @@ module Contrast
8
8
  # explicitly to false.
9
9
  class DefaultValue
10
10
  attr_reader :value
11
+
11
12
  def initialize value
12
13
  @value = value
13
14
  end
@@ -8,12 +8,6 @@ module Contrast
8
8
  # Common Configuration settings. Those in this section pertain to the
9
9
  # rule mode of a single protect rule in the Agent.
10
10
  class ProtectRuleConfiguration < BaseConfiguration
11
- # rubocop:disable Style/SymbolArray, Layout/SpaceBeforeComma, Layout/SpaceInsideArrayLiteralBrackets:
12
- BLOCKING_RULES = ::Set.new([:BLOCK , :BLOCK_AT_PERIMETER ]).cs__freeze
13
- PREFILTER_RULES = ::Set.new([ :BLOCK_AT_PERIMETER ]).cs__freeze
14
- POSTFILTER_RULES = ::Set.new([:BLOCK , :PERMIT, :MONITOR]).cs__freeze
15
- # rubocop:enable Style/SymbolArray, Layout/SpaceBeforeComma, Layout/SpaceInsideArrayLiteralBrackets:
16
-
17
11
  KEYS = {
18
12
  enable: EMPTY_VALUE,
19
13
  mode: EMPTY_VALUE,
@@ -24,14 +18,6 @@ module Contrast
24
18
  def initialize hsh
25
19
  super(hsh, KEYS)
26
20
  end
27
-
28
- def off?
29
- mode == 'off'
30
- end
31
-
32
- def on?
33
- !off?
34
- end
35
21
  end
36
22
  end
37
23
  end
@@ -14,7 +14,6 @@ module Contrast
14
14
  'nosql-injection' => Contrast::Config::ProtectRuleConfiguration,
15
15
  'untrusted-deserialization' => Contrast::Config::ProtectRuleConfiguration,
16
16
  'method-tampering' => Contrast::Config::ProtectRuleConfiguration,
17
- csrf: Contrast::Config::ProtectRuleConfiguration,
18
17
  xxe: Contrast::Config::ProtectRuleConfiguration,
19
18
  'path-traversal' => Contrast::Config::ProtectRuleConfiguration,
20
19
  'reflected-xss' => Contrast::Config::ProtectRuleConfiguration,
@@ -88,13 +88,13 @@ module Contrast
88
88
  puts "!!! Contrast - Configuration file at #{ path } is not readable by current user"
89
89
  next
90
90
  end
91
- config = yaml_to_hash(path)
91
+ config = yaml_to_hash(path) || {}
92
92
  break
93
93
  end
94
94
 
95
95
  if config.empty?
96
96
  puts "!!! Contrast - working directory: #{ Dir.pwd }"
97
- puts '!!! Contrast - configuration file could not be found at any of the search paths'
97
+ puts '!!! Contrast - valid configuration file could not be found at any of the search paths'
98
98
  puts 'Valid configuration paths are: '
99
99
  configuration_paths.each do |path|
100
100
  puts(path)
@@ -2,14 +2,15 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
5
- module CoreExtensions
6
- # Our top level Protect namespace in the Core Extensions section of our
5
+ module Extension
6
+ # Our top level Assess namespace in the Core Extension section of our
7
7
  # code. These patches are those that are invoked directly from a patched
8
8
  # Class.
9
9
  #
10
10
  # @deprecated This is one of our earliest designs and is not nearly as
11
11
  # relevant given the move to C based patching and the lessons learned
12
12
  # therein.
13
+ # Removing it requires a C refactor to handle the namespace.
13
14
  module Assess
14
15
  cs__scoped_require 'contrast/agent/patching/policy/patcher'
15
16
 
@@ -19,7 +20,6 @@ module Contrast
19
20
  cs__scoped_require 'contrast/agent/assess/rule/provider'
20
21
 
21
22
  # tagging / dataflow
22
- cs__scoped_require 'contrast/agent/assess/adjusted_span'
23
23
  cs__scoped_require 'contrast/agent/assess/policy/policy_node'
24
24
  cs__scoped_require 'contrast/agent/assess/policy/source_node'
25
25
  cs__scoped_require 'contrast/agent/assess/policy/source_method'
@@ -31,22 +31,18 @@ module Contrast
31
31
  cs__scoped_require 'contrast/agent/assess/policy/patcher'
32
32
 
33
33
  # classes that don't play nice w/ our standard propagation
34
- cs__scoped_require 'contrast/agent/assess/frozen_properties'
35
- cs__scoped_require 'contrast/extensions/ruby_core/assess/assess_extension'
34
+ cs__scoped_require 'contrast/extension/assess/assess_extension'
36
35
  # this needs to come first b/c array and others work on strings and
37
36
  # expect them to be trackable
38
- cs__scoped_require 'contrast/extensions/ruby_core/assess/string'
37
+ cs__scoped_require 'contrast/extension/assess/string'
39
38
 
40
- cs__scoped_require 'contrast/extensions/ruby_core/assess/array'
41
- cs__scoped_require 'contrast/extensions/ruby_core/assess/erb'
42
- cs__scoped_require 'contrast/extensions/ruby_core/assess/fiber'
43
- cs__scoped_require 'contrast/extensions/ruby_core/assess/hash'
44
- cs__scoped_require 'contrast/extensions/ruby_core/assess/kernel'
45
- cs__scoped_require 'contrast/extensions/ruby_core/assess/regexp'
46
- cs__scoped_require 'contrast/extensions/ruby_core/assess/module'
47
- cs__scoped_require 'contrast/extensions/ruby_core/assess/basic_object'
48
- cs__scoped_require 'contrast/extensions/ruby_core/assess/tilt_template_trigger'
49
- cs__scoped_require 'contrast/extensions/ruby_core/assess/xpath_library_trigger'
39
+ cs__scoped_require 'contrast/extension/assess/array'
40
+ cs__scoped_require 'contrast/extension/assess/erb'
41
+ cs__scoped_require 'contrast/extension/assess/eval_trigger'
42
+ cs__scoped_require 'contrast/extension/assess/fiber'
43
+ cs__scoped_require 'contrast/extension/assess/hash'
44
+ cs__scoped_require 'contrast/extension/assess/kernel'
45
+ cs__scoped_require 'contrast/extension/assess/regexp'
50
46
  end
51
47
  end
52
48
  end
@@ -0,0 +1,77 @@
1
+ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ cs__scoped_require 'contrast/agent/patching/policy/patch'
5
+ cs__scoped_require 'contrast/agent/patching/policy/patcher'
6
+ cs__scoped_require 'contrast/components/interface'
7
+
8
+ module Contrast
9
+ module Extension
10
+ module Assess
11
+ # This is our patch of the Array class required to handle propagation
12
+ # Disclaimer: there may be a better way, but we're in a 'get it work' state.
13
+ # Hopefully, we'll be in a 'get it right' state soon.
14
+ class ArrayPropagator
15
+ include Contrast::Components::Interface
16
+
17
+ access_component :scope
18
+
19
+ ARRAY_JOIN_HASH = {
20
+ 'class_name' => 'Array',
21
+ 'instance_method' => true,
22
+ 'method_visibility' => 'public',
23
+ 'method_name' => 'join',
24
+ 'action' => 'CUSTOM',
25
+ 'source' => 'O',
26
+ 'target' => 'R',
27
+ 'patch_class' => 'NOOP',
28
+ 'patch_method' => 'cs__track_join'
29
+ }.cs__freeze
30
+ ARRAY_JOIN_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(ARRAY_JOIN_HASH)
31
+
32
+ class << self
33
+ # When you call join, they use an internal thing, so there's no good way to get at the thing being returned.
34
+ # Multiple Strings are appended with the #join method. Because that
35
+ # operation happens in C, we have to do it here rather than rely on the
36
+ # patch of our String append or concat methods.
37
+ def cs__track_join ary, separator, ret
38
+ return unless ary
39
+ return ret if Contrast::Agent::Patching::Policy::Patch.skip_assess_analysis?
40
+
41
+ with_contrast_scope do
42
+ shift = 0
43
+ separator_length = separator.nil? ? 0 : separator.to_s.length
44
+ ary.each do |obj|
45
+ if obj # skip nil here
46
+ ret.cs__copy_from(obj, shift)
47
+ shift += obj.to_s.length
48
+ end
49
+ shift += separator_length
50
+ end
51
+ return ret unless ret.cs__tracked?
52
+
53
+ ret.cs__properties.cleanup_tags
54
+ ret.cs__properties.build_event(
55
+ ARRAY_JOIN_NODE,
56
+ ret,
57
+ ary,
58
+ ret,
59
+ [separator])
60
+ ret
61
+ end
62
+ end
63
+
64
+ def instrument_array_track
65
+ @_instrument_array_track ||= begin
66
+ cs__scoped_require 'cs__assess_array/cs__assess_array'
67
+ true
68
+ end
69
+ rescue StandardError, LoadError => e
70
+ logger.error('Error loading assess track patch', e)
71
+ false
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end