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
@@ -6,25 +6,19 @@ require 'contrast/utils/object_share'
6
6
 
7
7
  module Contrast
8
8
  module Config
9
- # This is the base for our configuration classes. It is intended to
10
- # facilitate the translation of the Common Configuration settings to usable
11
- # Ruby classes.
12
- class BaseConfiguration
9
+ # This is the base for our configuration classes. It is intended to facilitate the translation of the Common
10
+ # Configuration settings to usable Ruby classes.
11
+ module BaseConfiguration
13
12
  extend Forwardable
14
13
 
15
- attr_reader :configuration_map
16
-
17
- alias_method :to_hash, :configuration_map
18
- def_delegators :@configuration_map, :empty?, :key?, :delete, :fetch,
19
- :[], :[]=, :each, :each_pair, :each_key, :each_value
20
-
21
- EMPTY_VALUE = :EMPTY_VALUE
22
-
23
- def initialize hsh = {}, keys = {}
24
- # holds configuration key value pairs
25
- # each configuration class can contain nested BaseConfigurations
26
- @configuration_map = {}
27
- traverse_config(hsh, keys)
14
+ def to_hash
15
+ hsh = {}
16
+ instance_variables.each do |iv|
17
+ # strip the '@' to get the key
18
+ key = iv.to_s[1..]
19
+ hsh[key] = send(key.to_sym)
20
+ end
21
+ hsh
28
22
  end
29
23
 
30
24
  def assign_value_to_path_array dot_path_array, value
@@ -39,65 +33,6 @@ module Contrast
39
33
  end
40
34
  nil
41
35
  end
42
-
43
- def nil?
44
- @configuration_map.empty?
45
- end
46
-
47
- private
48
-
49
- # Traverse the given entity to build out the configuration graph.
50
- #
51
- # The values will be either a hash, indicating internal nodes to
52
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
53
- # leaf node.
54
- #
55
- # The spec_keys are the Contrast defined keys used to access a given
56
- # configuration. Each child of this class maintains its own set of keys,
57
- # as well as Objects to which those keys map.
58
- def traverse_config values, spec_keys
59
- internal_nodes = values.cs__respond_to?(:has_key?)
60
- spec_keys.each_pair do |spec_key, spec_value|
61
- user_provided_value = internal_nodes ? value_from_key_config(spec_key, values) : EMPTY_VALUE
62
- define_methods(spec_key, spec_value, user_provided_value)
63
- end
64
- end
65
-
66
- def define_methods spec_key, spec_value, user_provided_value
67
- str_key = spec_key.to_s
68
- assign_config_value(str_key, spec_value, user_provided_value)
69
- define_getter(str_key)
70
- define_setter(str_key)
71
- end
72
-
73
- def assign_config_value str_key, spec_value, user_provided_value
74
- @configuration_map[str_key] = if spec_value.is_a?(Class) && spec_value <= Contrast::Config::BaseConfiguration
75
- spec_value.new(user_provided_value)
76
- elsif user_provided_value == EMPTY_VALUE
77
- spec_value
78
- else
79
- user_provided_value
80
- end
81
- end
82
-
83
- def value_from_key_config key, config_hash
84
- return config_hash[key] if config_hash.key?(key)
85
- return config_hash.fetch(key.to_sym, EMPTY_VALUE) if key.is_a?(String)
86
-
87
- config_hash.fetch(key.to_s, EMPTY_VALUE)
88
- end
89
-
90
- def define_getter str_key
91
- define_singleton_method str_key.to_sym do
92
- @configuration_map[str_key] == EMPTY_VALUE ? nil : @configuration_map[str_key]
93
- end
94
- end
95
-
96
- def define_setter str_key
97
- define_singleton_method "#{ str_key }=".to_sym do |new_value|
98
- @configuration_map[str_key] = new_value
99
- end
100
- end
101
36
  end
102
37
  end
103
38
  end
