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
@@ -1,8 +1,8 @@
1
1
  /* Copyright (c) 2022 Contrast Security, Inc. See
2
2
  * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */
3
3
 
4
- #include "../cs__common/cs__common.h"
5
4
  #include "cs__scope.h"
5
+ #include "../cs__common/cs__common.h"
6
6
  #include <ruby.h>
7
7
 
8
8
  /* Calls to Contrast modules and classes */
@@ -26,8 +26,7 @@ VALUE get_ec() {
26
26
  keys = rb_const_get(scope_mod, rb_intern(rb_const_ec_keys));
27
27
  fiber = rb_fiber_current();
28
28
 
29
- if (RB_TYPE_P(scope_inst, T_NIL))
30
- {
29
+ if (RB_TYPE_P(scope_inst, T_NIL)) {
31
30
  new_inst = rb_new_c_scope();
32
31
  rb_ary_push(keys, fiber);
33
32
  rb_hash_aset(ec, fiber, new_inst);
@@ -57,17 +56,19 @@ int scope_decrease(int scope) {
57
56
  }
58
57
 
59
58
  VALUE is_in_scope(int scope) {
60
- if (scope > 0)
61
- {
59
+ if (scope > 0) {
62
60
  return Qtrue;
63
61
  } else if (scope <= 0) {
64
62
  return Qfalse;
65
63
  }
66
64
  }
67
65
 
68
- /* default: raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a scope." */
66
+ /* default: raise NoMethodError, "Scope '#{ name.inspect }' is not registered as
67
+ * a scope." */
69
68
  void rb_raise_scope_no_method_err(const VALUE method_scope_sym) {
70
- rb_raise(rb_eNoMethodError, "Scope ':%"PRIsVALUE"' is not registered as a scope.", rb_sym_to_s(method_scope_sym));
69
+ rb_raise(rb_eNoMethodError,
70
+ "Scope ':%" PRIsVALUE "' is not registered as a scope.",
71
+ rb_sym_to_s(method_scope_sym));
71
72
  }
72
73
 
73
74
  /*
@@ -254,8 +255,9 @@ VALUE split_scope_depth(VALUE self, VALUE args) {
254
255
  }
255
256
 
256
257
  /*
257
- * Static methods to be used, the cases are defined by the usage from the above methods
258
- * if more methods are added - please extend the case statements as they are no longed dynamic
258
+ * Static methods to be used, the cases are defined by the usage from the above
259
+ * methods if more methods are added - please extend the case statements as they
260
+ * are no longed dynamic
259
261
  */
260
262
 
261
263
  /*
@@ -274,9 +276,8 @@ VALUE split_scope_depth(VALUE self, VALUE args) {
274
276
  * when :split
275
277
  * in_split_scope?
276
278
  * else
277
- * raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a scope."
278
- * end
279
- * end
279
+ * raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a
280
+ * scope." end end
280
281
  */
281
282
  VALUE scope_klass_in_scope(VALUE self, VALUE method_scope_sym) {
282
283
  VALUE in_scope = Qnil;
@@ -313,9 +314,8 @@ VALUE scope_klass_in_scope(VALUE self, VALUE method_scope_sym) {
313
314
  * when :split
314
315
  * enter_split_scope!
315
316
  * else
316
- * raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a scope."
317
- * end
318
- * end
317
+ * raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a
318
+ * scope." end end
319
319
  */
320
320
  VALUE scope_klass_enter_scope(VALUE self, VALUE method_scope_sym) {
321
321
  VALUE enter_scope = Qnil;
@@ -349,9 +349,8 @@ VALUE scope_klass_enter_scope(VALUE self, VALUE method_scope_sym) {
349
349
  * when :split
350
350
  * exit_split_scope!
351
351
  * else
352
- * raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a scope."
353
- * end
354
- * end
352
+ * raise NoMethodError, "Scope '#{ name.inspect }' is not registered as a
353
+ * scope." end end
355
354
  */
356
355
  VALUE scope_klass_exit_scope(VALUE self, VALUE method_scope_sym) {
357
356
  VALUE exit_scope = Qnil;
@@ -392,8 +391,9 @@ VALUE contrast_scope_interface_init(VALUE self, VALUE args) {
392
391
  /*
393
392
  * @method #scope_for_current_ec
394
393
  *
395
- * This returns the scope governing the current execution context. Use this sparingly, preferring the instance
396
- * & class methods to access and query scope, rather than interacting with the scope object directly.
394
+ * This returns the scope governing the current execution context. Use this
395
+ * sparingly, preferring the instance & class methods to access and query scope,
396
+ * rather than interacting with the scope object directly.
397
397
  *
398
398
  * Alternative to Monitor => mutex.synchronize
399
399
  * rb_mutex_new(void)
@@ -425,8 +425,8 @@ VALUE contrast_scope_for_current_ec(VALUE self, VALUE args) {
425
425
  *
426
426
  * Iterates over the method policy's scopes and enters in each one.
427
427
  *
428
- * @param scopes_to_enter [Array<Symbol>] Scopes form method_policy#scopes_to_enter
429
- * for the scope current method policy
428
+ * @param scopes_to_enter [Array<Symbol>] Scopes form
429
+ * method_policy#scopes_to_enter for the scope current method policy
430
430
  * @return scopes_to_enter [Array<Symbol>]
431
431
  *
432
432
  * [Ruby definition]
@@ -438,17 +438,17 @@ VALUE contrast_scope_for_current_ec(VALUE self, VALUE args) {
438
438
  * end
439
439
  */
440
440
  VALUE inst_methods_enter_method_scope(VALUE self, VALUE scopes_to_enter) {
441
- VALUE scopes_ary, scope;
441
+ VALUE scopes_ary, scope;
442
442
 
443
- scopes_ary = rb_ary_dup(scopes_to_enter);
444
- scope = rb_ary_pop(scopes_ary);
443
+ scopes_ary = rb_ary_dup(scopes_to_enter);
444
+ scope = rb_ary_pop(scopes_ary);
445
445
 
446
- while(!RB_TYPE_P(scope, T_NIL)){
447
- inst_methods_enter_scope(self, scope);
448
- scope = rb_ary_pop(scopes_ary);
449
- }
446
+ while (!RB_TYPE_P(scope, T_NIL)) {
447
+ inst_methods_enter_scope(self, scope);
448
+ scope = rb_ary_pop(scopes_ary);
449
+ }
450
450
 
451
- return scopes_to_enter;
451
+ return scopes_to_enter;
452
452
  }
453
453
 
454
454
  /*
@@ -456,8 +456,8 @@ VALUE inst_methods_enter_method_scope(VALUE self, VALUE scopes_to_enter) {
456
456
  *
457
457
  * Iterates over the method policy's scopes and exits each one.
458
458
  *
459
- * @param scopes_to_exit [Array<Symbol>] Scopes form method_policy#scopes_to_exit
460
- * for the scope current method policy
459
+ * @param scopes_to_exit [Array<Symbol>] Scopes form
460
+ * method_policy#scopes_to_exit for the scope current method policy
461
461
  * @return scopes_to_exit [Array<Symbol>]
462
462
  *
463
463
  * [Ruby definition]
@@ -469,58 +469,68 @@ VALUE inst_methods_enter_method_scope(VALUE self, VALUE scopes_to_enter) {
469
469
  * end
470
470
  */
471
471
  VALUE inst_methods_exit_method_scope(VALUE self, VALUE scopes_to_exit) {
472
- VALUE scopes_ary, scope;
472
+ VALUE scopes_ary, scope;
473
473
 
474
- scopes_ary = rb_ary_dup(scopes_to_exit);
475
- scope = rb_ary_pop(scopes_ary);
474
+ scopes_ary = rb_ary_dup(scopes_to_exit);
475
+ scope = rb_ary_pop(scopes_ary);
476
476
 
477
- while(!RB_TYPE_P(scope, T_NIL)){
478
- inst_methods_exit_scope(self, scope);
479
- scope = rb_ary_pop(scopes_ary);
480
- }
477
+ while (!RB_TYPE_P(scope, T_NIL)) {
478
+ inst_methods_exit_scope(self, scope);
479
+ scope = rb_ary_pop(scopes_ary);
480
+ }
481
481
 
482
- return scopes_to_exit;
482
+ return scopes_to_exit;
483
483
  }
484
484
 
485
- /* For the InstanceMethods we need to call all the scope methods from the current ec context
486
- * All methods bellow are with same names as Contrast::Agent::Scope class with the difference
487
- * that they act as forwarders:
485
+ /* For the InstanceMethods we need to call all the scope methods from the
486
+ * current ec context All methods bellow are with same names as
487
+ * Contrast::Agent::Scope class with the difference that they act as forwarders:
488
488
  * exp:
489
489
  * def in_contrast_scope?
490
490
  * scope_for_current_ec.in_contrast_scope?
491
491
  * end
492
492
  */
493
493
  VALUE inst_methods_in_cntr_scope(VALUE self, VALUE args) {
494
- return is_in_scope(FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope)));
494
+ return is_in_scope(FIX2INT(
495
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope)));
495
496
  }
496
497
 
497
498
  VALUE inst_methods_enter_cntr_scope(VALUE self, VALUE args) {
498
- int scope = FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope));
499
- rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope, scope_increase(scope));
499
+ int scope = FIX2INT(
500
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope));
501
+ rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope,
502
+ scope_increase(scope));
500
503
 
501
504
  return rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope);
502
505
  }
503
506
 
504
507
  VALUE inst_methods_exit_cntr_scope(VALUE self, VALUE args) {
505
- int scope = FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope));
506
- rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope, scope_decrease(scope));
508
+ int scope = FIX2INT(
509
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope));
510
+ rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope,
511
+ scope_decrease(scope));
507
512
 
