contrast-agent 6.0.0 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) 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_basic_object/cs__assess_basic_object.c +5 -1
  6. data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
  7. data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
  8. data/ext/cs__assess_string/cs__assess_string.c +8 -0
  9. data/ext/cs__assess_test/cs__assess_test.h +9 -0
  10. data/ext/cs__assess_test/cs__assess_tests.c +22 -0
  11. data/ext/cs__assess_test/extconf.rb +5 -0
  12. data/ext/cs__common/cs__common.c +101 -0
  13. data/ext/cs__common/cs__common.h +29 -5
  14. data/ext/cs__contrast_patch/cs__contrast_patch.c +1 -1
  15. data/ext/cs__tests/cs__tests.c +12 -0
  16. data/ext/cs__tests/cs__tests.h +3 -0
  17. data/ext/cs__tests/extconf.rb +5 -0
  18. data/ext/extconf_common.rb +1 -1
  19. data/lib/contrast/agent/assess/contrast_object.rb +16 -16
  20. data/lib/contrast/agent/assess/events/source_event.rb +17 -19
  21. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -2
  22. data/lib/contrast/agent/assess/policy/policy.rb +9 -10
  23. data/lib/contrast/agent/assess/policy/policy_node.rb +9 -10
  24. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
  25. data/lib/contrast/agent/assess/policy/propagation_method.rb +3 -3
  26. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
  27. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  28. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +2 -1
  29. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  30. data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
  31. data/lib/contrast/agent/assess/policy/propagator/split.rb +17 -21
  32. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  33. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  34. data/lib/contrast/agent/assess/policy/trigger_method.rb +10 -18
  35. data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
  36. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  37. data/lib/contrast/agent/assess/property/evented.rb +2 -2
  38. data/lib/contrast/agent/assess/property/tagged.rb +2 -2
  39. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
  40. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
  41. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
  42. data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
  43. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
  44. data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
  45. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
  46. data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
  47. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
  48. data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
  49. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
  50. data/lib/contrast/agent/assess/tag.rb +13 -14
  51. data/lib/contrast/agent/at_exit_hook.rb +12 -1
  52. data/lib/contrast/agent/inventory/database_config.rb +22 -7
  53. data/lib/contrast/agent/middleware.rb +9 -6
  54. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
  55. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
  56. data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
  57. data/lib/contrast/agent/patching/policy/patch.rb +20 -19
  58. data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
  59. data/lib/contrast/agent/patching/policy/patcher.rb +1 -1
  60. data/lib/contrast/agent/patching/policy/policy.rb +13 -15
  61. data/lib/contrast/agent/patching/policy/policy_node.rb +19 -21
  62. data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
  63. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +126 -122
  64. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  65. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +1 -1
  66. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  67. data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
  68. data/lib/contrast/agent/protect/rule/base.rb +30 -18
  69. data/lib/contrast/agent/protect/rule/base_service.rb +31 -14
  70. data/lib/contrast/agent/protect/rule/cmd_injection.rb +16 -9
  71. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +3 -3
  72. data/lib/contrast/agent/protect/rule/default_scanner.rb +2 -1
  73. data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
  74. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +74 -74
  75. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +71 -53
  76. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +3 -3
  77. data/lib/contrast/agent/protect/rule/no_sqli.rb +15 -16
  78. data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
  79. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -2
  80. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -1
  81. data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
  82. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +61 -61
  83. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +29 -29
  84. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +32 -32
  85. data/lib/contrast/agent/protect/rule/xss.rb +17 -0
  86. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
  87. data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
  88. data/lib/contrast/agent/reaction_processor.rb +1 -1
  89. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +36 -36
  90. data/lib/contrast/agent/reporting/masker/masker.rb +18 -21
  91. data/lib/contrast/agent/reporting/masker/masker_utils.rb +10 -6
  92. data/lib/contrast/agent/reporting/reporter.rb +11 -16
  93. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
  94. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +6 -2
  95. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
  96. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
  97. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
  98. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
  99. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
  100. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
  101. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
  102. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +6 -2
  103. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
  104. data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
  105. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +15 -11
  106. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
  107. data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
  108. data/lib/contrast/agent/reporting/reporting_events/finding.rb +9 -3
  109. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
  110. data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
  111. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
  112. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +7 -3
  113. data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
  114. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
  115. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +6 -10
  116. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
  117. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
  118. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
  119. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
  120. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
  121. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  122. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
  123. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +15 -10
  124. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -67
  125. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
  126. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +9 -6
  127. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +17 -17
  128. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +47 -32
  129. data/lib/contrast/agent/reporting/settings/application_settings.rb +1 -1
  130. data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
  131. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +3 -3
  132. data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
  133. data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
  134. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
  135. data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
  136. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +2 -2
  137. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +2 -2
  138. data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
  139. data/lib/contrast/agent/request.rb +5 -5
  140. data/lib/contrast/agent/request_context.rb +23 -19
  141. data/lib/contrast/agent/request_context_extend.rb +11 -24
  142. data/lib/contrast/agent/request_handler.rb +4 -4
  143. data/lib/contrast/agent/response.rb +2 -0
  144. data/lib/contrast/agent/rule_set.rb +2 -2
  145. data/lib/contrast/agent/scope.rb +1 -1
  146. data/lib/contrast/agent/service_heartbeat.rb +6 -48
  147. data/lib/contrast/agent/static_analysis.rb +1 -1
  148. data/lib/contrast/agent/telemetry/base.rb +155 -0
  149. data/lib/contrast/agent/telemetry/events/event.rb +35 -0
  150. data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
  151. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +44 -36
  152. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +29 -21
  153. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +91 -73
  154. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +62 -44
  155. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +50 -33
  156. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
  157. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
  158. data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
  159. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
  160. data/lib/contrast/agent/thread_watcher.rb +52 -68
  161. data/lib/contrast/agent/version.rb +1 -1
  162. data/lib/contrast/agent/worker_thread.rb +8 -0
  163. data/lib/contrast/agent.rb +1 -3
  164. data/lib/contrast/api/communication/messaging_queue.rb +29 -12
  165. data/lib/contrast/api/communication/response_processor.rb +7 -10
  166. data/lib/contrast/api/communication/service_lifecycle.rb +1 -1
  167. data/lib/contrast/api/communication/socket.rb +1 -1
  168. data/lib/contrast/api/communication/socket_client.rb +1 -1
  169. data/lib/contrast/api/communication/speedracer.rb +3 -3
  170. data/lib/contrast/api/decorators/activity.rb +33 -0
  171. data/lib/contrast/api/decorators/agent_startup.rb +10 -9
  172. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  173. data/lib/contrast/api/decorators/application_startup.rb +4 -4
  174. data/lib/contrast/api/decorators/http_request.rb +1 -1
  175. data/lib/contrast/api/decorators/response_type.rb +4 -17
  176. data/lib/contrast/components/agent.rb +1 -1
  177. data/lib/contrast/components/base.rb +1 -1
  178. data/lib/contrast/components/config.rb +19 -28
  179. data/lib/contrast/components/contrast_service.rb +13 -1
  180. data/lib/contrast/components/sampling.rb +1 -1
  181. data/lib/contrast/components/settings.rb +58 -24
  182. data/lib/contrast/config/agent_configuration.rb +21 -11
  183. data/lib/contrast/config/api_configuration.rb +12 -8
  184. data/lib/contrast/config/api_proxy_configuration.rb +7 -3
  185. data/lib/contrast/config/application_configuration.rb +15 -11
  186. data/lib/contrast/config/assess_configuration.rb +13 -9
  187. data/lib/contrast/config/assess_rules_configuration.rb +6 -2
  188. data/lib/contrast/config/base_configuration.rb +3 -35
  189. data/lib/contrast/config/certification_configuration.rb +9 -5
  190. data/lib/contrast/config/exception_configuration.rb +10 -7
  191. data/lib/contrast/config/heap_dump_configuration.rb +13 -9
  192. data/lib/contrast/config/inventory_configuration.rb +9 -6
  193. data/lib/contrast/config/logger_configuration.rb +9 -6
  194. data/lib/contrast/config/protect_configuration.rb +9 -6
  195. data/lib/contrast/config/protect_rule_configuration.rb +12 -8
  196. data/lib/contrast/config/protect_rules_configuration.rb +19 -18
  197. data/lib/contrast/config/request_audit_configuration.rb +10 -7
  198. data/lib/contrast/config/root_configuration.rb +29 -12
  199. data/lib/contrast/config/ruby_configuration.rb +14 -11
  200. data/lib/contrast/config/sampling_configuration.rb +11 -8
  201. data/lib/contrast/config/server_configuration.rb +13 -9
  202. data/lib/contrast/config/service_configuration.rb +14 -11
  203. data/lib/contrast/configuration.rb +23 -14
  204. data/lib/contrast/extension/assess/array.rb +1 -1
  205. data/lib/contrast/extension/assess/erb.rb +1 -1
  206. data/lib/contrast/extension/assess/marshal.rb +1 -1
  207. data/lib/contrast/extension/assess/string.rb +1 -1
  208. data/lib/contrast/extension/extension.rb +2 -2
  209. data/lib/contrast/framework/base_support.rb +8 -8
  210. data/lib/contrast/framework/grape/support.rb +3 -3
  211. data/lib/contrast/framework/manager.rb +5 -5
  212. data/lib/contrast/framework/manager_extend.rb +1 -1
  213. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  214. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
  215. data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
  216. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  217. data/lib/contrast/framework/rails/patch/support.rb +14 -46
  218. data/lib/contrast/framework/rails/support.rb +2 -2
  219. data/lib/contrast/framework/sinatra/support.rb +1 -1
  220. data/lib/contrast/logger/aliased_logging.rb +94 -0
  221. data/lib/contrast/logger/application.rb +0 -4
  222. data/lib/contrast/logger/cef_log.rb +14 -14
  223. data/lib/contrast/logger/format.rb +1 -1
  224. data/lib/contrast/logger/log.rb +8 -8
  225. data/lib/contrast/tasks/config.rb +30 -21
  226. data/lib/contrast/tasks/service.rb +2 -2
  227. data/lib/contrast/utils/assess/tracking_util.rb +4 -4
  228. data/lib/contrast/utils/class_util.rb +6 -10
  229. data/lib/contrast/utils/findings.rb +3 -3
  230. data/lib/contrast/utils/hash_digest.rb +6 -7
  231. data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
  232. data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
  233. data/lib/contrast/utils/log_utils.rb +6 -4
  234. data/lib/contrast/utils/lru_cache.rb +1 -1
  235. data/lib/contrast/utils/metrics_hash.rb +1 -1
  236. data/lib/contrast/utils/middleware_utils.rb +6 -6
  237. data/lib/contrast/utils/net_http_base.rb +4 -4
  238. data/lib/contrast/utils/object_share.rb +1 -1
  239. data/lib/contrast/utils/os.rb +1 -1
  240. data/lib/contrast/utils/patching/policy/patch_utils.rb +2 -2
  241. data/lib/contrast/utils/request_utils.rb +2 -2
  242. data/lib/contrast/utils/sha256_builder.rb +4 -4
  243. data/lib/contrast/utils/stack_trace_utils.rb +31 -13
  244. data/lib/contrast/utils/telemetry.rb +22 -7
  245. data/lib/contrast/utils/telemetry_client.rb +27 -15
  246. data/lib/contrast/utils/telemetry_hash.rb +41 -0
  247. data/lib/contrast/utils/telemetry_identifier.rb +18 -3
  248. data/lib/contrast/utils/timer.rb +1 -1
  249. data/lib/contrast.rb +9 -0
  250. data/resources/assess/policy.json +1 -1
  251. data/ruby-agent.gemspec +1 -1
  252. data/service_executables/VERSION +1 -1
  253. data/service_executables/linux/contrast-service +0 -0
  254. data/service_executables/mac/contrast-service +0 -0
  255. metadata +41 -16
  256. data/lib/contrast/agent/telemetry/events/metric_telemetry_event.rb +0 -26
  257. data/lib/contrast/agent/telemetry/events/startup_metrics_telemetry_event.rb +0 -121
  258. data/lib/contrast/agent/telemetry/events/telemetry_event.rb +0 -33
  259. data/lib/contrast/agent/telemetry/telemetry.rb +0 -150
  260. data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -33,7 +33,7 @@ module Contrast