@@ -4,82 +4,29 @@
4
4
  module Contrast
5
5
  module Config
6
6
  # Certificate Configuration
7
- class CertificationConfiguration < BaseConfiguration
7
+ class CertificationConfiguration
8
+ include Contrast::Config::BaseConfiguration
9
+
8
10
  # @return [String] path to CA Cert file
9
- attr_reader :ca_file
11
+ attr_accessor :ca_file
10
12
  # @return [String] path to Certification file
11
- attr_reader :cert_file
13
+ attr_accessor :cert_file
12
14
  # @return [String] path to Certification Key file
13
- attr_reader :key_file
15
+ attr_accessor :key_file
16
+ attr_writer :enable
14
17
 
15
18
  def initialize hsh = {}
16
- @enable = traverse_config(hsh, :enable)
17
- @ca_file = traverse_config(hsh, :ca_file)
18
- @cert_file = traverse_config(hsh, :cert_file)
19
- @key_file = traverse_config(hsh, :key_file)
20
- @configuration_map = {}
21
- build_configuration_map
22
- end
23
-
24
- # GETTERS
25
-
26
- # @return [Boolean]
27
- def enable
28
- return false if @enable.nil?
29
-
30
- @enable
31
- end
32
-
33
- # SETTERS
34
-
35
- def enable= value
36
- self['enable'] = value
37
- end
38
-
39
- def ca_file= value
40
- self['ca_file'] = value
41
- end
19
+ return unless hsh
42
20
 
43
- def cert_file= value
44
- self['cert_file'] = value
21
+ @enable = hsh[:enable]
22
+ @ca_file = hsh[:ca_file]
23
+ @cert_file = hsh[:cert_file]
24
+ @key_file = hsh[:key_file]
45
25
  end
46
26
 
47
- def key_file= value
48
- self['key_file'] = value
49
- end
50
-
51
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
52
-
53
- def []= key, value
54
- instance_variable_set("@#{ key }".to_sym, value)
55
- @configuration_map[key] = value
56
- end
57
-
58
- def [] key
59
- send(key.to_sym)
60
- end
61
-
62
- # Traverse the given entity to build out the configuration graph.
63
- #
64
- # The values will be either a hash, indicating internal nodes to
65
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
66
- # leaf node.
67
- #
68
- # The spec_key are the Contrast defined keys based on the instance variables of
69
- # a given configuration.
70
- def traverse_config values, spec_key
71
- internal_nodes = values.cs__respond_to?(:has_key?)
72
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
73
- val == EMPTY_VALUE ? nil : val
74
- end
75
-
76
- def build_configuration_map
77
- instance_variables.each do |key|
78
- str_key = key.to_s.tr('@', '')
79
- next if str_key == 'configuration_map'
80
-
81
- @configuration_map[str_key] = send(str_key.to_sym)
82
- end
27
+ # @return [Boolean, false]
28
+ def enable
29
+ @enable.nil? ? false : @enable
83
30
  end
84
31
  end
85
32
  end
@@ -3,72 +3,28 @@
3
3
 
4
4
  module Contrast
5
5
  module Config
6
- # Common Configuration settings. Those in this section pertain to the
7
- # exception handling in Ruby, allowing for the override of Response Code
8
- # and Message when Security Exceptions are raised.
9
- class ExceptionConfiguration < BaseConfiguration
6
+ # Common Configuration settings. Those in this section pertain to the exception handling in Ruby, allowing for the
7
+ # override of Response Code and Message when Security Exceptions are raised.
8
+ class ExceptionConfiguration
9
+ include Contrast::Config::BaseConfiguration
10
+
10
11
  # @return [Integer] the HTTP status code override
11
- attr_reader :override_status
12
+ attr_accessor :override_status
12
13
  # @return [String] the message text override
13
- attr_reader :override_message
14
+ attr_accessor :override_message
15
+ attr_writer :capture
14
16
 
