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
@@ -0,0 +1,57 @@
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/utils/string_utils'
5
+ cs__scoped_require 'contrast/utils/assess/tracking_util'
6
+ cs__scoped_require 'base64'
7
+ cs__scoped_require 'contrast/components/interface'
8
+
9
+ module Contrast
10
+ module Api
11
+ module Decorators
12
+ # Used to decorate the TraceEventObject protobuf model
13
+ module TraceEventObject
14
+ def self.included klass
15
+ klass.extend(ClassMethods)
16
+ end
17
+
18
+ # Class methods for TraceEventObject
19
+ module ClassMethods
20
+ include Contrast::Components::Interface
21
+ access_component :scope
22
+ # Build the event object. We were originally going to include taint on
23
+ # each one, but TS doesn't accept / use that, so it is a waste of time.
24
+ #
25
+ # We'll truncate any object that isn't important to the taint ranges of
26
+ # this event, so that we don't murder TeamServer by, for instance,
27
+ # hypothetically sending the entire rendered HTML page >_> <_< >_>
28
+ ELLIPSIS = '...'
29
+ UNTRUNCATED_PORTION_LENGTH = 25
30
+ TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + ELLIPSIS.length
31
+ def build object, truncate
32
+ event_object = new
33
+ with_contrast_scope do
34
+ obj_string = Contrast::Utils::StringUtils.force_utf8(object)
35
+ obj_string = truncate(obj_string) if truncate && obj_string.length > TRUNCATION_LENGTH
36
+ event_object.value = Base64.encode64(obj_string)
37
+ event_object.tracked = Contrast::Utils::Assess::TrackingUtil.tracked?(object)
38
+ end
39
+ event_object
40
+ end
41
+
42
+ def truncate obj_string
43
+ tmp = []
44
+ tmp << obj_string[0, UNTRUNCATED_PORTION_LENGTH]
45
+ tmp << ELLIPSIS
46
+ tmp << obj_string[
47
+ obj_string.length - UNTRUNCATED_PORTION_LENGTH,
48
+ UNTRUNCATED_PORTION_LENGTH]
49
+ tmp.join
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ Contrast::Api::Dtm::TraceEventObject.include(Contrast::Api::Decorators::TraceEventObject)
@@ -0,0 +1,46 @@
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/utils/string_utils'
5
+ cs__scoped_require 'contrast/utils/assess/tracking_util'
6
+ cs__scoped_require 'base64'
7
+
8
+ module Contrast
9
+ module Api
10
+ module Decorators
11
+ # Used to decorate the TraceEventSignature protobuf model
12
+ module TraceEventSignature
13
+ def self.included klass
14
+ klass.extend(ClassMethods)
15
+ end
16
+
17
+ # Class methods for TraceEventSignature
18
+ module ClassMethods
19
+ def build ret_obj, policy_node, args
20
+ signature = new
21
+ return_type = ret_obj ? ret_obj.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
22
+ signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
23
+ signature.class_name = Contrast::Utils::StringUtils.force_utf8(policy_node.class_name)
24
+ signature.method_name = Contrast::Utils::StringUtils.force_utf8(policy_node.method_name)
25
+ if args
26
+ args&.each do |arg|
27
+ arg_type = arg ? arg.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
28
+ signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
29
+ end
30
+ end
31
+ signature.constructor = policy_node.method_name == :new
32
+ # if there's a ret, then this method isn't nil. not 100% full proof since you can
33
+ # return nil, but this is the best we've got currently.
34
+ signature.void_method = ret_obj.nil?
35
+ # 8 is STATIC in Java... we have to placate them for now
36
+ # it has been requested that flags be removed since it isn't used
37
+ signature.flags = 8 unless policy_node.instance_method?
38
+ signature
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ Contrast::Api::Dtm::TraceEventSignature.include(Contrast::Api::Decorators::TraceEventSignature)
@@ -0,0 +1,51 @@
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/utils/object_share'
5
+ cs__scoped_require 'contrast/utils/string_utils'
6
+
7
+ module Contrast
8
+ module Api
9
+ module Decorators
10
+ # Used to decorate the TraceTaintRange protobuf model
11
+ module TraceTaintRange
12
+ def self.included klass
13
+ klass.extend(ClassMethods)
14
+ end
15
+
16
+ # Class methods for TraceEventObject
17
+ module ClassMethods
18
+ # Convert the tags from Contrast::Agent::Assess::Property::Tagged to
19
+ # the form required for their Event's DTM.
20
+ #
21
+ # @param tags [Hash{String => Array<Contrast::Agent::Assess::Tag>}]
22
+ # @return [Array<Contrast::Api::Dtm::TraceTaintRange>]
23
+ def build_for_event tags
24
+ return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags&.any?
25
+
26
+ ranges = []
27
+ tags.each_value do |value|
28
+ next if value.empty?
29
+
30
+ value.each { |tag| ranges << build(tag) }
31
+ end
32
+ ranges
33
+ end
34
+
35
+ # Convert our Tags to their DTM equivalent
36
+ #
37
+ # @param tag [Contrast::Agent::Assess::Tag]
38
+ # @return [Contrast::Api::Dtm::TraceTaintRange]
39
+ def build tag
40
+ range = Contrast::Api::Dtm::TraceTaintRange.new
41
+ range.tag = Contrast::Utils::StringUtils.protobuf_safe_string(tag.label)
42
+ range.range = tag.start_idx.to_s + Contrast::Utils::ObjectShare::COLON + tag.end_idx.to_s
43
+ range
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ Contrast::Api::Dtm::TraceTaintRange.include(Contrast::Api::Decorators::TraceTaintRange)
@@ -0,0 +1,109 @@
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
+ module Contrast
5
+ module Api
6
+ module Decorators
7
+ # A holder for the valid tags that can be sent to the Service, and
8
+ # ultimately TS, that we have to honor. Placed here so as not to clutter
9
+ # other code.
10
+ module TraceTaintRangeTags
11
+ # EventTagTypeDTM
12
+ VALID_TAGS = %w[
13
+ XML_ENCODED
14
+ XML_DECODED
15
+ HTML_ENCODED
16
+ HTML_DECODED
17
+ URL_ENCODED
18
+ URL_DECODED
19
+ CSS_ENCODED
20
+ CSS_DECODED
21
+ BASE64_ENCODED
22
+ BASE64_DECODED
23
+ JAVASCRIPT_ENCODED
24
+ JAVASCRIPT_DECODED
25
+ JAVA_ENCODED
26
+ JAVA_DECODED
27
+ CSV_ENCODED
28
+ CSV_DECODED
29
+ SQL_ENCODED
30
+ SQL_DECODED
31
+ LDAP_ENCODED
32
+ LDAP_DECODED
33
+ XPATH_ENCODED
34
+ XPATH_DECODED
35
+ OS_ENCODED
36
+ OS_DECODED
37
+ VBSCRIPT_ENCODED
38
+ VBSCRIPT_DECODED
39
+ POTENTIAL_SANITIZED
40
+ POTENTIAL_VALIDATED
41
+ NO_CONTROL_CHARS
42
+ CUSTOM
43
+
44
+ CUSTOM_ENCODED
45
+ CUSTOM_ENCODED_CMD_INJECTION
46
+ CUSTOM_ENCODED_EXPRESSION_LANGUAGE_INJECTION
47
+ CUSTOM_ENCODED_HEADER_INJECTION
48
+ CUSTOM_ENCODED_HQL_INJECTION
49
+ CUSTOM_ENCODED_LDAP_INJECTION
50
+ CUSTOM_ENCODED_LOG_INJECTION
51
+ CUSTOM_ENCODED_NOSQL_INJECTION
52
+ CUSTOM_ENCODED_PATH_TRAVERSAL
53
+ CUSTOM_ENCODED_REDOS
54
+ CUSTOM_ENCODED_REFLECTED_XSS
55
+ CUSTOM_ENCODED_REFLECTION_INJECTION
56
+ CUSTOM_ENCODED_SMTP_INJECTION
57
+ CUSTOM_ENCODED_SQL_INJECTION
58
+ CUSTOM_ENCODED_SSRF
59
+ CUSTOM_ENCODED_STORED_XSS
60
+ CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION
61
+ CUSTOM_ENCODED_UNSAFE_CODE_EXECUTION
62
+ CUSTOM_ENCODED_UNSAFE_READLINE
63
+ CUSTOM_ENCODED_UNSAFE_XML_DECODE
64
+ CUSTOM_ENCODED_UNTRUSTED_DESERIALIZATION
65
+ CUSTOM_ENCODED_UNVALIDATED_FORWARD
66
+ CUSTOM_ENCODED_UNVALIDATED_REDIRECT
67
+ CUSTOM_ENCODED_XPATH_INJECTION
68
+ CUSTOM_ENCODED_XXE
69
+ CUSTOM_SECURITY_CONTROL_APPLIED
70
+
71
+ CUSTOM_VALIDATED
72
+ CUSTOM_VALIDATED_CMD_INJECTION
73
+ CUSTOM_VALIDATED_EXPRESSION_LANGUAGE_INJECTION
74
+ CUSTOM_VALIDATED_HEADER_INJECTION
75
+ CUSTOM_VALIDATED_HQL_INJECTION
76
+ CUSTOM_VALIDATED_LDAP_INJECTION
77
+ CUSTOM_VALIDATED_LOG_INJECTION
78
+ CUSTOM_VALIDATED_NOSQL_INJECTION
79
+ CUSTOM_VALIDATED_PATH_TRAVERSAL
80
+ CUSTOM_VALIDATED_REDOS
81
+ CUSTOM_VALIDATED_REFLECTED_XSS
82
+ CUSTOM_VALIDATED_REFLECTION_INJECTION
83
+ CUSTOM_VALIDATED_SMTP_INJECTION
84
+ CUSTOM_VALIDATED_SQL_INJECTION
85
+ CUSTOM_VALIDATED_SSRF
86
+ CUSTOM_VALIDATED_STORED_XSS
87
+ CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION
88
+ CUSTOM_VALIDATED_UNSAFE_CODE_EXECUTION
89
+ CUSTOM_VALIDATED_UNSAFE_READLINE
90
+ CUSTOM_VALIDATED_UNSAFE_XML_DECODE
91
+ CUSTOM_VALIDATED_UNTRUSTED_DESERIALIZATION
92
+ CUSTOM_VALIDATED_UNVALIDATED_FORWARD
93
+ CUSTOM_VALIDATED_UNVALIDATED_REDIRECT
94
+ CUSTOM_VALIDATED_XPATH_INJECTION
95
+ CUSTOM_VALIDATED_XXE
96
+
97
+ DATABASE_WRITE
98
+ ].cs__freeze
99
+
100
+ VALID_SOURCE_TAGS = %w[
101
+ NO_NEWLINES
102
+ UNTRUSTED
103
+ CROSS_SITE
104
+ LIMITED_CHARS
105
+ ].cs__freeze
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,40 @@
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/utils/string_utils'
5
+ cs__scoped_require 'contrast/utils/assess/tracking_util'
6
+ cs__scoped_require 'base64'
7
+
8
+ module Contrast
9
+ module Api
10
+ module Decorators
11
+ # Used to decorate the TraceEventObject protobuf model
12
+ module UserInput
13
+ UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
14
+ user_input.input_type = :UNKNOWN
15
+ end.cs__freeze
16
+
17
+ def self.included klass
18
+ klass.extend(ClassMethods)
19
+ end
20
+
21
+ # Used to add class methods to UserInput
22
+ module ClassMethods
23
+ def build_from_ia_result ia_result
24
+ return UNKNOWN_USER_INPUT.dup unless ia_result
25
+
26
+ user_input = new
27
+ user_input.input_type = ia_result.input_type.to_i
28
+ user_input.matcher_ids = ia_result.ids
29
+ user_input.path = ia_result.path.to_s
30
+ user_input.key = ia_result.key.to_s
31
+ user_input.value = ia_result.value.to_s
32
+ user_input
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ Contrast::Api::Dtm::UserInput.include(Contrast::Api::Decorators::UserInput)
@@ -2,19 +2,19 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  cs__scoped_require 'rubygems/version'
5
+ cs__scoped_require 'contrast/agent/rule_set'
5
6
 
