contrast-agent 5.3.0 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +1 -1
  3. data/Rakefile +1 -1
  4. data/ext/build_funchook.rb +3 -3
  5. data/ext/cs__assess_array/cs__assess_array.c +7 -0
  6. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +24 -6
  7. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  8. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  11. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  12. data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
  13. data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
  14. data/ext/cs__assess_string/cs__assess_string.c +21 -1
  15. data/ext/cs__assess_test/cs__assess_test.h +9 -0
  16. data/ext/cs__assess_test/cs__assess_tests.c +22 -0
  17. data/ext/cs__assess_test/extconf.rb +5 -0
  18. data/ext/cs__common/cs__common.c +113 -11
  19. data/ext/cs__common/cs__common.h +29 -5
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
  21. data/ext/cs__os_information/cs__os_information.c +13 -10
  22. data/ext/cs__scope/cs__scope.c +146 -97
  23. data/ext/cs__tests/cs__tests.c +12 -0
  24. data/ext/cs__tests/cs__tests.h +3 -0
  25. data/ext/cs__tests/extconf.rb +5 -0
  26. data/ext/extconf_common.rb +1 -1
  27. data/lib/contrast/agent/assess/contrast_object.rb +16 -16
  28. data/lib/contrast/agent/assess/events/source_event.rb +17 -19
  29. data/lib/contrast/agent/assess/finalizers/hash.rb +4 -2
  30. data/lib/contrast/agent/assess/policy/policy.rb +9 -10
  31. data/lib/contrast/agent/assess/policy/policy_node.rb +58 -36
  32. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  33. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
  34. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  35. data/lib/contrast/agent/assess/policy/propagation_method.rb +48 -14
  36. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
  37. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  38. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +119 -0
  39. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  40. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  41. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  42. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  43. data/lib/contrast/agent/assess/policy/propagator/split.rb +17 -21
  44. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  45. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/trim.rb +2 -2
  47. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  48. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  49. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  50. data/lib/contrast/agent/assess/policy/trigger_method.rb +11 -17
  51. data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
  52. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  53. data/lib/contrast/agent/assess/property/evented.rb +2 -2
  54. data/lib/contrast/agent/assess/property/tagged.rb +3 -3
  55. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
  56. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
  57. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
  58. data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
  59. data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
  60. data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
  61. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
  62. data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
  63. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
  64. data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
  65. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
  66. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
  67. data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
  68. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
  69. data/lib/contrast/agent/assess/tag.rb +13 -14
  70. data/lib/contrast/agent/at_exit_hook.rb +12 -1
  71. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  72. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  73. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  74. data/lib/contrast/agent/inventory/database_config.rb +10 -3
  75. data/lib/contrast/agent/middleware.rb +10 -5
  76. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
  77. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
  78. data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
  79. data/lib/contrast/agent/patching/policy/patch.rb +20 -19
  80. data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
  81. data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
  82. data/lib/contrast/agent/patching/policy/policy.rb +13 -15
  83. data/lib/contrast/agent/patching/policy/policy_node.rb +32 -21
  84. data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
  85. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  86. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +132 -75
  87. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +4 -3
  88. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  89. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  90. data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
  91. data/lib/contrast/agent/protect/rule/base.rb +53 -9
  92. data/lib/contrast/agent/protect/rule/base_service.rb +31 -12
  93. data/lib/contrast/agent/protect/rule/cmd_injection.rb +23 -3
  94. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  95. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  96. data/lib/contrast/agent/protect/rule/default_scanner.rb +2 -1
  97. data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
  98. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  99. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +72 -46
  100. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  101. data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -2
  102. data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
  103. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
  104. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +2 -5
  105. data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
  106. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  107. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  108. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  109. data/lib/contrast/agent/protect/rule/xss.rb +17 -0
  110. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
  111. data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
  112. data/lib/contrast/agent/reaction_processor.rb +1 -1
  113. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  114. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  115. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  116. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  117. data/lib/contrast/agent/reporting/masker/masker.rb +243 -0
  118. data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
  119. data/lib/contrast/agent/reporting/report.rb +2 -0
  120. data/lib/contrast/agent/reporting/reporter.rb +29 -22
  121. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
  122. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
  123. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
  124. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
  125. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
  126. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
  127. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
  128. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
  129. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
  130. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +13 -5
  131. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
  132. data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
  133. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +44 -0
  134. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  135. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
  136. data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
  137. data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
  138. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
  139. data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
  140. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  141. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
  142. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
  143. data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
  144. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
  145. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +8 -11
  146. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
  147. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  148. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
  149. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
  150. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
  151. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
  152. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
  153. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  154. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
  155. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +29 -13
  156. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
  157. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  158. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
  159. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
  160. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
  161. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  162. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +163 -122
  163. data/lib/contrast/agent/reporting/settings/application_settings.rb +10 -1
  164. data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
  165. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +7 -35
  166. data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
  167. data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
  168. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
  169. data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
  170. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  171. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  172. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  173. data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
  174. data/lib/contrast/agent/request.rb +5 -5
  175. data/lib/contrast/agent/request_context.rb +25 -21
  176. data/lib/contrast/agent/request_context_extend.rb +12 -25
  177. data/lib/contrast/agent/request_handler.rb +7 -3
  178. data/lib/contrast/agent/response.rb +2 -0
  179. data/lib/contrast/agent/rule_set.rb +2 -2
  180. data/lib/contrast/agent/scope.rb +1 -1
  181. data/lib/contrast/agent/service_heartbeat.rb +6 -48
  182. data/lib/contrast/agent/static_analysis.rb +1 -1
  183. data/lib/contrast/agent/telemetry/base.rb +155 -0
  184. data/lib/contrast/agent/telemetry/events/event.rb +35 -0
  185. data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
  186. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +59 -0
  187. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
  188. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
  189. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
  190. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
  191. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
  192. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
  193. data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
  194. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
  195. data/lib/contrast/agent/thread_watcher.rb +52 -68
  196. data/lib/contrast/agent/version.rb +1 -1
  197. data/lib/contrast/agent/worker_thread.rb +8 -0
  198. data/lib/contrast/agent.rb +4 -3
  199. data/lib/contrast/api/communication/messaging_queue.rb +29 -12
  200. data/lib/contrast/api/communication/response_processor.rb +7 -10
  201. data/lib/contrast/api/communication/service_lifecycle.rb +1 -1
  202. data/lib/contrast/api/communication/socket.rb +1 -1
  203. data/lib/contrast/api/communication/socket_client.rb +1 -1
  204. data/lib/contrast/api/communication/speedracer.rb +3 -3
  205. data/lib/contrast/api/decorators/activity.rb +33 -0
  206. data/lib/contrast/api/decorators/address.rb +1 -1
  207. data/lib/contrast/api/decorators/agent_startup.rb +10 -9
  208. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  209. data/lib/contrast/api/decorators/application_startup.rb +4 -4
  210. data/lib/contrast/api/decorators/http_request.rb +1 -1
  211. data/lib/contrast/api/decorators/response_type.rb +17 -0
  212. data/lib/contrast/api/decorators.rb +1 -0
  213. data/lib/contrast/components/agent.rb +1 -1
  214. data/lib/contrast/components/app_context.rb +0 -4
  215. data/lib/contrast/components/assess.rb +14 -0
  216. data/lib/contrast/components/base.rb +1 -1
  217. data/lib/contrast/components/config.rb +19 -28
  218. data/lib/contrast/components/contrast_service.rb +13 -1
  219. data/lib/contrast/components/protect.rb +2 -2
  220. data/lib/contrast/components/sampling.rb +8 -12
  221. data/lib/contrast/components/settings.rb +151 -19
  222. data/lib/contrast/config/agent_configuration.rb +34 -41
  223. data/lib/contrast/config/api_configuration.rb +16 -75
  224. data/lib/contrast/config/api_proxy_configuration.rb +9 -48
  225. data/lib/contrast/config/application_configuration.rb +24 -95
  226. data/lib/contrast/config/assess_configuration.rb +21 -76
  227. data/lib/contrast/config/assess_rules_configuration.rb +13 -38
  228. data/lib/contrast/config/base_configuration.rb +11 -76
  229. data/lib/contrast/config/certification_configuration.rb +15 -68
  230. data/lib/contrast/config/exception_configuration.rb +15 -59
  231. data/lib/contrast/config/heap_dump_configuration.rb +19 -73
  232. data/lib/contrast/config/inventory_configuration.rb +11 -55
  233. data/lib/contrast/config/logger_configuration.rb +8 -41
  234. data/lib/contrast/config/protect_configuration.rb +23 -10
  235. data/lib/contrast/config/protect_rule_configuration.rb +23 -37
  236. data/lib/contrast/config/protect_rules_configuration.rb +39 -43
  237. data/lib/contrast/config/request_audit_configuration.rb +16 -55
  238. data/lib/contrast/config/root_configuration.rb +71 -14
  239. data/lib/contrast/config/ruby_configuration.rb +14 -47
  240. data/lib/contrast/config/sampling_configuration.rb +12 -65
  241. data/lib/contrast/config/server_configuration.rb +13 -45
  242. data/lib/contrast/config/service_configuration.rb +18 -54
  243. data/lib/contrast/configuration.rb +25 -17
  244. data/lib/contrast/extension/assess/array.rb +1 -1
  245. data/lib/contrast/extension/assess/erb.rb +1 -1
  246. data/lib/contrast/extension/assess/marshal.rb +1 -1
  247. data/lib/contrast/extension/assess/string.rb +20 -1
  248. data/lib/contrast/extension/extension.rb +2 -2
  249. data/lib/contrast/extension/module.rb +0 -1
  250. data/lib/contrast/framework/base_support.rb +8 -8
  251. data/lib/contrast/framework/grape/support.rb +3 -3
  252. data/lib/contrast/framework/manager.rb +7 -7
  253. data/lib/contrast/framework/manager_extend.rb +1 -1
  254. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  255. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
  256. data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
  257. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  258. data/lib/contrast/framework/rails/patch/support.rb +14 -46
  259. data/lib/contrast/framework/rails/support.rb +2 -2
  260. data/lib/contrast/framework/sinatra/support.rb +1 -1
  261. data/lib/contrast/logger/aliased_logging.rb +94 -0
  262. data/lib/contrast/logger/application.rb +1 -5
  263. data/lib/contrast/logger/cef_log.rb +15 -15
  264. data/lib/contrast/logger/format.rb +1 -1
  265. data/lib/contrast/logger/log.rb +8 -8
  266. data/lib/contrast/tasks/config.rb +100 -4
  267. data/lib/contrast/tasks/service.rb +2 -2
  268. data/lib/contrast/utils/assess/object_store.rb +36 -0
  269. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  270. data/lib/contrast/utils/assess/tracking_util.rb +4 -4
  271. data/lib/contrast/utils/class_util.rb +9 -22
  272. data/lib/contrast/utils/findings.rb +3 -3
  273. data/lib/contrast/utils/hash_digest.rb +6 -7
  274. data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
  275. data/lib/contrast/utils/input_classification.rb +73 -0
  276. data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
  277. data/lib/contrast/utils/log_utils.rb +7 -5
  278. data/lib/contrast/utils/lru_cache.rb +1 -1
  279. data/lib/contrast/utils/metrics_hash.rb +1 -1
  280. data/lib/contrast/utils/middleware_utils.rb +15 -14
  281. data/lib/contrast/utils/net_http_base.rb +5 -5
  282. data/lib/contrast/utils/object_share.rb +2 -1
  283. data/lib/contrast/utils/os.rb +1 -6
  284. data/lib/contrast/utils/patching/policy/patch_utils.rb +6 -7
  285. data/lib/contrast/utils/request_utils.rb +2 -2
  286. data/lib/contrast/utils/response_utils.rb +18 -33
  287. data/lib/contrast/utils/sha256_builder.rb +4 -4
  288. data/lib/contrast/utils/stack_trace_utils.rb +31 -13
  289. data/lib/contrast/utils/telemetry.rb +22 -7
  290. data/lib/contrast/utils/telemetry_client.rb +28 -16
  291. data/lib/contrast/utils/telemetry_hash.rb +41 -0
  292. data/lib/contrast/utils/telemetry_identifier.rb +18 -3
  293. data/lib/contrast/utils/timer.rb +1 -1
  294. data/lib/contrast.rb +9 -0
  295. data/resources/assess/policy.json +99 -1
  296. data/resources/deadzone/policy.json +0 -86
  297. data/ruby-agent.gemspec +10 -9
  298. data/service_executables/VERSION +1 -1
  299. data/service_executables/linux/contrast-service +0 -0
  300. data/service_executables/mac/contrast-service +0 -0
  301. metadata +99 -29
  302. data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
  303. data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
  304. data/lib/contrast/agent/telemetry.rb +0 -137
  305. data/lib/contrast/agent/telemetry_event.rb +0 -33
  306. data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/utils/object_share'