15
17
  def initialize hsh = {}
16
- @capture = traverse_config(hsh, :capture)
17
- @override_status = traverse_config(hsh, :override_status)
18
- @override_message = traverse_config(hsh, :override_message)
19
- @configuration_map = {}
20
- build_configuration_map
21
- end
22
-
23
- # @return [Boolean] default: false
24
- def capture
25
- @capture.nil? ? false : @capture
26
- end
27
-
28
- def capture= value
29
- self['capture'] = value
30
- end
31
-
32
- def override_status= value
33
- self['override_status'] = value
34
- end
18
+ return unless hsh
35
19
 
36
- def override_message= value
37
- self['override_message'] = value
20
+ @capture = hsh[:capture]
21
+ @override_status = hsh[:override_status]
22
+ @override_message = hsh[:override_message]
38
23
  end
39
24
 
40
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
41
-
42
- def []= key, value
43
- instance_variable_set("@#{ key }".to_sym, value)
44
- @configuration_map[key] = value
45
- end
46
-
47
- def [] key
48
- send(key.to_sym)
49
- end
50
-
51
- # Traverse the given entity to build out the configuration graph.
52
- #
53
- # The values will be either a hash, indicating internal nodes to
54
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
55
- # leaf node.
56
- #
57
- # The spec_key are the Contrast defined keys based on the instance variables of
58
- # a given configuration.
59
- def traverse_config values, spec_key
60
- internal_nodes = values.cs__respond_to?(:has_key?)
61
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
62
- val == EMPTY_VALUE ? nil : val
63
- end
64
-
65
- def build_configuration_map
66
- instance_variables.each do |key|
67
- str_key = key.to_s.tr('@', '')
68
- next if str_key == 'configuration_map'
69
-
70
- @configuration_map[str_key] = send(str_key.to_sym)
71
- end
25
+ # @return [Boolean, false]
26
+ def capture
27
+ !!@capture
72
28
  end
73
29
  end
74
30
  end
@@ -3,27 +3,31 @@
3
3
 
4
4
  module Contrast
5
5
  module Config
6
- # Common Configuration settings. Those in this section pertain to the
7
- # Heap Dump collection functionality of the Agent.
8
- class HeapDumpConfiguration < BaseConfiguration
6
+ # Common Configuration settings. Those in this section pertain to the Heap Dump collection functionality of the
7
+ # Agent.
8
+ class HeapDumpConfiguration
9
+ include Contrast::Config::BaseConfiguration
10
+
9
11
  DEFAULT_PATH = 'contrast_heap_dumps' # saved
10
12
  DEFAULT_MS = 10_000
11
13
  DEFAULT_COUNT = 5
12
14
 
15
+ attr_writer :enable, :path, :delay_ms, :window_ms, :count, :clean
16
+
13
17
  def initialize hsh = {}
14
- @enable = traverse_config(hsh, :enable)
15
- @path = traverse_config(hsh, :path)
16
- @delay_ms = traverse_config(hsh, :delay_ms)
17
- @window_ms = traverse_config(hsh, :window_ms)
18
- @count = traverse_config(hsh, :count)
19
- @clean = traverse_config(hsh, :clean)
20
- @configuration_map = {}
21
- build_configuration_map
18
+ return unless hsh
19
+
20
+ @enable = hsh[:enable]
21
+ @path = hsh[:path]
22
+ @delay_ms = hsh[:delay_ms]
23
+ @window_ms = hsh[:window_ms]
24
+ @count = hsh[:count]
25
+ @clean = hsh[:clean]
22
26
  end
23
27
 
24
- # @return [Boolean, false] should dumps be taken
28
+ # @return [Boolean, Contrast::Utils::ObjectShare::FALSE] should dumps be taken
25
29
  def enable
26
- !!@enable
30
+ @enable.nil? ? Contrast::Utils::ObjectShare::FALSE : @enable
27
31
  end