6
7
  module Contrast
7
8
  module Components
8
9
  module Agent
9
10
  # A wrapper build around the Common Agent Configuration project to allow
10
- # for access of the values contained in its
11
- # parent_configuration_spec.yaml.
11
+ # for access of the values contained in its parent_configuration_spec.yaml.
12
12
  # Specifically, this allows for querying the state of the Agent.
13
13
  class Interface
14
14
  include Contrast::Components::ComponentBase
15
15
  include Contrast::Components::Interface
16
16
 
17
- access_component :config
17
+ access_component :analysis, :config, :settings
18
18
 
19
19
  def enabled?
20
20
  !!@enabled
@@ -32,12 +32,12 @@ module Contrast
32
32
  @enabled = false
33
33
  end
34
34
 
35
- def unavailable?
36
- !enabled?
35
+ def ruleset
36
+ @_ruleset ||= Contrast::Agent::RuleSet.new(retrieve_ruleset&.values)
37
37
  end
38
38
 
39
- def ready?
40
- state.agent_ready?
39
+ def reset_ruleset
40
+ @_ruleset = nil
41
41
  end
42
42
 
43
43
  def patch_interpolation?
@@ -49,15 +49,26 @@ module Contrast
49
49
  end
50
50
 
51
51
  def patch_yield?