33
33
  # need to check
34
34
  # @return [Boolean] if this method specifically was prepended
35
35
  def prepended_method? mod, method_policy
36
- target_module = determine_target_class mod, method_policy.instance_method
36
+ target_module = determine_target_class(mod, method_policy.instance_method)
37
37
  ancestors = target_module.ancestors
38
38
  return false unless prepended?(target_module, ancestors)
39
39
 
@@ -60,13 +60,13 @@ module Contrast
60
60
  # Only treat object like a string if it actually is a string+ some subclasses of String override string
61
61
  # methods we depend on
62
62
  if object.cs__class == String
63
- return @string_cache[object] if @string_cache.key? object
63
+ return @string_cache[object] if @string_cache.key?(object)
64
64
 
65
65
  @string_cache[object] = to_cached_string(object) || object.dup
66
66
  else
67
- return @lru_cache[object.__id__] if @lru_cache.key? object.__id__
67
+ return @lru_cache[object.__id__] if @lru_cache.key?(object.__id__)
68
68
 
69
- @lru_cache[object.__id__] = convert_object object
69
+ @lru_cache[object.__id__] = convert_object(object)
70
70
  end
71
71
  end
72
72
 
@@ -86,13 +86,9 @@ module Contrast
86
86
  end
87
87
  end