28
32
 
29
33
  # @return [String, DEFAULT_PATH] dir to which dumps should be
@@ -46,67 +50,9 @@ module Contrast
46
50
  @count ||= DEFAULT_COUNT
47
51
  end
48
52
 
49
- # @return [Boolean, false] remove temporary objects or not
53
+ # @return [Boolean, Contrast::Utils::ObjectShare::FALSE] remove temporary objects or not
50
54
  def clean
51
- !!@clean
52
- end
53
-
54
- def enable= value
55
- self['enable'] = value
56
- end
57
-
58
- def path= value
59
- self['path'] = value
60
- end
61
-
62
- def delay_ms= value
63
- self['delay_ms'] = value
64
- end
65
-
66
- def window_ms= value
67
- self['window_ms'] = value
68
- end
69
-
70
- def count= value
71
- self['count'] = value
72
- end
73
-
74
- def clean= value
75
- self['clean'] = value
76
- end
77
-
78
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
79
-
80
- def []= key, value
81
- instance_variable_set("@#{ key }".to_sym, value)
82
- @configuration_map[key] = value
83
- end
84
-
85
- def [] key
86
- send(key.to_sym)
87
- end
88
-
89
- # Traverse the given entity to build out the configuration graph.
90
- #
91
- # The values will be either a hash, indicating internal nodes to
92
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
93
- # leaf node.
94
- #
95
- # The spec_key are the Contrast defined keys based on the instance variables of
96
- # a given configuration.
97
- def traverse_config values, spec_key
98
- internal_nodes = values.cs__respond_to?(:has_key?)
99
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
100
- val == EMPTY_VALUE ? nil : val
101
- end
102
-
103
- def build_configuration_map
104
- instance_variables.each do |key|
105
- str_key = key.to_s.tr('@', '')
106
- next if str_key == 'configuration_map'
107
-
108
- @configuration_map[str_key] = send(str_key.to_sym)
109
- end
55
+ @clean.nil? ? Contrast::Utils::ObjectShare::FALSE : @clean
110
56
  end
111
57
  end
112
58
  end
@@ -3,18 +3,20 @@
3
3
 
4
4
  module Contrast
5
5
  module Config
6
- # Common Configuration settings. Those in this section pertain to the
7
- # inventory functionality of the Agent.
8
- class InventoryConfiguration < BaseConfiguration
6
+ # Common Configuration settings. Those in this section pertain to the inventory functionality of the Agent.
7
+ class InventoryConfiguration
8
+ include Contrast::Config::BaseConfiguration
9
+
9
10
  # @return [Array, nil] tags
10
- attr_reader :tags
11
+ attr_accessor :tags
12
+ attr_writer :enable, :analyze_libraries
11
13
 
12
14
  def initialize hsh = {}
13
- @enable = traverse_config(hsh, :enable)
14
- @analyze_libraries = traverse_config(hsh, :analyze_libraries)
15
- @tags = traverse_config(hsh, :tags)
16
- @configuration_map = {}
17
- build_configuration_map
15
+ return unless hsh
16
+
17
+ @enable = hsh[:enable]
18
+ @analyze_libraries = hsh[:analyze_libraries]
19
+ @tags = hsh[:tags]
18
20
  end
19
21
 
20
22
  # @return [Boolean, true]
@@ -26,52 +28,6 @@ module Contrast
26
28
  def analyze_libraries
27
29
  @analyze_libraries.nil? ? true : @analyze_libraries
28
30
  end