52
- !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.propagate_yield)
52
+ @_patch_yield = !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.propagate_yield) if @_patch_yield.nil?
53
+ @_patch_yield
53
54
  end
54
55
 
55
56
  def interpolation_enabled?
56
- !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.interpolate)
57
+ @_interpolation_enabled = !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.interpolate) if @_interpolation_enabled.nil?
58
+ @_interpolation_enabled
59
+ end
60
+
61
+ def omit_body?
62
+ @_omit_body = true?(CONFIG.root.agent.omit_body) if @_omit_body.nil?
63
+ @_omit_body
57
64
  end
58
65
 
59
- def report_custom_code_sysfile_access?
60
- Contrast::Agent::FeatureState.instance.report_custom_code_sysfile_access?
66
+ def exception_control
67
+ @_exception_control ||= {
68
+ enable: true?(CONFIG.root.agent.ruby.exceptions.capture),
69
+ status: CONFIG.root.agent.ruby.exceptions.override_status || 403,
70
+ message: CONFIG.root.agent.ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
71
+ }
61
72
  end
62
73
 
63
74
  def skip_instrumentation? loaded_module_name
@@ -66,19 +77,6 @@ module Contrast
66
77
  loaded_module_name.start_with?(*CONFIG.root.agent.ruby.uninstrument_namespace)