88
88
 
89
- # The method const_defined? can cause autoload, which is bad for us. The method autoload? doesn't traverse
90
- # namespaces. This method lets us provide a constant, as a String, and parse it to determine if it has been
91
- # truly truly defined, meaning it existed before this method was invoked, not as a result of it.
89
+ # The method Module.const_defined? can raise an exception if the constant is poorly named. As such, we need to
90
+ # handle the case where that exception is raised.
92
91
  #
93
- # TODO: RUBY-1326
94
- # This is required to handle a bug in Ruby prior to 2.7.0. When we drop support for 2.6.X, we should remove
95
- # this code. https://bugs.ruby-lang.org/issues/10741
96
92
  # @param name [String] the name of the constant to look up
97
93
  # @return [Boolean]
98
94
  def truly_defined? name
@@ -34,7 +34,7 @@ module Contrast
34
34
  # @param ret [Object] the Return of the invoked method
35
35
  # @param args [Array<Object>] the Arguments with which the method was invoked
36
36
  def collect_finding trigger_node, source, object, ret, *args
37
- push trigger_node, source, object, ret, args
37
+ push(trigger_node, source, object, ret, args)
38
38
  logger.trace('Finding collected', node_id: trigger_node.id,
39
39
  source_id: source.__id__,
40
40
  rule: trigger_node.rule_id)
@@ -52,11 +52,11 @@ module Contrast
52
52
 
53
53
  while @_collection.any?
54
54
  finding = @_collection.pop
55
- Contrast::Agent::Assess::Policy::TriggerMethod.build_finding finding[:trigger_node],
55
+ Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(finding[:trigger_node],
56
56
  finding[:source],
57
57
  finding[:object],
58
58
  finding[:ret],
59
- finding[:args]
59
+ finding[:args])
60
60
  end