5
+
6
+ module Contrast
7
+ module Agent
8
+ module Reporting
9
+ module Settings
10
+ # Sampling controls for the Assess Features provided by TeamServer
11
+ class Sampling
12
+ # @return [Integer] The number of baseline requests to take before switching to sampling for the window.
13
+ attr_reader :baseline
14
+ # @return [Boolean] If the sampling feature should be used or not.
15
+ attr_reader :enabled
16
+ # @return [Integer] The number of requests to skip before observing during the sampling window after the
17
+ # baseline.
18
+ attr_reader :request_frequency
19
+ # @return [Integer] The number of responses to skip before observing during the sampling window after the
20
+ # baseline.
21
+ attr_reader :response_frequency
22
+ # @return [Integer] The length of time for which the sample period is valid, in ms.
23
+ attr_reader :window_ms
24
+
25
+ def initialize hsh
26
+ @baseline = hsh[:baseline]
27
+ @enabled = hsh[:enabled]
28
+ @request_frequency = hsh[:frequency]
29
+ @response_frequency = hsh[:responseFrequency]
30
+ @window_ms = hsh[:window]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,110 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/agent/reporting/settings/sensitive_data_masking_rule'
5
+
6
+ module Contrast
7
+ module Agent
8
+ module Reporting
9
+ # This module will hold all the settings from the TS responce
10
+ module Settings
11
+ # Protect level settings for the sensitive_data_masking_policy.
12
+ # Configuration of the masking parameters will be delivered dynamically from TeamServer
13
+ # during an ApplicationSettings response from requests to TS endpoints that return that
14
+ # structure.
15
+ # https://contrast.atlassian.net/wiki/spaces/~699189087/pages/807960614/Sensitive+Data+Masking+Design
16
+ class SensitiveDataMasking
17
+ # Policy flag to enable the use of masking on request body
18
+ # Here is set to defaults to true.
19
+ #
20
+ # @return true | false
21
+ def mask_http_body?
22
+ @_mask_http_body
23
+ end
24
+
25
+ # Set the flag for request body masking
26
+ #
27
+ # @param bool [Boolean]
28
+ # @return true | false
29
+ def mask_http_body= bool
30
+ @_mask_http_body = bool.nil? ? true : !!bool
31
+ end
32
+
33
+ # Policy flag to enable the use of masking on attack vector.
34
+ # Here is set to defaults to false.
35
+ #
36
+ # @return true | false
37
+ def mask_attack_vector?
38
+ @_mask_attack_vector
39
+ end
40
+
41
+ # Set the flag for using masking on attack vector
42
+ #
43
+ # @param bool [Boolean]
44
+ # @return true | false
45
+ def mask_attack_vector= bool
46
+ @_mask_attack_vector = !!bool
47
+ end
48
+
49
+ # Rules to follow when using the masking
50
+ #
51
+ # @return rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>, []]
52
+ def rules
53
+ @_rules ||= Contrast::Agent::Reporting::Settings::RulesArray.new
54
+ end
55
+
56
+ # Assign rules array
57
+ #
58
+ # @param rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>]
59
+ # @return rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>, []]
60
+ def rules= rules
61
+ @_rules = rules if rules_array?(rules)
62
+ end
63
+
64
+ # Build rules from hash
65
+ #
66
+ # @param settings_rules [Hash] Response settings under Settings/sensitive_data_masking_policy/rules
67
+ # @return rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>, nil
68
+ def build_rules_form_settings settings_rules
69
+ return unless settings_rules || settings_rules.empty?
70
+
71
+ settings_rules.each do |rule|
72
+ instance = Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule.new
73
+ instance.rule_id = rule[:id]
74
+ instance.keywords = rule[:keywords]
75
+ rules << instance
76
+ end
77
+ rules
78
+ end
79
+
80
+ private
81
+
82
+ # Determine if parameter is array of Rules.
83
+ #
84
+ # @param array [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>] Array of keywords.
85
+ # @return true | false
86
+ def rules_array? array
87
+ return false unless array.is_a?(Array)
88
+
89
+ array.all?(Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule)
90
+ end
91
+ end
92
+
93
+ # Simple validation class for Rules Array.
94
+ class RulesArray < Array
95
+ # Do not push anything except Rules instances.
96
+ # :<< method is called on object directly so this
97
+ # will make sure the data pushed is as expected.
98
+ #
99
+ # @param item [Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule]
100
+ # @return itself [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>]
101
+ def << item
102
+ return itself unless item.instance_of?(Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule)
103
+
104
+ super
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,58 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/utils/object_share'
5
+
6
+ module Contrast
7
+ module Agent
8
+ module Reporting
9
+ # This module will hold all the settings from the TS responce
10
+ module Settings
11
+ # Protect level settings for the sensitive_data_masking_policy Rule entry.
12
+ class SensitiveDataMaskingRule
13
+ # Id for this rule.
14
+ #
15
+ # @return rule_id [String] Name of parameter to mask.
16
+ def rule_id
17
+ @_rule_id ||= Contrast::Utils::ObjectShare::EMPTY_STRING
18
+ end
19
+
20
+ # Set the rule name.
21
+ #
22
+ # @param id [String] Name of parameter to mask.
23
+ # @return rule_id [String]
24
+ def rule_id= id
25
+ @_rule_id = id.to_s
26
+ end
27
+
28
+ # Array of keywords to mask values for the rule_id.
29
+ #
30
+ # @return keywords [Array<String>] set of keywords
31
+ def keywords
32
+ @_keywords ||= []
33
+ end
34
+
35
+ # Set keywords array.
36
+ #
37
+ # @param words_array [Array<String>]
38
+ # @return keywords [Array<String>] set of keywords
39
+ def keywords= words_array
40
+ @_keywords = words_array if string_array?(words_array)
41
+ end
42
+
43
+ private
44
+
45
+ # Determine if a array is array of strings.
46
+ #
47
+ # @param array [Array<String] Array of keywords.
48
+ # @return true | false
49
+ def string_array? array
50
+ return false unless array.is_a?(Array) && array.any?
51
+
52
+ array.all?(String)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -27,7 +27,7 @@ module Contrast
27
27
  # @param log_level [String]