67
78
  end
68
79
 
69
- # All this method chain does anymore is load the Thread patch that
70
- # propagates request contexts. That can go away RUBY-700.
71
- SHARED_LIBRARIES = %w[contrast/extensions/ruby_core/thread].cs__freeze
72
- def run_instrumentation
73
- Contrast::Agent::FeatureState.instance.tap do |settings|
74
- SHARED_LIBRARIES.each { |lib| settings.instrument lib }
75
- end
76
- Contrast::Agent::Patching::Policy::Patcher.patch # This acts as a catch up for everything we didn't see get loaded
77
- enable_tracepoint # This handles all class loads & required instrumentation going forward
78
- end
79
-
80
- # TODO: RUBY-564: This responsibility should be extracted out of this agent component and moved to
81
- # the new component that handles one-time-whole-app initialization procedures.
82
80
  def insert_middleware app
83
81
  app.middleware.insert_before 0, Contrast::Agent::Middleware # Keep our middleware at the outermost layer of the onion
84
82
  end
@@ -96,6 +94,18 @@ module Contrast
96
94
  @_interpolation_patch_possible = Gem::Version.new(RUBY_VERSION) >= INTERPOLATION_HOOKABLE_VERSION if @_interpolation_patch_possible.nil?
97
95
  @_interpolation_patch_possible
98
96
  end
97
+
98
+ def retrieve_ruleset
99
+ return {} unless enabled?
100
+
101
+ if ASSESS.enabled? && PROTECT.enabled?
102
+ ASSESS.rules.merge(PROTECT.rules)
103
+ elsif ASSESS.enabled?
104
+ ASSESS.rules
105
+ else
106
+ PROTECT.rules
107
+ end
108
+ end
99
109
  end
100
110
 
101
111
  COMPONENT_INTERFACE = Interface.new
@@ -1,7 +1,6 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/sinatra_helper'
5
4
  cs__scoped_require 'rubygems/version'
6
5
 
7
6
  module Contrast
@@ -16,32 +15,30 @@ module Contrast
16
15
  include Contrast::Components::ComponentBase
17
16
  include Contrast::Components::Interface
18
17
 
19
- access_component :config
18
+ access_component :agent, :config
20
19
 
21
20
  DEFAULT_APP_NAME = 'rails'
22
21
  DEFAULT_APP_PATH = '/'
23
22
  DEFAULT_SERVER_NAME = 'localhost'
24
23
  DEFAULT_SERVER_PATH = '/'
25
24
 
26
- def present? str
27
- Contrast::Utils::EnvironmentUtil.present?(str)
25
+ def initialize
26
+ original_pid
28
27
  end
29
28
 
30
29
  def server_type
31
30
  @_server_type ||= begin
32
31
  tmp = CONFIG.root.server.type
33
- tmp = Contrast::Agent.framework_manager.server_type unless present?(tmp)
32
+ tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
34
33
  tmp
35
- rescue StandardError
36
- RACK_TYPE
37
34
  end
38
35
  end
39
36
 
40
37
  def name
41
38
  @_name ||= begin
42
39
  tmp = CONFIG.root.application.name
43
- tmp = Contrast::Agent.framework_manager.app_name unless present?(tmp)
44
- tmp = File.basename(Dir.pwd) unless present?(tmp)
40
+ tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
41
+ tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
45
42
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
46
43
  rescue StandardError