508
513
  return rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_cntr_scope);
509
514
  }
510
515
 
511
516
  VALUE inst_methods_in_split_scope(VALUE self, VALUE args) {
512
- return is_in_scope(FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope)));
517
+ return is_in_scope(FIX2INT(
518
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope)));
513
519
  }
514
520
 
515
521
  VALUE inst_methods_enter_split_scope(VALUE self, VALUE args) {
516
- int scope = FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope));
522
+ int scope = FIX2INT(
523
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope));
517
524
 
518
- return rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope, scope_increase(scope));
525
+ return rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope,
526
+ scope_increase(scope));
519
527
  }
520
528
 
521
529
  VALUE inst_methods_exit_split_scope(VALUE self, VALUE args) {
522
- int scope = FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope));
523
- rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope, scope_decrease(scope));
530
+ int scope = FIX2INT(
531
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope));
532
+ rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope,
533
+ scope_decrease(scope));
524
534
 
525
535
  return rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_split_scope);
526
536
  }
@@ -530,19 +540,24 @@ VALUE inst_methods_split_scope_depth(VALUE self, VALUE args) {
530
540
  }
531
541
 
532
542
  VALUE inst_methods_in_dsrl_scope(VALUE self, VALUE args) {
533
- return is_in_scope(FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope)));
543
+ return is_in_scope(FIX2INT(
544
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope)));
534
545
  }