28
28
  # @return log_level [String] [ ERROR, WARN, INFO, DEBUG, TRACE ]
29
29
  def log_level= log_level
30
- @_log_level = log_level if log_level.is_a? String
30
+ @_log_level = log_level if log_level.is_a?(String)
31
31
  end
32
32
 
33
33
  # Where to log the agent's log file, if set by the user. Overridden by agent.logger.path
@@ -43,7 +43,7 @@ module Contrast
43
43
  # @param log_file [String] path
44
44
  # @return log_file [String] path
45
45
  def log_file= log_file
46
- @_log_file = log_file if log_file.is_a? String
46
+ @_log_file = log_file if log_file.is_a?(String)
47
47
  end
48
48
 
49
49
  # Controls for the reporting of telemetry events from the agent to TeamServer.
@@ -34,12 +34,14 @@ module Contrast
34
34
  LAST_REST_TOKEN = %r{/\d+$}.cs__freeze
35
35
  INNER_NUMBER_MARKER = '/{n}/'
36
36
  LAST_NUMBER_MARKER = '/{n}'
37
+ STATIC_SUFFIXES = /\.(?:js|css|jpeg|jpg|gif|png|ico|woff|svg|pdf|eot|ttf|jar)$/i.cs__freeze
38
+ MEDIA_TYPE_MARKERS = %w[image/ text/css text/javascript].cs__freeze
37
39
 