47
44
  DEFAULT_APP_NAME
@@ -60,7 +57,7 @@ module Contrast
60
57
  def server_name
61
58
  @_server_name ||= begin
62
59
  tmp = CONFIG.root.server.name
63
- tmp = Socket.gethostname unless present?(tmp)
60
+ tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
64
61
  tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
65
62
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
66
63
  rescue StandardError
@@ -71,7 +68,7 @@ module Contrast
71
68
  def server_path
72
69
  @_server_path ||= begin
73
70
  tmp = CONFIG.root.server.path
74
- tmp = Dir.pwd unless present?(tmp)
71
+ tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
75
72
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
76
73
  rescue StandardError
77
74
  DEFAULT_SERVER_PATH
@@ -81,34 +78,27 @@ module Contrast
81
78
  def build_app_startup_message
82
79
  msg = Contrast::Api::Dtm::ApplicationCreate.new
83
80
 
84
- app_ver = if CONFIG.root.application.version.to_s.empty?
85
- Contrast::Utils::EnvironmentUtil.determine_application_version
86
- else
87
- CONFIG.root.application.version
88
- end
89
-
90
- msg.group = protobuf_format CONFIG.root.application.group
91
- msg.tags = protobuf_format CONFIG.root.application.tags
92
- msg.app_version = protobuf_format app_ver
93
- msg.code = protobuf_format CONFIG.root.application.code
94
- msg.metadata = protobuf_format CONFIG.root.application.metadata
81
+ msg.group = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.group
82
+ msg.tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
83
+ msg.app_version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.version.to_s
84
+ msg.code = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.code
85
+ msg.metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.metadata
95
86
  # Other fields have limits in TeamServer, the rest don't.
96
- msg.session_id = protobuf_format CONFIG.root.application.session_id, truncate: false
97
- msg.session_metadata = protobuf_format CONFIG.root.application.session_metadata, truncate: false
87
+ msg.session_id = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_id, truncate: false
88
+ msg.session_metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_metadata, truncate: false
98
89
 
99
90
  msg
100
91
  end
101
92
 
102
- LOG_BUILD_STARTUP = 'build startup message'
103
93
  def build_agent_startup_message
104
94
  msg = Contrast::Api::Dtm::AgentStartup.new
105
- msg.server_name = protobuf_format server_name
106
- msg.server_path = protobuf_format server_path
107
- msg.server_type = protobuf_format server_type
95
+ msg.server_name = Contrast::Utils::StringUtils.protobuf_format server_name
96
+ msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path
97
+ msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type
108
98
  msg.server_version = Contrast::Agent::VERSION
109
- msg.version = protobuf_format CONFIG.root.server.version
110
- msg.environment = protobuf_format CONFIG.root.server.environment
111
- msg.tags = protobuf_format CONFIG.root.server.tags
99
+ msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
100
+ msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
101
+ msg.tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
112
102
  msg
113
103
  end
114
104
 
@@ -128,20 +118,30 @@ module Contrast
128
118
  @_client_id ||= [name, pgid].join('-')
129
119
  end
130
120
 
131
- # TODO: RUBY-564: This responsibility should be extracted out of app_context and moved to
132
- # the new component that handles one-time-whole-app initialization procedures.
133
121
  def instrument_middleware_stack?
134
122
  !Contrast::Utils::JobServersRunning.job_servers_running?
135
123
  end
136
124
 
125
+ def disabled_agent_rake_tasks
126
+ CONFIG.root.agent.ruby.disabled_agent_rake_tasks
127
+ end
128
+
129
+ # Determines if the Process we're currently in matches that of the
130
+ # Process in which the App Context instance was created.
131
+ # If it doesn't, that indicates the running context is in a new
132
+ # Process.
133
+ # @return [Boolean] if we're in the original Process in which the
134
+ # App Context instance was initialized.
135
+ def in_new_process?
136
+ current_pid = Process.pid
137
+ original_pid = pid
138
+ current_pid != original_pid
139
+ end
140
+
137
141
  private
138
142
 
139
- # TODO: RUBY-120, move this responsibility toward the protobuf object
140
- def protobuf_format param, truncate: true
141
- param = param&.to_s
142
- param = Contrast::Utils::StringUtils.force_utf8(param)
143
- param = Contrast::Utils::StringUtils.truncate(param) if truncate
144
- param
143
+ def original_pid
144
+ @_original_pid ||= Process.pid
145
145
  end
146
146
  end
147
147