61
61
  true
62
62
  end
@@ -15,8 +15,8 @@ module Contrast
15
15
  class HashDigest < Digest::Class
16
16
  include Digest::Instance
17
17
  extend Contrast::Utils::HashDigestExtend
18
-
19
18
  CONTENT_LENGTH_HEADER = 'Content-Length'
19
+ CHARS = %w[a b c d e f g].cs__freeze
20
20
  CRYPTO_RULES = %w[crypto-bad-ciphers crypto-bad-mac].cs__freeze
21
21
  CONFIG_PATH_KEY = 'path'
22
22
  CONFIG_SESSION_ID_KEY = 'sessionId'
@@ -24,6 +24,11 @@ module Contrast
24
24
  CLASS_CONSTANT_NAME_KEY = 'name'
25
25
  CLASS_LINE_NO_KEY = 'lineNo'
26
26
 
27
+ def initialize
28
+ super
29
+ @crc32 = 0
30
+ end
31
+
27
32
  # Update to CRC checksum the finding route and verb if finding route
28
33
  # [Contrast::Api::Dtm::RouteCoverage] is available else update the passed
29
34
  # request or Contrast::REQUEST_TRACKER.current.request uri and used request
@@ -77,7 +82,6 @@ module Contrast
77
82
  end
78
83
  end
79
84
 
80
- CHARS = %w[a b c d e f g].cs__freeze
81
85
  # This method converts and integer value for length into a string value
82
86
  # that we can hash on, based on the logarithmic value of the length, and
83
87
  # updates the current hash with that value.
@@ -86,11 +90,6 @@ module Contrast
86
90
  update(CHARS[Math.log10(chr.to_s.length).to_i] || CHARS[-1])
87
91
  end
88
92
 
89
- def initialize
90
- super
91
- @crc32 = 0
92
- end
93
-
94
93
  # Converts given string to CRC checksum. CRC32 checksum ensures that If error
95
94
  # of a single bit occurs, the CRC checksum will fail, regardless of any other
96
95
  # property of the transmitted data, including its length. Called several times
@@ -13,7 +13,7 @@ module Contrast
13
13
  delay = control[:delay]
14
14
  clean = control[:clean]
15
15
 
16
- logger.info <<~WARNING
16
+ logger.info(<<~WARNING)
17
17
  *****************************************************
18
18
  ******** HEAP DUMP HAS BEEN ENABLED ********
19
19
  *** APPLICATION PROCESS WILL EXIT UPON COMPLETION ***
@@ -50,10 +50,10 @@ module Contrast
50
50
  new_preflight_message.data = "#{ rule_id },#{ hash_code }"
51
51
  new_preflight.messages << new_preflight_message
52
52
 
53
- ruby_finding = Contrast::Agent::Reporting::Finding.new rule_id
53
+ ruby_finding = Contrast::Agent::Reporting::Finding.new(rule_id)
54
54
  ruby_finding.hash_code = hash_code
55
55
  set_new_finding_properties(ruby_finding, user_provided_options, call_location)
56
- Contrast::Agent.reporter&.send_event_immediately(new_preflight)
56
+ Contrast::Agent.reporter&.send_event(new_preflight)
57
57
  Contrast::Agent::Reporting::ReportingStorage[hash_code] = ruby_finding
58
58
  end
59
59
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'socket'
5
5
  require 'contrast/agent/version'
6
+ require 'contrast/logger/aliased_logging'
6
7
 
7
8
  module Contrast
8
9
  module Utils
@@ -37,6 +38,7 @@ module Contrast
37
38
  logger.extend(Contrast::Logger::Application)
38
39
  logger.extend(Contrast::Logger::Request)
39
40
  logger.extend(Contrast::Logger::Time)
41
+ logger.extend(Contrast::Logger::AliasedLogging) if Contrast::Utils::Telemetry.exceptions_enabled?
40
42
  end
41
43
 
42
44
  # Determine the valid path to which to log, given the precedence of config > settings > default.
@@ -62,13 +64,13 @@ module Contrast
62
64
  # Log once when the path is invalid. We'll change to this path, so no
63
65
  # need to log again.
64
66
  if previous_path != DEFAULT_NAME
65
- $stdout.puts "[!] Unable to write to '#{ path }'. Writing to default log '#{ DEFAULT_NAME }' instead."
67
+ $stdout.puts("[!] Unable to write to '#{ path }'. Writing to default log '#{ DEFAULT_NAME }' instead.")
66
68
  end
67
69
  DEFAULT_NAME
68
70
  else
69
71
  # Log once when the path is invalid. We'll change to this path, so no
70
72
  # need to log again.
71
- $stdout.puts "[!] Unable to write to '#{ path }'. Writing to standard out instead."
73
+ $stdout.puts("[!] Unable to write to '#{ path }'. Writing to standard out instead.")
72
74
  STDOUT_STR
73
75
  end
74
76
  end
@@ -139,7 +141,7 @@ module Contrast
139
141
  end
140
142
  logger.progname = PROGNAME
141
143
  logger.level = level_const