38
40
  attr_reader :rack_request
39
41
  attr_accessor :route, :observed_route, :new_observed_route
40
42
 
41
43
  # Delegate calls to the following methods to the attribute @rack_request
42
- def_delegators :@rack_request, :base_url, :content_type, :cookies, :env, :ip, :path, :port, :query_string,
44
+ def_delegators :@rack_request, :base_url, :cookies, :env, :ip, :media_type, :path, :port, :query_string,
43
45
  :request_method, :scheme, :url, :user_agent
44
46
 
45
47
  # Initialize new Contrast Request
@@ -86,9 +88,9 @@ module Contrast
86
88
  #
87
89
  # @return type [Symbol<:XML, :JSON, :NORMAL>]
88
90
  def document_type
89
- @_document_type ||= if /xml/i.match?(content_type) || body&.start_with?('<?xml')
91
+ @_document_type ||= if /xml/i.match?(media_type) || body&.start_with?('<?xml')
90
92
  :XML
91
- elsif /json/i.match?(content_type) || body&.match?(/\s*[{\[]/)
93
+ elsif /json/i.match?(media_type) || body&.match?(/\s*[{\[]/)
92
94
  :JSON
93
95
  else
94
96
  :NORMAL
@@ -181,8 +183,6 @@ module Contrast
181
183
  @_hash_id ||= Contrast::Utils::HashDigest.generate_request_hash(self)
182
184
  end
183
185
 
184
- STATIC_SUFFIXES = /\.(?:js|css|jpeg|jpg|gif|png|ico|woff|svg|pdf|eot|ttf|jar)$/i.cs__freeze
185
- MEDIA_TYPE_MARKERS = %w[image/ text/css text/javascript].cs__freeze
186
186
  # Utility method for checking if a request is for a static resource.
187
187
  # @return [Boolean] true, if the request is for a well-known static
188
188
  # type as determined by the request suffix or the accept header.
@@ -1,6 +1,7 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'contrast/api/dtm.pb'
4
5
  require 'contrast/utils/timer'
5
6
  require 'contrast/agent/request'
6
7
  require 'contrast/agent/response'
@@ -16,20 +17,6 @@ module Contrast
16
17
  module Agent
17
18
  # This class acts to encapsulate information about the currently executed request, making it available to the Agent
18
19
  # for the duration of the request in a standardized and normalized format which the Agent understands.
19
- #
20
- # @attr_reader timer [Contrast::Utils::Timer] when the context was created
21
- # @attr_reader logging_hash [Hash] context used to log the request
22
- # @attr_reader speedracer_input_analysis [Contrast::Api::Settings::InputAnalysis] the protect input analysis of
23
- # sources on this request
24
- # @attr_reader request [Contrast::Agent::Request] our wrapper around the Rack::Request for this context
25
- # @attr_reader response [Contrast::Agent::Response] our wrapper aroudn the Rack::Response or Array for this context,
26
- # only available after the application has finished its processing
27
- # @attr_reader activity [Contrast::Api::Dtm::Activity] the application activity found in this request
28
- # @attr_reader server_activity [Contrast::Api::Dtm::ServerActivity] the server activity found in this request
29
- # @attr_reader route [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
30
- # @attr_reader observed_route [Contrast::Api::Dtm::ObservedRoute] the route, used for coverage, of this request
31
- # @attr_reader new_observed_route [Contrast::Agent::Reporting::ObservedRoute] the route, used for coverage, of this
32
- # request
33
20
  class RequestContext
34
21
  include Contrast::Components::Logger::InstanceMethods
35
22
  include Contrast::Components::Scope::InstanceMethods
@@ -37,12 +24,30 @@ module Contrast
37
24
  include Contrast::Agent::RequestContextExtend
38
25
 
39
26
  EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
40
- INPUT_ANALYSIS = Contrast::Agent::Reporting::InputAnalysis.new
41
27
 
42
- attr_reader :activity, :logging_hash, :observed_route, :new_observed_route, :request, :response, :route,
43
- :speedracer_input_analysis, :agent_input_analysis, :server_activity, :timer
44
-
45
- def initialize rack_request, app_loaded = true
28
+ # @return [Contrast::Api::Dtm::Activity] the application activity found in this request
29
+ attr_reader :activity
30
+ # @return [Hash] context used to log the request
31
+ attr_reader :logging_hash
32
+ # @return [Contrast::Agent::Reporting::ObservedRoute] the route, used for coverage, of this request
33
+ attr_reader :new_observed_route
34
+ # @return [Contrast::Api::Dtm::ObservedRoute] the route, used for coverage, of this request
35
+ attr_reader :observed_route
36
+ # @return [Contrast::Agent::Request] our wrapper around the Rack::Request for this context
37
+ attr_reader :request
38
+ # @return [Contrast::Agent::Response] our wrapper around the Rack::Response or Array for this context,
39
+ # only available after the application has finished its processing
40
+ attr_reader :response
41
+ # @return [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
42
+ attr_reader :route
43
+ # @return [Contrast::Api::Dtm::ServerActivity] the server activity found in this request
44
+ attr_reader :server_activity
45
+ # @return [Contrast::Api::Settings::InputAnalysis] the protect input analysis of sources on this request
46
+ attr_reader :speedracer_input_analysis
47
+ # @return [Contrast::Utils::Timer] when the context was created
48
+ attr_reader :timer
49
+
50
+ def initialize rack_request, app_loaded: true
46
51
  with_contrast_scope do
47
52
  # all requests get a timer and hash
48
53
  @timer = Contrast::Utils::Timer.new
@@ -61,8 +66,7 @@ module Contrast
61
66
  @speedracer_input_analysis = EMPTY_INPUT_ANALYSIS_PB
62
67
  speedracer_input_analysis.request = request
63
68
 
64
- @agent_input_analysis = INPUT_ANALYSIS
65
- agent_input_analysis.request = request
69
+ # TODO: RUBY-1627
66
70
 
67
71
  # flag to indicate whether the app is fully loaded
68
72
  @app_loaded = !!app_loaded
@@ -76,15 +76,16 @@ module Contrast
76
76
  return false unless ::Contrast::PROTECT.enabled?
77
77
  return false if @do_not_track
78
78
 
79
- service_response = Contrast::Agent.messaging_queue.send_event_immediately(@activity.http_request)
79
+ service_response = Contrast::Agent&.messaging_queue&.send_event_immediately(@activity.http_request)
80
80
  return false unless service_response
81
81
 
82
82
  handle_protect_state(service_response)
83
83
  ia = service_response.input_analysis
84
84
  if ia
85
- service_extract_logging ia
85
+ service_extract_logging(ia)
86
+ # TODO: RUBY-1629
86
87
  # using Agent analysis
87
- initialize_agent_input_analysis request
88
+ # initialize_agent_input_analysis request
88
89
 
89
90
  @speedracer_input_analysis = ia
90
91
  speedracer_input_analysis.request = request
@@ -93,7 +94,7 @@ module Contrast
93
94
  false
94
95
  end
95
96
  rescue Contrast::SecurityException => e
96
- raise e
97
+ raise(e)
97
98
  rescue StandardError => e
98
99
  logger.warn('Unable to extract Contrast Service information from request', e)
99
100
  false
@@ -115,7 +116,7 @@ module Contrast
115
116
  # If Contrast Service has NOT handled the input analysis, handle them here
116
117
  build_attack_results(agent_settings)
117
118
  logger.debug('Contrast Service said to block this request')
118
- raise Contrast::SecurityException.new(nil, (state.security_message || 'Blocking suspicious behavior'))
119
+ raise(Contrast::SecurityException.new(nil, (state.security_message || 'Blocking suspicious behavior')))
119
120
  end
120
121
 
121
122
  # append anything we've learned to the request seen message this is the sum-total of all inventory information
@@ -126,6 +127,7 @@ module Contrast
126
127
  @response = Contrast::Agent::Response.new(rack_response)
127
128
  return unless @sample_res
128
129
 
130
+ #
129
131
  # TODO: RUBY-1376 once all rules translated, move this to if/else w/ the enabled
130
132
  if Contrast::Agent::Reporter.enabled?
131
133
  Contrast::Agent::Assess::Rule::Response::AutoComplete.new.analyze(@response)
@@ -146,7 +148,7 @@ module Contrast
146
148
 
147
149
  # This here is for things we don't have implemented
148
150
  def log_to_cef
149
- activity.results.each { |attack_result| logging_logic attack_result, attack_result.rule_id.downcase }
151
+ activity.results.each { |attack_result| logging_logic(attack_result, attack_result.rule_id.downcase) }
150
152
  end
151
153
 
152
154
  # @param input_analysis [Contrast::Api::Settings::InputAnalysis]
@@ -171,7 +173,7 @@ module Contrast
171
173
  next unless rule
172
174
 
173
175
  logger.debug(BUILD_ATTACK_LOGGER_MESSAGE, result: ia_result.inspect) if logger.debug?
174
- results_by_rule[rule_id] = attack_result rule, rule_id, ia_result, results_by_rule
176
+ results_by_rule[rule_id] = attack_result(rule, rule_id, ia_result, results_by_rule)
175
177
  end
176
178
 
177
179
  results_by_rule.each_pair do |_, attack_result|
@@ -198,21 +200,6 @@ module Contrast
198
200
  end
199
201
  end
200
202
 
201
- # Sets request to be used with agent and service input analysis.
202
- #
203
- # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request
204
- # for this context
205
- def initialize_agent_input_analysis request
206
- # using Agent analysis
207
- ia = Contrast::Agent::Protect::InputAnalyzer.analyse request
208
- if ia
209
- @agent_input_analysis = ia
210
- else
211
- logger.trace('Analysis from Agent was empty.')
212
-
213
- end
214
- end
215
-
216
203
  def logging_logic result, rule_id
217
204
  rules = %w[bot_blocker virtual_patch ip_denylist]
218
205
  return unless rules.include?(rule_id)
@@ -221,14 +208,14 @@ module Contrast
221
208
  outcome = Contrast::Api::Dtm::AttackResult::ResponseType.get_name_by_tag(result.response)
222
209
  case rule_id
223
210
  when /bot_blocker/i
224
- blocker_to_json = Contrast::Api::Dtm::BotBlockerDetails.to_controlled_hash rule_details
211
+ blocker_to_json = Contrast::Api::Dtm::BotBlockerDetails.to_controlled_hash(rule_details)
225
212
  cef_logger.bot_blocking_message(blocker_to_json, outcome)
226
213
  when /virtual_patch/i
227
- virtual_patch_to_json = Contrast::Api::Dtm::VirtualPatchDetails.to_controlled_hash rule_details
214
+ virtual_patch_to_json = Contrast::Api::Dtm::VirtualPatchDetails.to_controlled_hash(rule_details)
228
215
  cef_logger.virtual_patch_message(virtual_patch_to_json, outcome)
229
216
  when /ip_denylist/i
230
217
  sender_ip = extract_sender_ip
231
- ip_denylist_to_json = Contrast::Api::Dtm::IpDenylistDetails.to_controlled_hash rule_details
218
+ ip_denylist_to_json = Contrast::Api::Dtm::IpDenylistDetails.to_controlled_hash(rule_details)
232
219
  return unless sender_ip
233
220
  return unless sender_ip.include?(ip_denylist_to_json[:ip])
234
221
 
@@ -5,6 +5,7 @@ require 'contrast/components/logger'
5
5
  require 'contrast/components/scope'
6
6
  require 'contrast/agent/reporting/reporter'
7
7
  require 'contrast/agent/reporting/reporting_utilities/dtm_message'
8
+ require 'contrast/agent/reporting/masker/masker'
8
9
 
9
10
  module Contrast
10
11
  module Agent
@@ -46,18 +47,21 @@ module Contrast
46
47
  # This method is used to send our JSON messages directly to TeamServer at the end of each request. As we move
47
48
  # more endpoints over, this method will take the messages originally sent by #send_actiivty_messages. At the end,
48
49
  # that method should be removed.
49
- # TODO: RUBY-1358
50
- def report_activity
50
+ def report_activity # rubocop:disable Metrics/AbcSize
51
51
  return unless Contrast::Agent::Reporter.enabled?
52
52
 
53
53
  reporter = Contrast::Agent.reporter
54
54
  return unless reporter
55
55
 
56
+ # Mask Sensitive Data
57
+ Contrast::Agent::Reporting::Masker.mask(context.activity)
58
+
56
59
  Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage(context.activity)
57
60
  [
58
61
  context.new_observed_route,
59
62
  Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.server_activity),
60
- Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity.library_usages)
63
+ Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity.library_usages),
64
+ Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity)
61
65
  ].each do |event|