29
-
30
- def enable= value
31
- self['enable'] = value
32
- end
33
-
34
- def analyze_libraries= value
35
- self['analyze_libraries'] = value
36
- end
37
-
38
- def tags= value
39
- self['tags'] = value
40
- end
41
-
42
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
43
-
44
- def []= key, value
45
- instance_variable_set("@#{ key }".to_sym, value)
46
- @configuration_map[key] = value
47
- end
48
-
49
- def [] key
50
- send(key.to_sym)
51
- end
52
-
53
- # Traverse the given entity to build out the configuration graph.
54
- #
55
- # The values will be either a hash, indicating internal nodes to
56
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
57
- # leaf node.
58
- #
59
- # The spec_key are the Contrast defined keys based on the instance variables of
60
- # a given configuration.
61
- def traverse_config values, spec_key
62
- internal_nodes = values.cs__respond_to?(:has_key?)
63
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
64
- val == EMPTY_VALUE ? nil : val
65
- end
66
-
67
- def build_configuration_map
68
- instance_variables.each do |key|
69
- str_key = key.to_s.tr('@', '')
70
- next if str_key == 'configuration_map'
71
-
72
- @configuration_map[str_key] = send(str_key.to_sym)
73
- end
74
- end
75
31
  end
76
32
  end
77
33
  end
@@ -3,9 +3,10 @@
3
3
 
4
4
  module Contrast
5
5
  module Config
6
- # Common Configuration settings. Those in this section pertain to the
7
- # logging in the Agent.
8
- class LoggerConfiguration < BaseConfiguration
6
+ # Common Configuration settings. Those in this section pertain to the logging in the Agent.
7
+ class LoggerConfiguration
8
+ include Contrast::Config::BaseConfiguration
9
+
9
10
  # @return [String, nil]
10
11
  attr_accessor :path
11
12
  # @return [String, nil]
@@ -14,45 +15,11 @@ module Contrast
14
15
  attr_accessor :progname
15
16
 
16
17
  def initialize hsh = {}
17
- @path = traverse_config(hsh, :path)
18
- @level = traverse_config(hsh, :level)
19
- @progname = traverse_config(hsh, :progname)
20
- @configuration_map = {}
21
- build_configuration_map
22
- end
23
-
24
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
25
-
26
- def []= key, value
27
- instance_variable_set("@#{ key }".to_sym, value)
28
- @configuration_map[key] = value
29
- end
30
-
31
- def [] key
32
- send(key.to_sym)
33
- end
34
-
35
- # Traverse the given entity to build out the configuration graph.
36
- #
37
- # The values will be either a hash, indicating internal nodes to
38
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
39
- # leaf node.
40
- #
41
- # The spec_key are the Contrast defined keys based on the instance variables of
42
- # a given configuration.
43
- def traverse_config values, spec_key
44
- internal_nodes = values.cs__respond_to?(:has_key?)
45
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
46
- val == EMPTY_VALUE ? nil : val
47
- end
48
-
49
- def build_configuration_map
50
- instance_variables.each do |key|
51
- str_key = key.to_s.tr('@', '')
52
- next if str_key == 'configuration_map'
18
+ return unless hsh
53
19
 
54
- @configuration_map[str_key] = send(str_key.to_sym)
55
- end
20
+ @path = hsh[:path]
21
+ @level = hsh[:level]
22
+ @progname = hsh[:progname]
56
23
  end
57
24
  end
58
25
  end
@@ -3,17 +3,30 @@
3
3
 
4
4
  module Contrast
5
5
  module Config
6
- # Common Configuration settings. Those in this section pertain to the
7
- # protect functionality of the Agent.
8
- class ProtectConfiguration < BaseConfiguration
9
- KEYS = {
10
- exceptions: Contrast::Config::ExceptionConfiguration,
11
- rules: Contrast::Config::ProtectRulesConfiguration,
12
- enable: EMPTY_VALUE
13
- }.cs__freeze
6
+ # Common Configuration settings. Those in this section pertain to the protect functionality of the Agent.
7
+ class ProtectConfiguration
8
+ include Contrast::Config::BaseConfiguration
14
9
 
