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
@@ -6,7 +6,8 @@ module Contrast
6
6
  # A simple wrapper around a Module and a call to its name, used to avoid
7
7
  # calling the Module#name method and generating extra Strings
8
8
  class ModuleData
9
- attr_accessor :mod, :name
9
+ attr_reader :mod, :name
10
+
10
11
  def initialize mod, name = nil
11
12
  @mod = mod
12
13
  @name = name || mod.cs__name
@@ -1,6 +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/components/interface'
5
+ cs__scoped_require 'contrast/extension/module'
4
6
  cs__scoped_require 'contrast/utils/class_util'
5
7
 
6
8
  module Contrast
@@ -9,16 +11,20 @@ module Contrast
9
11
  module Policy
10
12
  # Used to handle tracking patches that need to apply special instrumentation when a module is loaded
11
13
  class AfterLoadPatch
12
- attr_reader :applied, :module_name, :instrumentation_file_path, :method_to_instrument
13
- def initialize module_name, instrumentation_file_path, method_to_instrument: nil
14
+ include Contrast::Components::Interface
15
+ access_component :scope
16
+ attr_reader :applied, :module_name, :instrumentation_file_path, :method_to_instrument, :instrumenting_module
17
+
18
+ def initialize module_name, instrumentation_file_path, method_to_instrument: nil, instrumenting_module:
14
19
  @applied = false
15
20
  @module_name = module_name
16
21
  @method_to_instrument = method_to_instrument
17
22
  @instrumentation_file_path = instrumentation_file_path
23
+ @instrumenting_module = instrumenting_module
18
24
  end
19
25
 
20
26
  def applied?
21
- @applied
27
+ applied
22
28
  end
23
29
 
24
30
  # Modules can be re-opened, so the first load may not
@@ -54,6 +60,10 @@ module Contrast
54
60
 
55
61
  def instrument!
56
62
  cs__scoped_require instrumentation_file_path
63
+ if instrumenting_module
64
+ mod = Module.cs__const_get(instrumenting_module)
65
+ with_contrast_scope { mod.instrument } if mod
66
+ end
57
67
  @applied = true
58
68
  end
59
69
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  cs__scoped_require 'contrast/components/interface'
5
5
  cs__scoped_require 'contrast/agent/patching/policy/after_load_patch'
6
+ cs__scoped_require 'contrast/framework/manager'
6
7
 
7
8
  module Contrast
8
9
  module Agent
@@ -12,69 +13,80 @@ module Contrast
12
13
  # after they've been loaded
13
14
  module AfterLoadPatcher
14
15
  include Contrast::Components::Interface
15
- access_component :logging, :agent
16
-
17
- AFTER_LOAD_PATCHES = Set.new([
18
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
19
- 'ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods',
20
- 'contrast/extensions/framework/rails/active_record_time_zone_inherited',
21
- method_to_instrument: :inherited),
22
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
23
- 'ActionController::Railties::Helper::ClassMethods',
24
- 'contrast/extensions/framework/rails/action_controller_railties_helper_inherited',
25
- method_to_instrument: :inherited),
26
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
27
- 'ActiveRecord::Scoping::Named::ClassMethods',
28
- 'contrast/extensions/framework/rails/active_record_named'),
29
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
30
- 'ActiveRecord::AttributeMethods::Read::ClassMethods',
31
- 'contrast/extensions/framework/rails/active_record'),
32
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
33
- 'Sinatra::Base',
34
- 'contrast/extensions/framework/sinatra/base'),
35
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
36
- 'Rails::Application::Configuration',
37
- 'contrast/extensions/framework/rails/configuration',
38
- method_to_instrument: :session_store),
39
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
40
- 'Rack::Request',
41
- 'contrast/extensions/framework/rack/request'),
42
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
43
- 'Rack::Response',
44
- 'contrast/extensions/framework/rack/response'),
45
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
46
- 'ActionController::Live::Buffer',
47
- 'contrast/extensions/framework/rails/buffer'),
48
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
49
- 'Rack::Session::Cookie',
50
- 'contrast/extensions/framework/rack/cookie')
51
- ])
16
+ access_component :agent, :logging
52
17
 
53
18
  # After initialization run a catchup check to instrument any already loaded modules we care about
54
19
  def catchup_after_load_patches