62
66
  reporter.send_event(event)
63
67
  rescue StandardError => e
@@ -22,6 +22,8 @@ module Contrast
22
22
 
23
23
  extend Forwardable
24
24
 
25
+ # @return [Array, Rack::Response] The Rack Response passed by the application & middleware. It can be an Array
26
+ # in format [response_code, header_hash, response_body] or an instance of Rack::Response
25
27
  attr_reader :rack_response
26
28
 
27
29
  def initialize rack_response
@@ -23,7 +23,7 @@ module Contrast
23
23
  end
24
24
  rescue Contrast::SecurityException => e
25
25
  logger.warn('RASP threw security exception in prefilter', e)
26
- raise e
26
+ raise(e)
27
27
  rescue StandardError => e
28
28
  logger.error('Unexpected exception during prefilter', e)
29
29
  end
@@ -39,7 +39,7 @@ module Contrast
39
39
  end
40
40
  rescue Contrast::SecurityException => e
41
41
  logger.warn('RASP threw security exception in postfilter', e)
42
- raise e
42
+ raise(e)
43
43
  rescue StandardError => e
44
44
  logger.error('Unexpected exception during postfilter', e)
45
45
  end
@@ -142,7 +142,7 @@ module Contrast
142
142
  # @param scope_sym [Symbol] scope to check.