142
- change_logger_formatter logger
144
+ change_logger_formatter(logger)
143
145
  logger
144
146
  end
145
147
 
@@ -181,7 +183,7 @@ module Contrast
181
183
  DEFAULT_METADATA
182
184
  end
183
185
  app_name = ::Contrast::APP_CONTEXT.app_name
184
- attach_request_and_sender_info message, sender_info
186
+ attach_request_and_sender_info(message, sender_info)
185
187
  message << "request=#{ context.request.url } "
186
188
  message << "requestMethod=#{ request_method } "
187
189
  message << "app=#{ app_name } "
@@ -6,7 +6,7 @@ module Contrast
6
6
  # A LRU(Least Recently Used) Cache store.
7
7
  class LRUCache
8
8
  def initialize capacity = 500
9
- raise StandardError 'Capacity must be bigger than 0' if capacity <= 0
9
+ raise(StandardError('Capacity must be bigger than 0')) if capacity <= 0
10
10
 
11
11
  @capacity = capacity
12
12
  @cache = {}
@@ -29,7 +29,7 @@ module Contrast
29
29
  value_val = value.dup
30
30
  key_val.strip! if key_val.cs__is_a?(String)
31
31
  value_val.strip! if value_val.cs__is_a?(String)
32
- return unless valid_pair? key_val, value_val
32
+ return unless valid_pair?(key_val, value_val)
33
33
 
34
34
  key_val.downcase!
35
35
  key_val.strip!
@@ -37,12 +37,12 @@ module Contrast
37
37
  def handle_exception exception
38
38
  if security_exception?(exception)
39
39
  exception_control = ::Contrast::AGENT.exception_control
40
- raise exception unless exception_control[:enable]
40
+ raise(exception) unless exception_control[:enable]
41
41
 
42
42
  [exception_control[:status], {}, [exception_control[:message]]]
43
43
  else
44
44
  logger.debug('Re-throwing original error', exception)
45
- raise exception
45
+ raise(exception)
46
46
  end
47
47
  end
48
48
 
@@ -66,11 +66,11 @@ module Contrast
66
66
  # if .telemetry file doesn't exist we create one and then show the disclaimer.
67
67
  # if the file already exists we do nothing.
68
68
  def telemetry_disclaimer
69
- return unless Contrast::Agent::Telemetry.enabled?
69
+ return unless Contrast::Agent::Telemetry::Base.enabled?
70
70
  return unless Contrast::Utils::Telemetry.create_telemetry_file
71
71
 
72
- logger.info Contrast::Utils::Telemetry.disclaimer
73
- $stdout.print Contrast::Utils::Telemetry.disclaimer
72
+ logger.info(Contrast::Utils::Telemetry.disclaimer)
73
+ $stdout.print(Contrast::Utils::Telemetry.disclaimer)
74
74
  true
75
75
  end
76
76
 
@@ -80,7 +80,7 @@ module Contrast
80
80
  end
81
81
  rescue Contrast::SecurityException => e
82
82
  logger.trace('Security Exception raised during application lifecycle to prevent an attack', e)
83
- raise e
83
+ raise(e)
84
84
  end
85
85
  end
86
86
  end
@@ -31,14 +31,14 @@ module Contrast
31
31
  return if addr.scheme != 'https' && !addr.host.to_s.include?('localhost') # TODO: RUBY-99999 allow http w/ localhost # rubocop:disable Layout/LineLength
32
32
 
33
33
  proxy_addr = URI(Contrast::API.proxy_url) if proxy_enabled?
34
- net_http_client = initialize_client addr, proxy_addr, use_proxy, use_custom_cert
34
+ net_http_client = initialize_client(addr, proxy_addr, use_proxy, use_custom_cert)
35
35
  return if net_http_client.nil?
36
36
 
37
37
  net_http_client.start
38
38
  return unless net_http_client.started?
39
39
 
40
40
  logger.debug("Starting #{ service_name } connection test")
41
- return unless connection_verified? net_http_client
41
+ return unless connection_verified?(net_http_client)
42
42
 
43
43
  logger.debug('Client verified', service: service_name, url: url)
44
44
  net_http_client
@@ -63,7 +63,7 @@ module Contrast
63
63
  response = client.request(Net::HTTP::Get.new(client.address))
64
64
  verify_cert = client.address.to_s.include?('localhost') ||
65
65
  OpenSSL::SSL.verify_certificate_identity(client.peer_cert, client.address)
66
- resolved = resolved? client.address, ipaddr
66
+ resolved = resolved?(client.address, ipaddr)
67
67
  @_connection_verified = if resolved && response && verify_cert
68
68
  true
69
69
  else
@@ -91,7 +91,7 @@ module Contrast
91
91
  def resolved? address, ipaddr
92
92
  return @_resolved unless @_resolved.nil?
93
93
 
94
- @_resolved = if (addresses = Resolv.getaddresses address)
94
+ @_resolved = if (addresses = Resolv.getaddresses(address))
95
95
  addresses.any? { |addr| addr.include?(ipaddr) }
96
96
  else
97
97
  false
@@ -10,7 +10,6 @@ module Contrast
10
10
  module ObjectShare
11
11
  # Strings