535
546
 
536
547
  VALUE inst_methods_enter_dsrl_scope(VALUE self, VALUE args) {
537
- int scope = FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope));
538
- rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope, scope_increase(scope));
548
+ int scope = FIX2INT(
549
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope));
550
+ rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope,
551
+ scope_increase(scope));
539
552
 
540
553
  return rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope);
541
554
  }
542
555
 
543
556
  VALUE inst_methods_exit_dsrl_scope(VALUE self, VALUE args) {
544
- int scope = FIX2INT(rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope));
545
- rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope, scope_decrease(scope));
557
+ int scope = FIX2INT(
558
+ rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope));
559
+ rb_iv_set(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope,
560
+ scope_decrease(scope));
546
561
 
547
562
  return rb_iv_get(contrast_scope_for_current_ec(self, 0), rb_iv_dslr_scope);
548
563
  }
@@ -561,7 +576,7 @@ VALUE inst_methods_in_scope(VALUE self, VALUE method_scope_sym) {
561
576
 
562
577
  VALUE inst_methods_enter_scope(VALUE self, VALUE method_scope_sym) {
563
578
  if (method_scope_sym == rb_sym_contrast) {
564
- inst_methods_enter_cntr_scope(self, 0);
579
+ inst_methods_enter_cntr_scope(self, 0);
565
580
  } else if (method_scope_sym == rb_sym_deserialization) {
566
581
  inst_methods_enter_dsrl_scope(self, 0);
567
582
  } else if (method_scope_sym == rb_sym_split) {
@@ -586,9 +601,10 @@ VALUE inst_methods_exit_scope(VALUE self, VALUE method_scope_sym) {
586
601
  /*
587
602
  * @module Contrast::Components::Scope
588
603
  *
589
- * TODO: RUBY-534, #sweep_dead_ecs compensates for a lack of weak tables. when we can use WeakRef, we should
590
- * investigate removing this call and instead use the WeakRef for the Execution Context's Keys or using our
591
- * Finalizers Hash for Fibers
604
+ * TODO: RUBY-534, #sweep_dead_ecs compensates for a lack of weak tables. when
605
+ * we can use WeakRef, we should investigate removing this call and instead use
606
+ * the WeakRef for the Execution Context's Keys or using our Finalizers Hash for
607
+ * Fibers
592
608
  *
593
609
  * [Ruby definition]
594
610
  *
@@ -614,14 +630,14 @@ VALUE scope_mod_sweep_dead_ecs(VALUE self, VALUE args) {
614
630
  key = rb_ary_entry(ec_keys, i);
615
631
  test = key;
616
632
  if (!RB_TYPE_P(key, T_NIL)) {
617
- if(!rb_fiber_alive_p(key)) {
633
+ if (!rb_fiber_alive_p(key)) {
618
634
  rb_hash_delete(ec, key);
619
635
  }
620
636
  }
621
637
  }
622
638
 
623
639
  return ec;
624
- }
640
+ }
625
641
 
626
642
  void Init_cs__scope() {
627
643
  /* ivs */
@@ -676,29 +692,45 @@ void Init_cs__scope() {
676
692
  */
677
693
 
678
694
  /* Instance methods: */
679
- rb_define_method(scope_klass, rb_method_name_init, contrast_scope_klass_init, 0);
680
- rb_define_method(scope_klass, rb_method_name_in_cntr_scope, in_cntr_scope, 0);
681
- rb_define_method(scope_klass, rb_method_name_enter_cntr_scope, enter_cntr_scope, 0);
682
- rb_define_method(scope_klass, rb_method_name_exit_cntr_scope, exit_cntr_scope, 0);
683
- rb_define_method(scope_klass, rb_method_name_in_dslr_scope, in_dslr_scope, 0);
684
- rb_define_method(scope_klass, rb_method_name_enter_dslr_scope, enter_dsrl_scope, 0);
685
- rb_define_method(scope_klass, rb_method_name_exit_dslr_scope, exit_dsrl_scope, 0);
686
- rb_define_method(scope_klass, rb_method_name_in_split_scope, in_split_scope, 0);
687
- rb_define_method(scope_klass, rb_method_name_enter_split_scope, enter_split_scope, 0);
688
- rb_define_method(scope_klass, rb_method_name_exit_split_scope, exit_split_scope, 0);
689
- rb_define_method(scope_klass, rb_method_name_split_scope_depth, split_scope_depth, 0);
690
- rb_define_method(scope_klass, rb_method_name_in_scope, scope_klass_in_scope, 1);
691
- rb_define_method(scope_klass, rb_method_name_enter_scope, scope_klass_enter_scope, 1);
692
- rb_define_method(scope_klass, rb_method_name_exit_scope, scope_klass_exit_scope, 1);
695
+ rb_define_method(scope_klass, rb_method_name_init,
696
+ contrast_scope_klass_init, 0);
697
+ rb_define_method(scope_klass, rb_method_name_in_cntr_scope, in_cntr_scope,
698
+ 0);
699
+ rb_define_method(scope_klass, rb_method_name_enter_cntr_scope,
700
+ enter_cntr_scope, 0);
701
+ rb_define_method(scope_klass, rb_method_name_exit_cntr_scope,
702
+ exit_cntr_scope, 0);
703
+ rb_define_method(scope_klass, rb_method_name_in_dslr_scope, in_dslr_scope,
704
+ 0);
705
+ rb_define_method(scope_klass, rb_method_name_enter_dslr_scope,
706
+ enter_dsrl_scope, 0);
707
+ rb_define_method(scope_klass, rb_method_name_exit_dslr_scope,
708
+ exit_dsrl_scope, 0);
709
+ rb_define_method(scope_klass, rb_method_name_in_split_scope, in_split_scope,
710
+ 0);
711
+ rb_define_method(scope_klass, rb_method_name_enter_split_scope,
712
+ enter_split_scope, 0);
713
+ rb_define_method(scope_klass, rb_method_name_exit_split_scope,
714
+ exit_split_scope, 0);
715
+ rb_define_method(scope_klass, rb_method_name_split_scope_depth,
716
+ split_scope_depth, 0);
717
+ rb_define_method(scope_klass, rb_method_name_in_scope, scope_klass_in_scope,
718
+ 1);
719
+ rb_define_method(scope_klass, rb_method_name_enter_scope,
720
+ scope_klass_enter_scope, 1);
721
+ rb_define_method(scope_klass, rb_method_name_exit_scope,
722
+ scope_klass_exit_scope, 1);
693
723
 
694
724
  /*
695
725
  * @class Contrast::Components::Interface
696
726
  */
697
727
 
698
728
  /* Interface#initialize */
699
- rb_define_method(scope_interface, rb_method_name_init, contrast_scope_interface_init, 0);
729
+ rb_define_method(scope_interface, rb_method_name_init,
730
+ contrast_scope_interface_init, 0);
700
731
  /* Interface#scope_for_current_ec */
701
- rb_define_method(scope_interface, rb_method_name_scope_for_current_ec, contrast_scope_for_current_ec, 0);
732
+ rb_define_method(scope_interface, rb_method_name_scope_for_current_ec,
733
+ contrast_scope_for_current_ec, 0);
702
734
 
703
735
  /*
704
736
  * @module Contrast::Components::Scope
@@ -718,30 +750,47 @@ void Init_cs__scope() {
718
750
  */
719
751
 
720
752
  /* InstanceMethods#scope_for_current_ec */
721
- rb_define_method(scope_inst_methods, rb_method_name_scope_for_current_ec, contrast_scope_for_current_ec, 0);
753
+ rb_define_method(scope_inst_methods, rb_method_name_scope_for_current_ec,
754
+ contrast_scope_for_current_ec, 0);
722
755
  /* Forwarders */
723
- rb_define_method(scope_inst_methods, rb_method_name_in_cntr_scope, inst_methods_in_cntr_scope, 0);
724
- rb_define_method(scope_inst_methods, rb_method_name_enter_cntr_scope, inst_methods_enter_cntr_scope, 0);
725
- rb_define_method(scope_inst_methods, rb_method_name_exit_cntr_scope, inst_methods_exit_cntr_scope, 0);
726
- rb_define_method(scope_inst_methods, rb_method_name_in_dslr_scope, inst_methods_in_dsrl_scope, 0);
727
- rb_define_method(scope_inst_methods, rb_method_name_enter_dslr_scope, inst_methods_enter_dsrl_scope, 0);
728
- rb_define_method(scope_inst_methods, rb_method_name_exit_dslr_scope, inst_methods_exit_dsrl_scope, 0);
729
- rb_define_method(scope_inst_methods, rb_method_name_in_split_scope, inst_methods_in_split_scope, 0);
730
- rb_define_method(scope_inst_methods, rb_method_name_enter_split_scope, inst_methods_enter_split_scope, 0);
731
- rb_define_method(scope_inst_methods, rb_method_name_exit_split_scope, inst_methods_exit_split_scope, 0);
732
- rb_define_method(scope_inst_methods, rb_method_name_split_scope_depth, inst_methods_split_scope_depth, 0);
733
- rb_define_method(scope_inst_methods, rb_method_name_in_scope, inst_methods_in_scope, 1);
734
- rb_define_method(scope_inst_methods, rb_method_name_enter_scope, inst_methods_enter_scope, 1);
735
- rb_define_method(scope_inst_methods, rb_method_name_exit_scope, inst_methods_exit_scope, 1);
756
+ rb_define_method(scope_inst_methods, rb_method_name_in_cntr_scope,
757
+ inst_methods_in_cntr_scope, 0);
758
+ rb_define_method(scope_inst_methods, rb_method_name_enter_cntr_scope,
759
+ inst_methods_enter_cntr_scope, 0);
760
+ rb_define_method(scope_inst_methods, rb_method_name_exit_cntr_scope,
761
+ inst_methods_exit_cntr_scope, 0);
762
+ rb_define_method(scope_inst_methods, rb_method_name_in_dslr_scope,
763
+ inst_methods_in_dsrl_scope, 0);
764
+ rb_define_method(scope_inst_methods, rb_method_name_enter_dslr_scope,
765
+ inst_methods_enter_dsrl_scope, 0);
766
+ rb_define_method(scope_inst_methods, rb_method_name_exit_dslr_scope,
767
+ inst_methods_exit_dsrl_scope, 0);
768
+ rb_define_method(scope_inst_methods, rb_method_name_in_split_scope,
769
+ inst_methods_in_split_scope, 0);
770
+ rb_define_method(scope_inst_methods, rb_method_name_enter_split_scope,
771
+ inst_methods_enter_split_scope, 0);
772
+ rb_define_method(scope_inst_methods, rb_method_name_exit_split_scope,
773
+ inst_methods_exit_split_scope, 0);
774
+ rb_define_method(scope_inst_methods, rb_method_name_split_scope_depth,
775
+ inst_methods_split_scope_depth, 0);
776
+ rb_define_method(scope_inst_methods, rb_method_name_in_scope,
777
+ inst_methods_in_scope, 1);
778
+ rb_define_method(scope_inst_methods, rb_method_name_enter_scope,
779
+ inst_methods_enter_scope, 1);
780
+ rb_define_method(scope_inst_methods, rb_method_name_exit_scope,
781
+ inst_methods_exit_scope, 1);
736
782
 
737
783
  /*
738
784
  * @module Contrast::Components::Scope
739
785
  */
740
- rb_define_singleton_method(scope_mod, "sweep_dead_ecs", scope_mod_sweep_dead_ecs, 0);
786
+ rb_define_singleton_method(scope_mod, "sweep_dead_ecs",
787
+ scope_mod_sweep_dead_ecs, 0);
741
788
 
742
789
  /*
743
790
  * @module Contrast::Components::Scope::InstanceMethods
744
791
  */
745
- rb_define_method(scope_inst_methods, "contrast_enter_method_scopes!", inst_methods_enter_method_scope, 1);
746
- rb_define_method(scope_inst_methods, "contrast_exit_method_scopes!", inst_methods_exit_method_scope, 1);
792
+ rb_define_method(scope_inst_methods, "contrast_enter_method_scopes!",
793
+ inst_methods_enter_method_scope, 1);
794
+ rb_define_method(scope_inst_methods, "contrast_exit_method_scopes!",
795
+ inst_methods_exit_method_scope, 1);
747
796
  }
@@ -0,0 +1,12 @@
1
+ /* Copyright (c) 2022 Contrast Security, Inc. See
2
+ * https://www.contrastsecurity.com/enduser-terms-0317a for more details. */
3
+
4
+ #include "cs__tests.h"
5
+ #include "../cs__common/cs__common.h"
6
+ #include <ruby.h>
7
+
8
+ /* Define any tests functions here, you could call a patch function and define
9
+ * it in Ruby */
10
+
11
+ void Init_cs__tests(void) {
12
+ }
@@ -0,0 +1,3 @@
1
+ #include <ruby.h>
2
+
3
+ void Init_cs__tests(void);
@@ -0,0 +1,5 @@
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
+ $TO_MAKE = File.basename(__dir__)
5
+ require_relative '../extconf_common'
@@ -5,7 +5,7 @@ require 'mkmf'
5
5
  require_relative '../lib/contrast/agent/version'
6
6
 
7
7
  def make!
8
- create_makefile "#{ $TO_MAKE }/#{ $TO_MAKE }"
8
+ create_makefile("#{ $TO_MAKE }/#{ $TO_MAKE }")
9
9
  end
10
10
 
11
11
  def ext_path
@@ -8,24 +8,22 @@ require 'contrast/agent/assess/tracker'
8
8
  module Contrast
9
9
  module Agent
10
10
  module Assess
11
- # This class is a convenient holder of our version of an Object. It
12
- # creates a String version of the Object from the original provided
13
- # and keeps reference to the original's Tags, letting us determine if it
14
- # was tracked when we try to report to TeamServer.
11
+ # This class is a convenient holder of our version of an Object. It creates a String version of the Object from
12
+ # the original provided and keeps reference to the original's Tags, letting us determine if it was tracked when
13
+ # we try to report to TeamServer.
15
14
  #
16
- # @attr_reader object [String, nil] the Contrast string representing the
17
- # object.
18
- # @attr_reader object_type [String] the name of the object's module.
19
- # @attr_reader tags [Hash{String => Contrast::Agent::Assess::Tag}, nil]
20
- # the tags on the object before it was captured.
21
- #
22
- # TODO: RUBY-1083 determine if this is expensive and/or worth not storing
23
- # these values directly on ContrastEvent and passing them around. Args
24
- # probably make the argument for wrapping them b/c otherwise we'll have
25
- # to keep two arrays in synch or make an array of arrays, at which
26
- # point, we may as well make this.
15
+ # TODO: RUBY-1083 determine if this is expensive and/or worth not storing these values directly on ContrastEvent
16
+ # and passing them around. Args probably make the argument for wrapping them b/c otherwise we'll have to keep
17
+ # two arrays in synch or make an array of arrays, at which point, we may as well make this.
27
18
  class ContrastObject
28
- attr_reader :object, :object_type, :tags
19
+ # @return [String] the Contrast String representation of the Object.
20
+ attr_reader :object
21
+ # @return [Integer] the __id__ of the original Object.
22
+ attr_reader :tracked_object_id
23
+ # @return [String] the name of the Class/Module of the Object.
24
+ attr_reader :object_type
25
+ # @return [Hash<Contrast::Agent::Assess::Tag>] the tags on the original Object.
26
+ attr_reader :tags
29
27
 
30
28
  # Capture the details about the object which we need to render it in
31
29
  # TeamServer.
@@ -34,10 +32,12 @@ module Contrast
34
32
  def initialize object
35
33
  if object
36
34
  @object = Contrast::Utils::ClassUtil.to_contrast_string(object)
35
+ @tracked_object_id = object.__id__
37
36
  @object_type = object.cs__class.cs__name
38
37
  @tags = Contrast::Agent::Assess::Tracker.properties(object)&.get_tags
39
38
  else
40
39
  @object = Contrast::Utils::ObjectShare::NIL_STRING
40
+ @tracked_object_id = nil.__id__
41
41
  @object_type = nil.cs__class.cs__name
42
42
  end
43
43
  end
@@ -9,22 +9,22 @@ module Contrast
9
9
  module Agent
10
10
  module Assess
11
11
  module Events
12
- # This class holds the data about an event in the application
13
- # We'll use it to build an event that TeamServer can consume if
14
- # the object to which this event belongs ends in a trigger.
15
- #
16
- # @attr_reader request [Contrast::Agent::Request] our wrapper around the Rack::Request at the time this source
17
- # was created
18
- # @attr_reader source_name [String] the name of the source if it comes from a map-like entity
19
- # @attr_reader source_type [String] the TeamServer understood type of source; i.e. parameter
12
+ # This class holds the data about an event in the application. We'll use it to build an event that TeamServer
13
+ # can consume if the object to which this event belongs ends in a trigger.
20
14
  class SourceEvent < Contrast::Agent::Assess::ContrastEvent
21
- attr_reader :request, :source_name, :source_type
15
+ # @return [Contrast::Agent::Request] our wrapper around the Rack::Request at the time this source
16
+ # was created
17
+ attr_reader :request
18
+ # @return [String] the name of the source if it comes from a map-like entity
19
+ attr_reader :source_name
20
+ # @return [String] the TeamServer understood type of source; i.e. parameter
21
+ attr_reader :source_type
22
22
 
23
23
  # @param event_data [Contrast::Agent::Assess::Events::EventData]
24
- # @param source_type [String] the type of this source, from the
25
- # source_node, or a KEY_TYPE if invoked for a map,
26
- # @param source_name [String, nil] the name of this source, i.e.
27
- # the key used to accessed if from a map or nil if a type like,
24
+ # @param source_type [String] the type of this source, from the source_node, or a KEY_TYPE if invoked for a
25
+ # Hash
26
+ # @param source_name [String, nil] the name of this source, i.e. the key used to accessed if from a Hash or
27
+ # nil if a type like
28
28
  def initialize event_data, source_type = nil, source_name = nil
29
29
  super(event_data)
30
30
  @source_type = source_type
@@ -54,8 +54,7 @@ module Contrast
54
54
  @_forced_source_name ||= Contrast::Utils::StringUtils.force_utf8(source_name)
55
55
  end
56
56
 
57
- # Probably only for source events, but we'll go
58
- # with source_type instead. java & .net support source_type
57
+ # Probably only for source events, but we'll go with source_type instead. java & .net support source_type
59
58
  # in propagation events, so we'll future proof this
60
59
  def build_event_source_dtm
61
60
  # You can have a source w/o a name, but not w/o a type
@@ -67,8 +66,7 @@ module Contrast
67
66
  dtm
68
67
  end
69
68
 
70
- # Probably only for source events, but we'll go
71
- # with source_type instead. java & .net support source_type
69
+ # Probably only for source events, but we'll go with source_type instead. java & .net support source_type
72
70
  # in propagation events, so we'll future proof this
73
71
  def build_event_source
74
72
  # You can have a source w/o a name, but not w/o a type
@@ -80,8 +78,8 @@ module Contrast
80
78
  trace_event_source
81
79
  end
82
80
 
83
- # We have to do a little work to figure out what our TS appropriate
84
- # target is. To break this down, the logic is as follows:
81
+ # We have to do a little work to figure out what our TS appropriate target is. To break this down, the logic
82
+ # is as follows:
85
83
  # 1) I'll set the event's source and target to TS values.
86
84
  # 2) Return the first source/target as the taint target.
87
85
  def determine_taint_target event_dtm
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/utils/duck_utils'
5
+ require 'contrast/agent/assess/policy/propagation_method'
5
6
 
6
7
  module Contrast
7
8
  module Agent
@@ -21,11 +22,11 @@ module Contrast
21
22
  else
22
23
  ObjectSpace.define_finalizer(key, finalizing_proc)
23
24
  end
24
- super key.__id__, obj
25
+ super(key.__id__, obj)
25
26
  end
26
27
 
27
28
  def [] key
28
- super key.__id__
29
+ super(key.__id__)
29
30
  end
30
31
 
31
32
  # Something is trackable if it is not a collection and either not frozen or it was frozen after we put a
@@ -66,6 +67,7 @@ module Contrast
66
67
  def finalizing_proc
67
68
  @_finalizing_proc ||= proc do |key_id|
68
69
  FROZEN_FINALIZED_IDS.delete(key_id)
70
+ Contrast::Agent::Assess::Policy::PropagationMethod.instance_variable_get(:@properties).delete(key_id)
69
71
  delete(key_id)
70
72
  end
71
73
  end