143
143
  # @return [Boolean] true | false
144
144
  def valid_scope? scope_sym
145
- Contrast::Agent::Scope::SCOPE_LIST.include? scope_sym
145
+ Contrast::Agent::Scope::SCOPE_LIST.include?(scope_sym)
146
146
  end
147
147
  end
148
148
  end
@@ -7,71 +7,29 @@ require 'contrast/agent/reporting/report'
7
7
 
8
8
  module Contrast
9
9
  module Agent
10
- # The ServiceHeartbeat functions to keep the Contrast Service alive and
11
- # ensure that it maintains this Agent's ApplicationContext.
10
+ # The ServiceHeartbeat functions to keep the Contrast Service alive and ensure that it maintains this Agent's
11
+ # ApplicationContext.
12
12
  class ServiceHeartbeat < WorkerThread
13
13
  include Contrast::Components::Logger::InstanceMethods
14
14
 
15
15
  # Spec recommends 30 seconds, we're going with 15.
16
16
  REFRESH_INTERVAL_SEC = 15
17
17
 
18
- # check if we can report to TS
19
- #
20
- # @return[Boolean] true if bypass is enabled, or false if bypass disabled
21
- def enabled?
22
- @_enabled = Contrast::CONTRAST_SERVICE.use_agent_communication? if @_enabled.nil?
23
- @_enabled
24
- end
25
-
26
- def client
27
- @_client ||= Contrast::Agent::Reporting::ReporterClient.new
28
- end
29
-
30
- def connection
31
- @_connection ||= client.initialize_connection
32
- end
33
-
34
18
  def start_thread!