15
- def initialize hsh
16
- super(hsh, KEYS)
10
+ # @return [Boolean, nil]
11
+ attr_accessor :enable
12
+ attr_writer :exceptions, :rules
13
+
14
+ def initialize hsh = {}
15
+ return unless hsh
16
+
17
+ @exceptions = Contrast::Config::ExceptionConfiguration.new(hsh[:exceptions])
18
+ @rules = Contrast::Config::ProtectRulesConfiguration.new(hsh[:rules])
19
+ @enable = hsh[:enable]
20
+ end
21
+
22
+ # @return [Contrast::Config::ExceptionConfiguration]
23
+ def exceptions
24
+ @exceptions ||= Contrast::Config::ExceptionConfiguration.new
25
+ end
26
+
27
+ # @return [Contrast::Config::ProtectRulesConfiguration]
28
+ def rules
29
+ @rules ||= Contrast::Config::ProtectRulesConfiguration.new
17
30
  end
18
31
  end
19
32
  end
@@ -5,18 +5,31 @@ require 'set'
5
5
 
6
6
  module Contrast
7
7
  module Config
8
- # Common Configuration settings. Those in this section pertain to the
9
- # rule mode of a single protect rule in the Agent.
10
- class ProtectRuleConfiguration < BaseConfiguration
11
- attr_accessor :enable, :mode, :disable_system_commands, :detect_custom_code_accessing_system_files
8
+ # Common Configuration settings. Those in this section pertain to the rule mode of a single protect rule in the
9
+ # Agent.
10
+ class ProtectRuleConfiguration
11
+ include Contrast::Config::BaseConfiguration
12
+
13
+ # @return [Boolean, nil]
14
+ attr_accessor :enable
15
+ # @return [String, nil]
16
+ attr_accessor :mode
17
+ # @return [Boolean, nil]
18
+ attr_accessor :disable_system_commands
19
+ attr_writer :detect_custom_code_accessing_system_files
12
20
 
13
21
  def initialize hsh = {}
14
- @enable = traverse_config(hsh, :enable)
15
- @mode = traverse_config(hsh, :mode)
16
- @disable_system_commands = traverse_config(hsh, :disable_system_commands)
17
- @detect_custom_code_accessing_system_files = traverse_config(hsh, :detect_custom_code_accessing_system_files)
18
- @configuration_map = {}
19
- build_configuration_map
22
+ return unless hsh
23
+
24
+ @enable = hsh[:enable]
25
+ @mode = hsh[:mode]
26
+ @disable_system_commands = hsh[:disable_system_commands]
27
+ @detect_custom_code_accessing_system_files = hsh[:detect_custom_code_accessing_system_files]
28
+ end
29
+
30
+ # @return [Boolean, true]
31
+ def detect_custom_code_accessing_system_files
32
+ @detect_custom_code_accessing_system_files.nil? ? true : @detect_custom_code_accessing_system_files
20
33
  end
21
34
 
22
35
  # To convert the user input mode from config to a standard format used by TS & SR, we need to convert the given
@@ -40,33 +53,6 @@ module Contrast
40
53
  Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
41
54
  end
42
55
  end
43
-
44
- def [] key
45
- send(key.to_sym)
46
- end
47
-
48
- # Traverse the given entity to build out the configuration graph.
49
- #
50
- # The values will be either a hash, indicating internal nodes to
51
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
52
- # leaf node.
53
- #
54
- # The spec_key are the Contrast defined keys based on the instance variables of
55
- # a given configuration.
56
- def traverse_config values, spec_key
57
- internal_nodes = values.cs__respond_to?(:has_key?)
58
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
59
- val == EMPTY_VALUE ? nil : val
60
- end
61
-
62
- def build_configuration_map
63
- instance_variables.each do |key|
64
- str_key = key.to_s.tr('@', '')
65
- next if str_key == 'configuration_map'
66
-
67
- @configuration_map[str_key] = send(str_key.to_sym)
68
- end
69
- end
70
56
  end
71
57
  end
72
58
  end