12
12
  ASTERISK = '*'
13
- AMPERSAND = '&'
14
13
  BACK_SLASH = '\\'
15
14
  EMPTY_STRING = ''
16
15
  COLON = ':'
@@ -24,6 +23,7 @@ module Contrast
24
23
  HTTPS_START = 'https:'
25
24
  NEW_LINE = "\n"
26
25
  NIL_STRING = 'nil'
26
+ NIL_64_STRING = 'bmls'
27
27
  PERIOD = '.'
28
28
  POUND_SIGN = '#'
29
29
  QUESTION_MARK = '?'
@@ -42,7 +42,7 @@ module Contrast
42
42
  end
43
43
 
44
44
  def mac?
45
- @_mac = RUBY_PLATFORM.include? 'darwin' if @_mac.nil?
45
+ @_mac = RUBY_PLATFORM.include?('darwin') if @_mac.nil?
46
46
  @_mac
47
47
  end
48
48
 
@@ -58,7 +58,7 @@ module Contrast
58
58
  rescue Contrast::SecurityException => e
59
59
  # We were told to block something, so we gotta. Don't catch this one, let it get back to our Middleware or
60
60
  # even all the way out to the framework
61
- raise e
61
+ raise(e)
62
62
  rescue StandardError => e
63
63
  # Anything else was our bad and we gotta catch that to allow for normal application flow
64
64
  logger.error('Unable to apply pre patch to method.', e)
@@ -155,7 +155,7 @@ module Contrast
155
155
  rescue Exception => e # rubocop:disable Lint/RescueException
156
156
  logger.error('Unable to assess method call.', e)
157
157
  handle_return(propagated_ret, source_ret, ret)
158
- raise e
158
+ raise(e)
159
159
  end
160
160
 
161
161
  # Generic invocation of the Inventory or Protect patch which apply to the given method.
@@ -31,7 +31,7 @@ module Contrast
31
31
  k = Contrast::Utils::StringUtils.force_utf8(k)
32
32
  nested_prefix = prefix.nil? ? k : "#{ prefix }[#{ k }]"
33
33
  hash[k] = Contrast::Utils::ObjectShare::EMPTY_STRING
34
- hash.merge! normalize_params(v, prefix: nested_prefix)
34
+ hash.merge!(normalize_params(v, prefix: nested_prefix))
35
35
  end
36
36
  res[prefix] = Contrast::Utils::ObjectShare::EMPTY_STRING if prefix
37
37
  res
@@ -39,7 +39,7 @@ module Contrast
39
39
  idx = 0
40
40
  res = {}
41
41
  while idx < val.length
42
- res.merge! normalize_params(val[idx], prefix: "#{ prefix }[#{ idx }]")
42
+ res.merge!(normalize_params(val[idx], prefix: "#{ prefix }[#{ idx }]"))
43
43
  idx += 1
44
44
  end
45
45
  res[prefix] = Contrast::Utils::ObjectShare::EMPTY_STRING if prefix
@@ -9,16 +9,16 @@ module Contrast
9
9
  # Utility methods for building and caching hashes from strings
10
10
  class Sha256Builder
11
11
  include Singleton
12
+ # Return a list of "source" files. Ignore metadata files as well as files
13
+ # in the spec, test or exe directories. Could potentially miss important
14
+ # files but good enough for the time being.
15
+ PATHS = '{lib,bin,ext}/**/*.{rb,c,h,c++,cpp,java,rs}'
12
16
 
13
17
  def initialize
14
18
  @sha256_cache = {}
15
19
  @gem_hash_cache = {}
16
20
  end
17
21
 
18
- # Return a list of "source" files. Ignore metadata files as well as files
19
- # in the spec, test or exe directories. Could potentially miss important
20
- # files but good enough for the time being.
21
- PATHS = '{lib,bin,ext}/**/*.{rb,c,h,c++,cpp,java,rs}'
22
22
  def files path
23
23
  if Dir.exist?(path)
24
24
  Dir.glob(File.join(path, PATHS))
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/utils/object_share'
5
+ require 'contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack'
5
6
  require 'contrast/api'
6
7
 
7
8
  module Contrast
@@ -35,21 +36,18 @@ module Contrast
35
36
  # StackTraceElement for TeamServer to display, excluding any Contrast
36
37
  # code found.
37
38
  #
38
- # @return [Array<Contrast::Api::Dtm::StackTraceElement]
39
+ # @return [Array<Contrast::Api::Dtm::StackTraceElement>]
39
40
  def build_protect_stack_array
40
- stack = caller(2, 20)
41
- return [] unless stack
41
+ build_protect_stack(Contrast::Api::Dtm::StackTraceElement)
42
+ end
42
43
 
43
- stack = reject_caller_entries(stack)
44
- i = 0
45
- stack.map! do |entry|
46
- element = Contrast::Api::Dtm::StackTraceElement.new
47
- element = fill_protect_element(element, entry, i)
48
- i += 1
49
- element
50
- end
51
- stack.compact!
52
- stack
44
+ # Call and translate a caller_locations array to an array of
45
+ # StackTraceElement for TeamServer to display, excluding any Contrast
46
+ # code found.
47
+ #
48
+ # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack>]
49
+ def build_protect_report_stack_array
50
+ build_protect_stack(Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack)
53
51
  end