19
+ return if ::Contrast::CONTRAST_SERVICE.unnecessary?
35
20
  return if running?
36
21
 
37
- report_from_reporter = check_report_provider
38
-
39
22
  @_thread = Contrast::Agent::Thread.new do
40
23
  logger.info('Starting heartbeat thread.')
41
24
  loop do
42
- if report_from_reporter
43
- client.send_event(poll_message, connection)
44
- else
45
- Contrast::Agent.messaging_queue.send_event_eventually(poll_message)
46
- end
47
-
48
- sleep REFRESH_INTERVAL_SEC
25
+ Contrast::Agent.messaging_queue.send_event_eventually(poll_message)
26
+ sleep(REFRESH_INTERVAL_SEC)
49
27
  end
50
28
  end
51
29
  end
52
30
 
53
31
  def poll_message
54
- @_poll_message ||= if enabled? && client
55
- Contrast::Agent::Reporting::Poll.new
56
- else
57
- Contrast::Api::Dtm::Poll.new
58
- end
59
- end
60
-
61
- def check_report_provider
62
- return false unless enabled?
63
- return false unless client && connection
64
-
65
- client.startup!(connection)
66
- true
67
- end
68
-
69
- def send_event provider
70
- if provider
71
- client.send_event(poll_message, connection)
72
- return
73
- end
74
- Contrast::Agent.messaging_queue.send_event_eventually(poll_message)
32
+ @_poll_message ||= Contrast::Api::Dtm::Poll.new
75
33
  end
76
34
  end
77
35
  end
@@ -40,7 +40,7 @@ module Contrast
40
40
  inventory_report = Contrast::Agent::Reporting::ApplicationInventory.convert(app_update_msg)
41
41
  Contrast::Agent.reporter.send_event(inventory_report)
42
42
  else
43
- Contrast::Agent.messaging_queue.send_event_eventually(app_update_msg)
43
+ Contrast::Agent.messaging_queue.send_event_eventually(app_update_msg, force: true)
44
44
  end
45
45
  end
46
46