55
- applied = []
56
- AFTER_LOAD_PATCHES.each do |after_load_patch|
20
+ apply_require_patches!
21
+ apply_direct_patches!
22
+ apply_load_patches!
23
+ end
24
+
25
+ private
26
+
27
+ # These patches need to be applied directly, not from our policy, so
28
+ # do so and do so only once. This should be the new standard so that
29
+ # there are no require time side effects of loading our core
30
+ # extensions.
31
+ def apply_direct_patches!
32
+ @_apply_direct_patches ||= begin
33
+ Contrast::Extension::Assess::ArrayPropagator.instrument_array_track
34
+ Contrast::Extension::Assess::EvalTrigger.instrument_basic_object_track
35
+ Contrast::Extension::Assess::EvalTrigger.instrument_module_track
36
+ Contrast::Extension::Assess::FiberPropagator.instrument_fiber_track
37
+ Contrast::Extension::Assess::HashPropagator.instrument_hash_track
38
+ Contrast::Extension::Assess::KernelPropagator.instrument_kernel_track
39
+ Contrast::Extension::Assess::RegexpPropagator.instrument_regexp_track
40
+ Contrast::Extension::Assess::StringPropagator.instrument_string
41
+ Contrast::Extension::Assess::StringPropagator.instrument_string_interpolation
42
+
43
+ Contrast::Extension::Protect::Kernel.instrument
44
+ true
45
+ end
46
+ end
47
+
48
+ def apply_load_patches!
49
+ after_load_patches.each do |after_load_patch|
57
50
  next unless after_load_patch.target_defined?
58
51
  next if AGENT.skip_instrumentation?(after_load_patch.module_name)
59
52
 
60
- logger.debug("Detected loading of #{ after_load_patch.module_name } - applying instrumentation")
53
+ logger.trace(
54
+ 'Catching up on already loaded afterload patch - applying instrumentation',
55
+ module: after_load_patch.module_name)
61
56
  after_load_patch.instrument!
62
- applied << after_load_patch
63
57
  end
64
- AFTER_LOAD_PATCHES.subtract(applied)
58
+ after_load_patches.delete_if(&:applied?)
59
+ end
60
+
61
+ # These patches need to be applied directly, not from our policy, and
62
+ # are applied as a result of requiring the file as they alias methods
63
+ # directly, allowing us to control things like scope and exception
64
+ # handling
65
+ def apply_require_patches!
66
+ @_apply_require_patches ||= begin
67
+ cs__scoped_require 'contrast/extension/thread'
68
+ cs__scoped_require 'contrast/extension/kernel'
69
+ true
70
+ rescue LoadError, StandardError => e
71
+ logger.error('failed instrumenting apply_require_patches!', e)
72
+ false
73
+ end
74
+ end
75
+
76
+ def after_load_patches
77
+ @_after_load_patches ||= Contrast::Agent.framework_manager.find_after_load_patches
65
78
  end
66
79
 
67
80
  # Use for any checks after we've initialized
68
81
  def load_patches_for_module module_name
69
- return if AFTER_LOAD_PATCHES.empty?
82
+ return if after_load_patches.empty?
70
83
 
71
- patch = AFTER_LOAD_PATCHES.find { |after_load_patch| after_load_patch.applies?(module_name) }
84
+ patch = after_load_patches.find { |after_load_patch| after_load_patch.applies?(module_name) }
72
85
  return unless patch
73
86
 
74
- logger.debug("Detected loading of #{ module_name } - applying instrumentation")
75
-
87
+ logger.trace('Detected loading of afterload patch - applying instrumentation', module: module_name)
76
88
  patch.instrument!
77
- AFTER_LOAD_PATCHES.subtract([patch]) if patch.applied?
89
+ after_load_patches.delete_if(&:applied?)
78
90
  end
79
91
  end
80
92
  end
@@ -7,9 +7,9 @@ module Contrast
7
7
  module Policy
8
8
  # This class is used to map each method to the trigger node that applies to it
9
9
  class MethodPolicy