54
52
 
55
53
  # Translate a caller array to an array of TraceStacks for TeamServer to
@@ -86,6 +84,26 @@ module Contrast
86
84
  end
87
85
  end
88
86
 
87
+ # @param clazz [Class] Contrast::Api::Dtm::StackTraceElement or
88
+ # Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack
89
+ # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack|
90
+ # Contrast::Api::Dtm::StackTraceElement>]
91
+ def build_protect_stack clazz
92
+ stack = caller(3, 21)
93
+ return [] unless stack
94
+
95
+ stack = reject_caller_entries(stack)
96
+ i = 0
97
+ stack.map! do |entry|
98
+ element = clazz.new
99
+ element = fill_protect_element(element, entry, i)
100
+ i += 1
101
+ element
102
+ end
103
+ stack.compact!
104
+ stack
105
+ end
106
+
89
107
  # In Contrast UI - there are many ways to render the stacktraces. For
90
108
  # Protect, there are two ways we're concerned about, one for the first
91
109
  # element and then all others.
@@ -1,8 +1,9 @@
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/agent/telemetry/telemetry'
4
+ require 'contrast/agent/telemetry/base'
5
5
  require 'contrast/utils/telemetry_identifier'
6
+ require 'contrast/config/env_variables'
6
7
 
7
8
  module Contrast
8
9
  module Utils
@@ -30,14 +31,21 @@ module Contrast
30
31
  # @return[Boolean, nil] true if file is created, false if file already exist
31
32
  # and nil if Telemetry is disabled or on unsupported OS.
32
33
  def self.create_telemetry_file
33
- write_mark_file DIR, FILE, CONFIG_DIR
34
+ write_mark_file(DIR, FILE, CONFIG_DIR)
34
35
  end
35
36
 
36
37
  def self.disclaimer
37
38
  @_disclaimer = MESSAGE[:disclaimer]
38
39
  end
39
40
 
41
+ def self.exceptions_enabled?
42
+ @_exceptions_enabled = telemetry_exceptions_enabled? if @_exceptions_enabled.nil?
43
+ @_exceptions_enabled
44
+ end
45
+
40
46
  class << self
47
+ include Contrast::Config::EnvVariables
48
+
41
49
  private
42
50
 
43
51
  # Create the mark file
@@ -48,7 +56,7 @@ module Contrast
48
56
  # @return[Boolean, nil] true if file is created, false if file already exist
49
57
  # and nil if Telemetry is disabled or on unsupported OS.
50
58
  def write_mark_file dir, file, config_dir
51
- return unless Contrast::Agent::Telemetry.enabled?
59
+ return unless Contrast::Agent::Telemetry::Base.enabled?
52
60
  return if Contrast::Utils::OS.windows?
53
61
 
54
62
  @dir = dir
@@ -56,7 +64,7 @@ module Contrast
56
64
  # nor can we write to the "root" directory ( / ). This results in Errno::EROFS exception.
57
65
  # So for the MacOS we would use the config directory of the instrumented application.
58
66
  @dir = config_dir if Contrast::Utils::OS.mac?
59
- return false if File.file? @dir + file
67
+ return false if File.file?(@dir + file)
60
68
  return true if touch_marker(@dir, file)
61
69
 
62
70
  # If we don't have permission to write to root directory use config instead
@@ -67,12 +75,19 @@ module Contrast
67
75
  #
68
76
  # @return[Boolean] true if success, false if fails
69
77
  def touch_marker dir, file
70
- FileUtils.mkdir_p dir unless Dir.exist? dir
71
- FileUtils.touch dir + file
72
- File.file? dir + file
78
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
79
+ FileUtils.touch(dir + file)
80
+ File.file?(dir + file)
73
81
  rescue StandardError => _e
74
82
  false
75
83
  end
84
+
85
+ def telemetry_exceptions_enabled?
86
+ opts_out_telemetry = return_value(:telemetry_opt_outs).to_s
87
+ return false if opts_out_telemetry.casecmp?('true') || opts_out_telemetry == '1'
88
+
89
+ true
90
+ end
76
91
  end
77
92
  end
78
93
  end
@@ -12,9 +12,10 @@ module Contrast
12
12
  module Utils
13
13
  # This module creates a Net::HTTP client and initiates a connection to the provided result
14
14
  class TelemetryClient < NetHttpBase
15
+ include Contrast::Components::Logger::InstanceMethods
15
16
  ENDPOINT = 'api/v1/telemetry/metrics' # /TelemetryEvent.path
17
+ EXCEPTIONS = 'api/v1/telemetry/exceptions' # /TelemetryExceptions::Event.path
16
18
  SERVICE_NAME = 'Telemetry'
17
- include Contrast::Components::Logger::InstanceMethods
18
19
  # This method initializes the Net::HTTP client we'll need. it will validate
19
20
  # the connection and make the first request. If connection is valid and response
20
21
  # is available then the open connection is returned.
@@ -28,30 +29,35 @@ module Contrast
28
29
  # This method will be responsible for building the request. Because the telemetry collector expects to receive
29
30
  # multiple events in a single request, we must always wrap the event in an array, even if there is only one.
30
31
  #
31
- # @param event [Contrast::Agent::TelemetryEvent,Contrast::Agent::StartupMetricsTelemetryEvent]
32
+ # @param event [Contrast::Agent::Telemetry::Event, Array<Contrast::Agent::Telemetry::TelemetryException::Event>]
32
33
  # @return [Net::HTTP::Post]
33
34
  def build_request event
34
- return unless valid_event? event
35
+ return unless valid_event?(event)
36
+
37
+ string_body = if Array(event).all?(Contrast::Agent::Telemetry::TelemetryException::Event)
38
+ event.map(&:to_controlled_hash).flatten!
39
+ else
40
+ [event.to_hash]
41
+ end
35
42
 
36
- string_body = [event.to_hash].to_json
37
43
  header = {
38
44
  'User-Agent' => "<#{ Contrast::Utils::ObjectShare::RUBY }>-<#{ Contrast::Agent::VERSION }>",
39
45
  'Content-Type' => 'application/json'
40
46
  }
41
- request = Net::HTTP::Post.new(build_path(event.path), header)
42
- request.body = string_body
47
+ request = Net::HTTP::Post.new(build_path(event), header)
48
+ request.body = string_body.to_json
43
49
  request
44
50
  end
45
51
 
46
52
  # This method will create the actual request and send it
47
- # @param event[Contrast::Agent::TelemetryEvent]
53
+ # @param event[Contrast::Agent::Telemetry::Event]
48
54
  # @param connection[Net::HTTP]
49
55
  def send_request event, connection
50
56
  return if connection.nil? || event.nil?
51
- return unless valid_event? event
57
+ return unless valid_event?(event)
52
58
 
53
- req = build_request event
54
- connection.request req
59
+ req = build_request(event)
60
+ connection.request(req)
55
61
  end
56
62
 
57
63
  # This method will handle the response from the tenant
@@ -68,10 +74,13 @@ module Contrast
68
74
  end
69
75
 
70
76
  # This method will be responsible for validating the event
71
- # @param event[Contrast::Agent::TelemetryEvent,Contrast::Agent::StartupMetricsTelemetryEvent]
77
+ # @param event[Contrast::Agent::Telemetry::Event,Contrast::Agent::Telemetry::StartupMetricsEvent,
78
+ # array<Contrast::Agent::Telemetry::TelemetryException::Event>]
72
79
  def valid_event? event
73
- return true if event.cs__is_a?(Contrast::Agent::TelemetryEvent)
74
- return true if event.cs__is_a?(Contrast::Agent::StartupMetricsTelemetryEvent)
80
+ return true if event.cs__is_a?(Contrast::Agent::Telemetry::Event)
81
+ return true if event.cs__is_a?(Contrast::Agent::Telemetry::StartupMetricsEvent)
82
+ # Batch
83
+ return true if Array(event).all?(Contrast::Agent::Telemetry::TelemetryException::Event)
75
84
 
76
85
  false
77
86
  end
@@ -81,9 +90,12 @@ module Contrast
81
90
  # The telemetry instance accepts any path to #{ Contrast::Agent::Telemetry::URL }#{ ENDPOINT }, using the
82
91
  # remainder of the path to segregate messages.
83
92
  #
93
+ # @param event [Contrast::Agent::Telemetry::Event, Contrast::Agent::Telemetry::TelemetryException::Event]
84
94
  # @return [String] the fully qualified path to send the request
85
- def build_path event_path
86
- "#{ Contrast::Agent::Telemetry::URL }#{ ENDPOINT }#{ event_path }"
95
+ def build_path event
96
+ endpoint = Array(event).all?(Contrast::Agent::Telemetry::TelemetryException::Event) ? EXCEPTIONS : ENDPOINT
97
+ path = endpoint == EXCEPTIONS ? Contrast::Agent::Telemetry::TelemetryException::Event.path : event.path
98
+ "#{ Contrast::Agent::Telemetry::Base::URL }#{ endpoint }#{ path }"
87
99
  end
88
100
  end
89
101
  end
@@ -0,0 +1,41 @@
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/components/logger'
5
+
6
+ module Contrast
7
+ module Utils
8
+ # This is the TelemetryHash, which will take data type, so we can push freely, without worrying about
9
+ # validating the event before that
10
+ class TelemetryHash < Hash
11
+ include Contrast::Components::Logger::InstanceMethods
12
+
13
+ attr_reader :data_type
14
+
15
+ def initialize data_type, *_several_variants
16
+ super()
17
+ @data_type = data_type
18
+ end
19
+
20
+ def []= key, value
21
+ return unless valid_value?(value)
22
+
23
+ super(key, value)
24
+ end
25
+
26
+ def increment key
27
+ self[key].exceptions[0].increment_occurrences
28
+ :incremented!
29
+ end
30
+
31
+ def valid_value? value
32
+ unless value.cs__is_a?(data_type)
33
+ logger.debug('The following key will be omitted', value: value)
34
+ return false
35
+ end
36
+
37
+ true
38
+ end
39
+ end
40
+ end
41
+ end