10
- attr_accessor :source_node, :propagation_node, :trigger_node,
11
- :inventory_node, :protect_node, :deadzone_node,
12
- :method_name, :method_visibility, :instance_method
10
+ attr_reader :deadzone_node, :inventory_node, :propagation_node, :protect_node, :trigger_node
11
+ attr_accessor :source_node, :method_name, :method_visibility, :instance_method
12
+
13
13
  def initialize(source_node: nil, propagation_node: nil,
14
14
  trigger_node: nil, inventory_node: nil,
15
15
  protect_node: nil, deadzone_node: nil,
@@ -73,31 +73,6 @@ module Contrast
73
73
  end
74
74
  end
75
75
 
76
- def collect_class_nodes nodes, clazz_name
77
- return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless nodes
78
-
79
- nodes.select { |policy_node| clazz_name == policy_node.class_name }
80
- end
81
-
82
- def collect_method_nodes nodes, method, instance_method
83
- return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless nodes
84
-
85
- nodes.select do |node|
86
- node.instance_method? == instance_method && node.method_name == method
87
- end
88
- end
89
-
90
- def create_method_policy_subset method, instance_method
91
- method_policy = ModulePolicy.new
92
- method_policy.source_nodes = collect_method_nodes(source_nodes, method, instance_method)
93
- method_policy.propagator_nodes = collect_method_nodes(propagator_nodes, method, instance_method)
94
- method_policy.trigger_nodes = collect_method_nodes(trigger_nodes, method, instance_method)
95
- method_policy.inventory_nodes = collect_method_nodes(inventory_nodes, method, instance_method)
96
- method_policy.protect_nodes = collect_method_nodes(protect_nodes, method, instance_method)
97
- method_policy.deadzone_nodes = collect_method_nodes(deadzone_nodes, method, instance_method)
98
- method_policy
99
- end
100
-
101
76
  private
102
77
 
103
78
  def sort_method_names nodes, instance_methods, singleton_methods
@@ -2,28 +2,25 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  cs__scoped_require 'monitor'
5
- # base
6
- cs__scoped_require 'contrast/extensions/ruby_core/module'
5
+ cs__scoped_require 'contrast/components/interface'
6
+
7
+ cs__scoped_require 'contrast/agent'
8
+ cs__scoped_require 'contrast/logger/log'
7
9
  cs__scoped_require 'contrast/agent/patching/policy/method_policy'
8
10
  cs__scoped_require 'contrast/agent/patching/policy/patch_status'
9
11
  cs__scoped_require 'contrast/agent/patching/policy/trigger_node'
10
- cs__scoped_require 'contrast/components/interface'
11
12
 
12
13
  # assess
13
14
  cs__scoped_require 'contrast/agent/assess/policy/policy'
14
15
  cs__scoped_require 'contrast/agent/assess/policy/propagation_method'
15
16
  cs__scoped_require 'contrast/agent/assess/policy/source_method'
16
17
  cs__scoped_require 'contrast/agent/assess/policy/trigger_method'
17
- cs__scoped_require 'contrast/extensions/ruby_core/assess'
18
-
19
- # inventory
20
- cs__scoped_require 'contrast/agent/inventory/policy/policy'
21
- cs__scoped_require 'contrast/extensions/ruby_core/inventory'
22
18
 
23
19
  # protect
24
20
  cs__scoped_require 'contrast/agent/protect/policy/policy'
25
- cs__scoped_require 'contrast/extensions/ruby_core/protect'
26
- cs__scoped_require 'contrast/extensions/ruby_core/protect/kernel'
21
+
22
+ # inventory
23
+ cs__scoped_require 'contrast/agent/inventory/policy/policy'
27
24
 
28
25
  module Contrast
29
26
  module Agent
@@ -40,7 +37,7 @@ module Contrast
40
37
  include Contrast::Agent::Assess::Policy::TriggerMethod
41
38
 
42
39
  include Contrast::Components::Interface
43
- access_component :logging, :analysis, :agent, :scope
40
+ access_component :agent, :analysis, :logging, :scope
44
41
 
45
42
  POLICIES = [
46
43
  Contrast::Agent::Assess::Policy::Policy,
@@ -86,7 +83,7 @@ module Contrast
86
83
  rescue StandardError => e
87
84
  # Anything else was our bad and we gotta catch that to allow for
88
85
  # normal application flow
89
- logger.error(e, 'Unable to apply pre patch to method.')
86
+ logger.error('Unable to apply pre patch to method.', e)
90
87
  rescue Exception => e # rubocop:disable Lint/RescueException
91
88
  # This is something like NoMemoryError that we can't
92
89
  # hope to handle. Nonetheless, shouldn't leak scope.
@@ -115,7 +112,7 @@ module Contrast
115
112
  def apply_post_patch method_policy, preshift, object, ret, args, block
116
113
  apply_assess(method_policy, preshift, object, ret, args, block)
117
114
  rescue StandardError => e
118
- logger.error(e, 'Unable to apply post patch to method.')
115
+ logger.error('Unable to apply post patch to method.', e)
119
116
  end
120
117
 
121
118
  # Apply the Protect patch which applies to the given method.
@@ -130,6 +127,7 @@ module Contrast
130
127
  # @param args [Array<Object>] The arguments passed to the method
131
128
  # being invoked.
132
129
  def apply_protect method_policy, method, exception, object, args
130
+ return unless AGENT.enabled?
133
131
  return unless PROTECT.enabled?
134
132
 
135
133
  apply_trigger_only(method_policy&.protect_node,
@@ -184,14 +182,12 @@ module Contrast
184
182
 
185
183
  trigger_node = method_policy.trigger_node
186
184
  Contrast::Agent::Assess::Policy::TriggerMethod.apply_trigger_rule(trigger_node, object, ret, args) if trigger_node
187
-
188
185
  if method_policy.source_node
189
186
  # If we were given a frozen return, and it was the target of a
190
187
  # source, and we have frozen sources enabled, we'll need to
191
188
  # replace the return. Note, this is not the default case.
192
189
  source_ret = Contrast::Agent::Assess::Policy::SourceMethod.source_patchers(method_policy, object, ret, args)
193
190
  end
194
-
195
191
  if method_policy.propagation_node
196
192
  propagated_ret = Contrast::Agent::Assess::Policy::PropagationMethod.apply_propagation(
197
193
  method_policy,
@@ -201,13 +197,12 @@ module Contrast
201
197
  args,
202
198
  block)
203
199
  end
204
-
205
200
  handle_return(propagated_ret, source_ret, ret)
206
201
  rescue StandardError => e
207
- logger.error(e, 'Unable to assess method call.')
202
+ logger.error('Unable to assess method call.', e)
208
203
  handle_return(propagated_ret, source_ret, ret)
209
204
  rescue Exception => e # rubocop:disable Lint/RescueException
210
- logger.error(e, 'Unable to assess method call.')
205
+ logger.error('Unable to assess method call.', e)
211
206
  handle_return(propagated_ret, source_ret, ret)
212
207
  raise e
213
208
  end
@@ -237,7 +232,6 @@ module Contrast
237
232
  # resembling CUSTOM - they all have a common interface but their
238
233
  # own logic based on what's in the method(s) they've been patched
239
234
  # into.
240
- applicator = trigger_node.applicator
241
235
  # Each patch also knows the method of its applicator. Some
242
236
  # things, like AppliesXxeRule, have different methods depending
243
237
  # on the library patched. This lets us handle the boilerplate of
@@ -247,7 +241,7 @@ module Contrast
247
241
  # By calling send like this, we can reuse all the patching.
248
242
  # We `send` to the given method of the given class
249
243
  # (applicator) since they all accept the same inputs
250
- applicator.send(applicator_method, method, exception, trigger_node.properties, object, args)
244
+ trigger_node.applicator.send(applicator_method, method, exception, trigger_node.properties, object, args)
251
245
  end
252
246
 
253
247
  # Method to choose which replaced return from the post_patch to
@@ -279,6 +273,15 @@ module Contrast
279
273
  patched_method.to_s).to_sym
280
274
  end
281
275
 
276
+ # Given a method, return a symbol in the format
277
+ # <method_start>_unbound_<method_name>
278
+ def build_unbound_method_name patcher_method
279
+ (Contrast::Utils::ObjectShare::CONTRAST_PATCHED_METHOD_START +
280
+ 'unbound' +
281
+ Contrast::Utils::ObjectShare::UNDERSCORE +
282
+ patcher_method.to_s).to_sym
283
+ end
284
+
282
285
  # @param mod [Module] the module in which the patch should be
283
286
  # placed.
284
287
  # @param methods [Array(Symbol)] all the instance or singleton
@@ -297,10 +300,11 @@ module Contrast
297
300
  rescue NameError => e
298
301
  # This shouldn't happen anymore, but just in case calling alias
299
302
  # results in a NameError, we'll be safe here.
300
- logger.debug(
303
+ logger.error(
304
+ 'Attempted to alias a method on a Module that doesn\'t respond to it.',
301
305
  e,
302
- "The class #{ mod.cs__name } does not respond to the "\
303
- "method#{ method_policy.method_name }.")
306
+ module: mod.cs__name,
307
+ method: method_policy.method_name)
304
308
  return false
305
309
  end
306
310
  true
@@ -316,9 +320,79 @@ module Contrast
316
320
  contrast_prepend_method(mod, method_policy)
317
321
  end
318
322
 
323
+ # @param unbound_method [UnboundMethod] An unbound method, that doesn't reference its binding.
324
+ # This method executes C hooking code.
325
+ def register_c_hook unbound_method
326
+ # current binding is as meaningless as any other. but we need something
327
+ unbound_method.bind_call(self)
328
+ end
329
+
330
+ # @param target_module_name [String] Fully-qualified module name, as string, to which the C patch applies.
331
+ # @param unbound_method [UnboundMethod] An unbound method, to be patched into target_module.
332
+ # @param impl [Symbol] Strategy for applying the patch: { :alias_instance, :alias_singleton, or :prepend }:
333
+ # :alias_instance -> alias instance method of module
334
+ # :alias_singleton -> alias instance method of singleton class of module
335
+ # (equivalent to :alias, where `module = module.singleton class`)
336
+ # (this is a.k.a. "class-method patch")
337
+ # :prepend -> prepend instance method of module
338
+ # [prepending singleton is easily supported too, just not implemented yet.]
339
+ # @return [Symbol] new alias for the underlying method (presumably, so the patched method can call it)
340
+ def register_c_patch target_module_name, unbound_method, impl = :alias_instance
341
+ # These could be set as AfterLoadPatches.
342
+ method_name = unbound_method.name.to_sym
343
+ underlying_method_name = build_unbound_method_name(method_name).to_sym
344
+
345
+ target_module = Module.cs__const_get(target_module_name)
346
+
347
+ target_module = target_module.cs__singleton_class if %i[alias_singleton prepend].include? impl
348
+
349
+ visibility = if target_module.private_instance_methods(false).include?(method_name)
350
+ :private
351
+ elsif target_module.protected_instance_methods(false).include?(method_name)
352
+ :protected
353
+ elsif target_module.public_instance_methods(false).include?(method_name)
354
+ :public
355
+ else
356
+ raise NoMethodError,
357
+ <<~ERR
358
+ Tried to register a C-defined #{ impl } patch for \
359
+ #{ target_module_name }##{ method_name }, but can't find :#{ method_name }.
360
+ ERR
361
+ end
362
+
363
+ case impl
364
+ when :alias_instance, :alias_singleton
365
+ unless target_module.instance_methods(false).include? underlying_method_name
366
+ # alias_method may be private
367
+ target_module.send(:alias_method, underlying_method_name, method_name)
368
+ target_module.send(:define_method, method_name, unbound_method.bind(target_module))
369
+ end
370
+ target_module.send(visibility, method_name) # e.g., module.private(:my_method)
371
+ when :prepend
372
+ prepending_module = Module.new
373
+ prepending_module.send(:define_method, method_name, unbound_method.bind(target_module))
374
+ prepending_module.send(visibility, :method_name)
375
+ # This prepends to the singleton class (it patches a class method)
376
+ target_module.prepend prepending_module
377
+ end
378
+ # Ougai::Logger.create_item_with_2args calls Hash#[]=, so we
379
+ # can't invoke this logging method or we'll seg fault as we'd
380
+ # change the method definition mid-call
381
+ # if method_name != :[]=
382
+ # logger.trace(
383
+ # 'Registered C-defined patch',
384
+ # implementation: impl,
385
+ # module: target_module_name,
386
+ # method: method_name,
387
+ # visibility: visibility)
388
+ # end
389
+ underlying_method_name.to_sym
390
+ end
391
+
319
392
  # @return [Boolean]
320
393
  def skip_contrast_analysis?
321
394
  return true if in_contrast_scope?
395
+ return true unless defined?(Contrast::Agent::REQUEST_TRACKER)
322
396
  return true unless Contrast::Agent::REQUEST_TRACKER.current&.analyze_request?
323
397
 
324
398
  false