contrast-agent 4.4.0 → 4.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (313) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +1 -1
  3. data/.simplecov +1 -1
  4. data/Gemfile +1 -1
  5. data/LICENSE.txt +1 -1
  6. data/Rakefile +2 -3
  7. data/exe/contrast_service +1 -1
  8. data/ext/build_funchook.rb +4 -4
  9. data/ext/cs__assess_active_record_named/cs__active_record_named.c +1 -1
  10. data/ext/cs__assess_active_record_named/extconf.rb +1 -1
  11. data/ext/cs__assess_array/cs__assess_array.c +1 -1
  12. data/ext/cs__assess_array/extconf.rb +1 -1
  13. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +1 -1
  14. data/ext/cs__assess_basic_object/extconf.rb +1 -1
  15. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  16. data/ext/cs__assess_fiber_track/extconf.rb +1 -1
  17. data/ext/cs__assess_hash/cs__assess_hash.c +4 -2
  18. data/ext/cs__assess_hash/extconf.rb +1 -1
  19. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
  20. data/ext/cs__assess_kernel/extconf.rb +1 -1
  21. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +1 -1
  22. data/ext/cs__assess_marshal_module/extconf.rb +1 -1
  23. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  24. data/ext/cs__assess_module/extconf.rb +1 -1
  25. data/ext/cs__assess_regexp/cs__assess_regexp.c +1 -1
  26. data/ext/cs__assess_regexp/extconf.rb +1 -1
  27. data/ext/cs__assess_string/cs__assess_string.c +1 -1
  28. data/ext/cs__assess_string/extconf.rb +1 -1
  29. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -1
  30. data/ext/cs__assess_string_interpolation26/extconf.rb +1 -1
  31. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -1
  32. data/ext/cs__assess_yield_track/extconf.rb +1 -1
  33. data/ext/cs__common/cs__common.c +5 -5
  34. data/ext/cs__common/cs__common.h +4 -4
  35. data/ext/cs__common/extconf.rb +1 -1
  36. data/ext/cs__contrast_patch/cs__contrast_patch.c +22 -25
  37. data/ext/cs__contrast_patch/extconf.rb +1 -1
  38. data/ext/cs__protect_kernel/cs__protect_kernel.c +1 -1
  39. data/ext/cs__protect_kernel/extconf.rb +1 -1
  40. data/ext/extconf_common.rb +2 -6
  41. data/lib/contrast-agent.rb +1 -1
  42. data/lib/contrast.rb +20 -1
  43. data/lib/contrast/agent.rb +1 -3
  44. data/lib/contrast/agent/assess.rb +2 -2
  45. data/lib/contrast/agent/assess/contrast_event.rb +54 -69
  46. data/lib/contrast/agent/assess/contrast_object.rb +3 -3
  47. data/lib/contrast/agent/assess/events/event_factory.rb +3 -2
  48. data/lib/contrast/agent/assess/events/source_event.rb +7 -2
  49. data/lib/contrast/agent/assess/finalizers/freeze.rb +1 -1
  50. data/lib/contrast/agent/assess/finalizers/hash.rb +26 -34
  51. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +24 -20
  52. data/lib/contrast/agent/assess/policy/patcher.rb +11 -18
  53. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  54. data/lib/contrast/agent/assess/policy/policy_node.rb +26 -34
  55. data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
  56. data/lib/contrast/agent/assess/policy/preshift.rb +4 -2
  57. data/lib/contrast/agent/assess/policy/propagation_method.rb +8 -21
  58. data/lib/contrast/agent/assess/policy/propagation_node.rb +20 -9
  59. data/lib/contrast/agent/assess/policy/propagator.rb +2 -1
  60. data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -1
  61. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  62. data/lib/contrast/agent/assess/policy/propagator/center.rb +3 -2
  63. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  65. data/lib/contrast/agent/assess/policy/propagator/insert.rb +4 -2
  66. data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -1
  67. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
  68. data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -1
  69. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -1
  70. data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
  71. data/lib/contrast/agent/assess/policy/propagator/remove.rb +23 -19
  72. data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -1
  73. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -1
  74. data/lib/contrast/agent/assess/policy/propagator/select.rb +3 -13
  75. data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
  76. data/lib/contrast/agent/assess/policy/propagator/split.rb +4 -8
  77. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -8
  78. data/lib/contrast/agent/assess/policy/propagator/trim.rb +64 -45
  79. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +7 -4
  80. data/lib/contrast/agent/assess/policy/source_method.rb +92 -81
  81. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  82. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +8 -6
  83. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +2 -4
  84. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -3
  85. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +7 -8
  86. data/lib/contrast/agent/assess/policy/trigger_method.rb +102 -74
  87. data/lib/contrast/agent/assess/policy/trigger_node.rb +5 -4
  88. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +5 -4
  89. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -3
  90. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +1 -1
  91. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +2 -9
  92. data/lib/contrast/agent/assess/properties.rb +1 -1
  93. data/lib/contrast/agent/assess/property/evented.rb +9 -6
  94. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  95. data/lib/contrast/agent/assess/property/updated.rb +1 -1
  96. data/lib/contrast/agent/assess/rule/provider.rb +1 -1
  97. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +12 -6
  98. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +5 -2
  99. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -6
  100. data/lib/contrast/agent/assess/tag.rb +1 -1
  101. data/lib/contrast/agent/assess/tracker.rb +1 -1
  102. data/lib/contrast/agent/at_exit_hook.rb +1 -1
  103. data/lib/contrast/agent/class_reopener.rb +4 -2
  104. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  105. data/lib/contrast/agent/deadzone/policy/policy.rb +7 -3
  106. data/lib/contrast/agent/disable_reaction.rb +2 -4
  107. data/lib/contrast/agent/exclusion_matcher.rb +6 -12
  108. data/lib/contrast/agent/inventory.rb +1 -2
  109. data/lib/contrast/agent/inventory/dependencies.rb +3 -1
  110. data/lib/contrast/agent/inventory/dependency_analysis.rb +1 -1
  111. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +35 -23
  112. data/lib/contrast/agent/inventory/policy/datastores.rb +1 -1
  113. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  114. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  115. data/lib/contrast/agent/middleware.rb +38 -67
  116. data/lib/contrast/agent/module_data.rb +4 -4
  117. data/lib/contrast/agent/patching/policy/after_load_patch.rb +1 -1
  118. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +9 -4
  119. data/lib/contrast/agent/patching/policy/method_policy.rb +7 -3
  120. data/lib/contrast/agent/patching/policy/module_policy.rb +15 -8
  121. data/lib/contrast/agent/patching/policy/patch.rb +23 -29
  122. data/lib/contrast/agent/patching/policy/patch_status.rb +7 -8
  123. data/lib/contrast/agent/patching/policy/patcher.rb +23 -22
  124. data/lib/contrast/agent/patching/policy/policy.rb +14 -21
  125. data/lib/contrast/agent/patching/policy/policy_node.rb +15 -5
  126. data/lib/contrast/agent/patching/policy/trigger_node.rb +22 -9
  127. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +2 -2
  128. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  129. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  130. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -4
  131. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  132. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +6 -10
  133. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  134. data/lib/contrast/agent/protect/policy/rule_applicator.rb +6 -6
  135. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  136. data/lib/contrast/agent/protect/rule.rb +1 -1
  137. data/lib/contrast/agent/protect/rule/base.rb +19 -33
  138. data/lib/contrast/agent/protect/rule/base_service.rb +10 -6
  139. data/lib/contrast/agent/protect/rule/cmd_injection.rb +15 -19
  140. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  141. data/lib/contrast/agent/protect/rule/deserialization.rb +7 -14
  142. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +4 -15
  143. data/lib/contrast/agent/protect/rule/no_sqli.rb +7 -3
  144. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +2 -4
  145. data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -6
  146. data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
  147. data/lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb +1 -1
  148. data/lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb +1 -1
  149. data/lib/contrast/agent/protect/rule/sqli/postgres_sql_scanner.rb +2 -2
  150. data/lib/contrast/agent/protect/rule/sqli/sqlite_sql_scanner.rb +1 -1
  151. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -2
  152. data/lib/contrast/agent/protect/rule/xss.rb +2 -2
  153. data/lib/contrast/agent/protect/rule/xxe.rb +6 -13
  154. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -3
  155. data/lib/contrast/agent/reaction_processor.rb +12 -11
  156. data/lib/contrast/agent/request.rb +25 -24
  157. data/lib/contrast/agent/request_context.rb +13 -23
  158. data/lib/contrast/agent/request_handler.rb +1 -1
  159. data/lib/contrast/agent/response.rb +1 -1
  160. data/lib/contrast/agent/rewriter.rb +6 -4
  161. data/lib/contrast/agent/rule_set.rb +3 -3
  162. data/lib/contrast/agent/scope.rb +1 -1
  163. data/lib/contrast/agent/service_heartbeat.rb +3 -4
  164. data/lib/contrast/agent/static_analysis.rb +1 -1
  165. data/lib/contrast/agent/thread.rb +1 -1
  166. data/lib/contrast/agent/thread_watcher.rb +1 -1
  167. data/lib/contrast/agent/tracepoint_hook.rb +2 -2
  168. data/lib/contrast/agent/version.rb +2 -2
  169. data/lib/contrast/agent/worker_thread.rb +1 -1
  170. data/lib/contrast/api.rb +1 -1
  171. data/lib/contrast/api/communication.rb +1 -1
  172. data/lib/contrast/api/communication/connection_status.rb +1 -1
  173. data/lib/contrast/api/communication/messaging_queue.rb +1 -1
  174. data/lib/contrast/api/communication/response_processor.rb +5 -7
  175. data/lib/contrast/api/communication/service_lifecycle.rb +5 -3
  176. data/lib/contrast/api/communication/socket.rb +1 -1
  177. data/lib/contrast/api/communication/socket_client.rb +9 -22
  178. data/lib/contrast/api/communication/speedracer.rb +6 -10
  179. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  180. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  181. data/lib/contrast/api/decorators.rb +1 -1
  182. data/lib/contrast/api/decorators/address.rb +1 -1
  183. data/lib/contrast/api/decorators/agent_startup.rb +1 -1
  184. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  185. data/lib/contrast/api/decorators/application_startup.rb +10 -4
  186. data/lib/contrast/api/decorators/application_update.rb +1 -1
  187. data/lib/contrast/api/decorators/http_request.rb +1 -1
  188. data/lib/contrast/api/decorators/input_analysis.rb +1 -1
  189. data/lib/contrast/api/decorators/instrumentation_mode.rb +37 -0
  190. data/lib/contrast/api/decorators/library.rb +9 -7
  191. data/lib/contrast/api/decorators/library_usage_update.rb +1 -1
  192. data/lib/contrast/api/decorators/message.rb +4 -4
  193. data/lib/contrast/api/decorators/rasp_rule_sample.rb +1 -1
  194. data/lib/contrast/api/decorators/route_coverage.rb +1 -1
  195. data/lib/contrast/api/decorators/server_features.rb +1 -1
  196. data/lib/contrast/api/decorators/trace_event.rb +4 -2
  197. data/lib/contrast/api/decorators/trace_event_object.rb +2 -4
  198. data/lib/contrast/api/decorators/trace_event_signature.rb +1 -1
  199. data/lib/contrast/api/decorators/trace_taint_range.rb +1 -1
  200. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +2 -7
  201. data/lib/contrast/api/decorators/user_input.rb +1 -1
  202. data/lib/contrast/components/agent.rb +14 -15
  203. data/lib/contrast/components/app_context.rb +7 -7
  204. data/lib/contrast/components/assess.rb +6 -11
  205. data/lib/contrast/components/config.rb +3 -2
  206. data/lib/contrast/components/contrast_service.rb +8 -9
  207. data/lib/contrast/components/heap_dump.rb +1 -1
  208. data/lib/contrast/components/interface.rb +4 -3
  209. data/lib/contrast/components/inventory.rb +1 -1
  210. data/lib/contrast/components/logger.rb +1 -1
  211. data/lib/contrast/components/protect.rb +11 -14
  212. data/lib/contrast/components/sampling.rb +9 -3
  213. data/lib/contrast/components/scope.rb +2 -1
  214. data/lib/contrast/components/settings.rb +27 -98
  215. data/lib/contrast/config.rb +1 -1
  216. data/lib/contrast/config/agent_configuration.rb +1 -1
  217. data/lib/contrast/config/application_configuration.rb +1 -1
  218. data/lib/contrast/config/assess_configuration.rb +1 -1
  219. data/lib/contrast/config/assess_rules_configuration.rb +2 -4
  220. data/lib/contrast/config/base_configuration.rb +5 -6
  221. data/lib/contrast/config/default_value.rb +1 -1
  222. data/lib/contrast/config/exception_configuration.rb +2 -6
  223. data/lib/contrast/config/heap_dump_configuration.rb +13 -7
  224. data/lib/contrast/config/inventory_configuration.rb +1 -1
  225. data/lib/contrast/config/logger_configuration.rb +2 -6
  226. data/lib/contrast/config/protect_configuration.rb +1 -1
  227. data/lib/contrast/config/protect_rule_configuration.rb +23 -1
  228. data/lib/contrast/config/protect_rules_configuration.rb +1 -1
  229. data/lib/contrast/config/root_configuration.rb +1 -1
  230. data/lib/contrast/config/ruby_configuration.rb +1 -1
  231. data/lib/contrast/config/sampling_configuration.rb +1 -1
  232. data/lib/contrast/config/server_configuration.rb +1 -1
  233. data/lib/contrast/config/service_configuration.rb +1 -1
  234. data/lib/contrast/configuration.rb +4 -15
  235. data/lib/contrast/delegators/input_analysis.rb +12 -0
  236. data/lib/contrast/extension/assess.rb +1 -1
  237. data/lib/contrast/extension/assess/array.rb +2 -7
  238. data/lib/contrast/extension/assess/erb.rb +2 -8
  239. data/lib/contrast/extension/assess/eval_trigger.rb +3 -11
  240. data/lib/contrast/extension/assess/exec_trigger.rb +4 -14
  241. data/lib/contrast/extension/assess/fiber.rb +3 -13
  242. data/lib/contrast/extension/assess/hash.rb +1 -1
  243. data/lib/contrast/extension/assess/kernel.rb +3 -10
  244. data/lib/contrast/extension/assess/marshal.rb +3 -11
  245. data/lib/contrast/extension/assess/regexp.rb +2 -7
  246. data/lib/contrast/extension/assess/string.rb +4 -2
  247. data/lib/contrast/extension/delegator.rb +1 -1
  248. data/lib/contrast/extension/inventory.rb +1 -1
  249. data/lib/contrast/extension/kernel.rb +5 -3
  250. data/lib/contrast/extension/module.rb +1 -1
  251. data/lib/contrast/extension/protect.rb +1 -1
  252. data/lib/contrast/extension/protect/kernel.rb +1 -1
  253. data/lib/contrast/extension/protect/psych.rb +1 -1
  254. data/lib/contrast/extension/thread.rb +1 -1
  255. data/lib/contrast/framework/base_support.rb +1 -1
  256. data/lib/contrast/framework/manager.rb +5 -9
  257. data/lib/contrast/framework/platform_version.rb +1 -1
  258. data/lib/contrast/framework/rack/patch/session_cookie.rb +6 -19
  259. data/lib/contrast/framework/rack/patch/support.rb +7 -5
  260. data/lib/contrast/framework/rack/support.rb +1 -1
  261. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -1
  262. data/lib/contrast/framework/rails/patch/assess_configuration.rb +8 -3
  263. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +4 -4
  264. data/lib/contrast/framework/rails/patch/support.rb +6 -4
  265. data/lib/contrast/framework/rails/railtie.rb +32 -0
  266. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +5 -2
  267. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +3 -1
  268. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -1
  269. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +3 -1
  270. data/lib/contrast/framework/rails/support.rb +3 -3
  271. data/lib/contrast/framework/sinatra/support.rb +4 -2
  272. data/lib/contrast/funchook/funchook.rb +2 -6
  273. data/lib/contrast/logger/application.rb +13 -10
  274. data/lib/contrast/logger/format.rb +3 -6
  275. data/lib/contrast/logger/log.rb +5 -4
  276. data/lib/contrast/logger/request.rb +2 -3
  277. data/lib/contrast/logger/time.rb +1 -1
  278. data/lib/contrast/security_exception.rb +2 -2
  279. data/lib/contrast/tasks/config.rb +1 -1
  280. data/lib/contrast/tasks/service.rb +6 -2
  281. data/lib/contrast/utils/assess/sampling_util.rb +1 -1
  282. data/lib/contrast/utils/assess/tracking_util.rb +2 -3
  283. data/lib/contrast/utils/class_util.rb +15 -11
  284. data/lib/contrast/utils/duck_utils.rb +1 -1
  285. data/lib/contrast/utils/env_configuration_item.rb +1 -1
  286. data/lib/contrast/utils/hash_digest.rb +16 -24
  287. data/lib/contrast/utils/heap_dump_util.rb +1 -1
  288. data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
  289. data/lib/contrast/utils/inventory_util.rb +1 -1
  290. data/lib/contrast/utils/io_util.rb +2 -2
  291. data/lib/contrast/utils/job_servers_running.rb +10 -5
  292. data/lib/contrast/utils/object_share.rb +1 -1
  293. data/lib/contrast/utils/os.rb +3 -2
  294. data/lib/contrast/utils/preflight_util.rb +1 -1
  295. data/lib/contrast/utils/resource_loader.rb +1 -1
  296. data/lib/contrast/utils/ruby_ast_rewriter.rb +3 -2
  297. data/lib/contrast/utils/sha256_builder.rb +1 -1
  298. data/lib/contrast/utils/stack_trace_utils.rb +1 -1
  299. data/lib/contrast/utils/string_utils.rb +1 -1
  300. data/lib/contrast/utils/tag_util.rb +1 -1
  301. data/lib/contrast/utils/thread_tracker.rb +1 -1
  302. data/lib/contrast/utils/timer.rb +1 -1
  303. data/resources/assess/policy.json +60 -2
  304. data/resources/deadzone/policy.json +7 -23
  305. data/ruby-agent.gemspec +22 -20
  306. data/service_executables/VERSION +1 -1
  307. data/service_executables/linux/contrast-service +0 -0
  308. data/service_executables/mac/contrast-service +0 -0
  309. data/sonar-project.properties +9 -0
  310. metadata +94 -50
  311. data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +0 -38
  312. data/lib/contrast/agent/railtie.rb +0 -31
  313. data/lib/contrast/common_agent_configuration.rb +0 -87
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/policy/trigger/reflected_xss'
@@ -47,8 +47,8 @@ module Contrast
47
47
  TRIGGER
48
48
  end
49
49
 
50
- def apply_custom_trigger context, trigger_node, source, object, ret, *args
51
- custom_trigger_class.send(@trigger_method, context, trigger_node, source, object, ret, *args)
50
+ def apply_custom_trigger trigger_node, source, object, ret, *args
51
+ custom_trigger_class.send(@trigger_method, trigger_node, source, object, ret, *args)
52
52
  end
53
53
 
54
54
  def custom_trigger_class
@@ -104,7 +104,8 @@ module Contrast
104
104
 
105
105
  properties = Contrast::Agent::Assess::Tracker.properties(source)
106
106
  # find the ranges that violate the rule (untrusted, etc)
107
- vulnerable_ranges = ranges_with_all_tags(Contrast::Utils::StringUtils.ret_length(source), properties, required_tags)
107
+ vulnerable_ranges = ranges_with_all_tags(Contrast::Utils::StringUtils.ret_length(source), properties,
108
+ required_tags)
108
109
  # if there aren't any vulnerable ranges, nope out
109
110
  return false if vulnerable_ranges.empty?
110
111
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -35,9 +35,10 @@ module Contrast
35
35
  # https://bitbucket.org/contrastsecurity/assess-specifications/src/master/rules/dataflow/redos.md
36
36
  def regexp_vulnerable? regexp
37
37
  # A pattern is considered vulnerable if it has 2 or more levels of nested multi-matching.
38
- # A level is defined as any set of opening and closing control characters immediately followed by a multi match control character.
39
- # A control character is defined as one of the OPENING_CHARS, CLOSING_CHARS,
40
- # or MULTI_MATCH_CHARS that is not immediately preceded by an escaping \ character.
38
+ # A level is defined as any set of opening and closing control characters immediately followed by a
39
+ # multi match control character.
40
+ # A control character is defined as one of the OPENING_CHARS, CLOSING_CHARS, or MULTI_MATCH_CHARS that
41
+ # is not immediately preceded by an escaping \ character.
41
42
  # OPENING_CHARS are ( and [ CLOSING_CHARS are ) and ] MULTI_MATCH_CHARS are +, *, and ?
42
43
 
43
44
  # Nota bene about Regexp#to_s: it doesn't necessarily give you the original Regexp back
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -10,8 +10,7 @@ module Contrast
10
10
  # before serializing that finding as a DTM to report to the service.
11
11
  module SSRFValidator
12
12
  RULE_NAME = 'ssrf'
13
- URL_PATTERN =
14
- %r{(?<protocol>http|https|ftp|sftp|telnet|gopher|rtsp|rtsps|ssh|svn)://(?<host>[^/?]+)(?<path>/?[^?]*)(?<query_string>\?.*)?}i.cs__freeze
13
+ URL_PATTERN = %r{(?<protocol>http|https|ftp|sftp|telnet|gopher|rtsp|rtsps|ssh|svn)://(?<host>[^/?]+)(?<path>/?[^?]*)(?<query_string>\?.*)?}i.cs__freeze # rubocop:disable Layout/LineLength
15
14
  # The Net::HTTP class validates host format on instantiation. Since
16
15
  # our triggers for that class are on the instance, they already
17
16
  # have this validation done for them. We do not need to apply the
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/policy/trigger_validation/ssrf_validator'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -11,14 +11,7 @@ module Contrast
11
11
  # the service.
12
12
  module XSSValidator
13
13
  RULE_NAME = 'reflected-xss'
14
- SAFE_CONTENT_TYPES = %w[
15
- /csv
16
- /javascript
17
- /json
18
- /pdf
19
- /x-javascript
20
- /x-json
21
- ].cs__freeze
14
+ SAFE_CONTENT_TYPES = %w[/csv /javascript /json /pdf /x-javascript /x-json].cs__freeze
22
15
 
23
16
  # A finding is valid for XSS if the response type is not one of
24
17
  # those assumed to be safe
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'base64'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/events/event_factory'
@@ -14,7 +14,7 @@ module Contrast
14
14
  # @attr_reader event [Contrast::Agent::Assess::ContrastEvent] the
15
15
  # latest event to track
16
16
  module Evented
17
- attr_accessor :event
17
+ attr_reader :event
18
18
 
19
19
  # Create a new event and add it to the event set.
20
20
  #
@@ -31,7 +31,8 @@ module Contrast
31
31
  # the key used to accessed if from a map or nil if a type like
32
32
  # BODY
33
33
  def build_event policy_node, tagged, object, ret, args, source_type = nil, source_name = nil
34
- @event = Contrast::Agent::Assess::Events::EventFactory.build(policy_node, tagged, object, ret, args, source_type, source_name)
34
+ @event = Contrast::Agent::Assess::Events::EventFactory.build(policy_node, tagged, object, ret, args,
35
+ source_type, source_name)
35
36
  report_sources(tagged, event)
36
37
  end
37
38
 
@@ -46,10 +47,12 @@ module Contrast
46
47
  return unless tagged && !tagged.to_s.empty?
47
48
  return unless event.cs__is_a?(Contrast::Agent::Assess::Events::SourceEvent)
48
49
  return unless event.source_type
50
+ return unless (current_request = Contrast::Agent::REQUEST_TRACKER.current)
51
+
52
+ if current_request.observed_route.sources.any? do |source|
53
+ source.type == event.forced_source_type && source.name == event.forced_source_name
54
+ end
49
55
 
50
- current_request = Contrast::Agent::REQUEST_TRACKER.current
51
- return unless current_request
52
- if current_request.observed_route.sources.any? { |source| source.type == event.forced_source_type && source.name == event.forced_source_name }
53
56
  return
54
57
  end
55
58
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/tag'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/utils/duck_utils'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -55,9 +55,12 @@ module Contrast
55
55
  value_node.children.each do |child|
56
56
  next unless child
57
57
 
58
- return false unless child.cs__is_a?(RubyVM::AbstractSyntaxTree::Node) &&
59
- child.type == :LIT &&
60
- child.children[0]&.cs__is_a?(Integer)
58
+ unless child.cs__is_a?(RubyVM::AbstractSyntaxTree::Node) &&
59
+ child.type == :LIT &&
60
+ child.children[0]&.cs__is_a?(Integer)
61
+
62
+ return false
63
+ end
61
64
  end
62
65
 
63
66
  true
@@ -84,8 +87,11 @@ module Contrast
84
87
  return false unless children.length >= 2
85
88
 
86
89
  potential_string_node = children[0]
87
- return false unless potential_string_node.cs__is_a?(RubyVM::AbstractSyntaxTree::Node) &&
88
- potential_string_node.type == :STR
90
+ unless potential_string_node.cs__is_a?(RubyVM::AbstractSyntaxTree::Node) &&
91
+ potential_string_node.type == :STR
92
+
93
+ return false
94
+ end
89
95
 
90
96
  children[1] == :bytes
91
97
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -29,7 +29,10 @@ module Contrast
29
29
  # These are markers whose presence indicates that a field is more
30
30
  # likely to be a descriptor or requirement than an actual password.
31
31
  # We should ignore fields that contain them.
32
- NON_PASSWORD_PARTIAL_NAMES = %w[DATE FORGOT FORM ENCODE PATTERN PREFIX PROP SUFFIX URL BASE FILE URI].cs__freeze
32
+ NON_PASSWORD_PARTIAL_NAMES = %w[
33
+ DATE FORGOT FORM ENCODE PATTERN PREFIX PROP SUFFIX URL BASE FILE
34
+ URI
35
+ ].cs__freeze
33
36
 
34
37
  # If the constant looks like a password and it doesn't look like a
35
38
  # password descriptor, it passes for this rule
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/policy/trigger_method'
@@ -26,10 +26,7 @@ module Contrast
26
26
  end
27
27
 
28
28
  # TODO: RUBY-1014 - remove `#analyze`
29
- COMMON_CONSTANTS = %i[
30
- CONTRAST_ASSESS_POLICY_STATUS
31
- VERSION
32
- ].cs__freeze
29
+ COMMON_CONSTANTS = %i[CONTRAST_ASSESS_POLICY_STATUS VERSION].cs__freeze
33
30
  def analyze clazz
34
31
  return if disabled?
35
32
 
@@ -171,7 +168,8 @@ module Contrast
171
168
 
172
169
  finding.properties[SOURCE_KEY] = Contrast::Utils::StringUtils.protobuf_safe_string(class_name)
173
170
  finding.properties[CONSTANT_NAME_KEY] = Contrast::Utils::StringUtils.protobuf_safe_string(constant_string)
174
- finding.properties[CODE_SOURCE_KEY] = Contrast::Utils::StringUtils.protobuf_safe_string(constant_string + redacted_marker)
171
+ finding.properties[CODE_SOURCE_KEY] =
172
+ Contrast::Utils::StringUtils.protobuf_safe_string(constant_string + redacted_marker)
175
173
 
176
174
  hash = Contrast::Utils::HashDigest.generate_class_scanning_hash(finding)
177
175
  finding.hash_code = Contrast::Utils::StringUtils.protobuf_safe_string(hash)
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/finalizers/hash'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/interface'
@@ -1,6 +1,8 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ return unless RUBY_VERSION < '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5
5
+
4
6
  require 'ripper'
5
7
  require 'contrast/extension/module'
6
8
  require 'contrast/components/interface'
@@ -48,7 +50,7 @@ module Contrast
48
50
  :public_instance_methods, :protected_instance_methods, :private_instance_methods, :locations
49
51
 
50
52
  def initialize module_data
51
- @class_module_path = module_data.name
53
+ @class_module_path = module_data.mod_name
52
54
  clazz = module_data.mod
53
55
  @is_class = clazz.is_a?(Class)
54
56
  @public_instance_methods = []
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/patching/policy/policy_node'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/deadzone/policy/deadzone_node'
@@ -8,8 +8,8 @@ module Contrast
8
8
  module Agent
9
9
  module Deadzone
10
10
  module Policy
11
- # This is just a holder for our policy. Takes the policy JSON and
12
- # converts it into hashes that we can access nicely
11
+ # This is just a holder for our policy. Takes the policy JSON and converts it into hashes that we can access
12
+ # nicely.
13
13
  class Policy < Contrast::Agent::Patching::Policy::Policy
14
14
  def self.policy_folder
15
15
  'deadzone'
@@ -35,6 +35,10 @@ module Contrast
35
35
  end
36
36
  end
37
37
 
38
+ def module_names
39
+ @_module_names ||= Set.new(deadzones.map(&:class_name))
40
+ end
41
+
38
42
  def add_node node, _node_type = :deadzones
39
43
  unless node
40
44
  logger.error('Node was nil when adding node to policy')
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/interface'
@@ -13,9 +13,7 @@ module Contrast
13
13
  access_component :agent, :logging
14
14
 
15
15
  def self.run _reaction, level
16
- logger.with_level(
17
- level,
18
- 'Contrast received instructions to disable itself - Disabling now')
16
+ logger.with_level(level, 'Contrast received instructions to disable itself - Disabling now')
19
17
  AGENT.disable!
20
18
  end
21
19
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/interface'
@@ -47,7 +47,7 @@ module Contrast
47
47
  return if @wildcard_url
48
48
  return unless @exclusion.urls&.any?
49
49
 
50
- @wildcard_url ||= @exclusion.urls.any? { |test| test == '/.*' }
50
+ @wildcard_url ||= @exclusion.urls.any?('/.*')
51
51
  return if @wildcard_url
52
52
 
53
53
  @urls = []
@@ -95,8 +95,8 @@ module Contrast
95
95
  @exclusion.type == Contrast::Api::Settings::Exclusion::ExclusionType::CODE
96
96
  end
97
97
 
98
- def name
99
- @exclusion.name
98
+ def exc_name
99
+ @exclusion.name # rubocop:disable Security/Module/Name -- part of the API.
100
100
  end
101
101
 
102
102
  def match_all?
@@ -109,10 +109,7 @@ module Contrast
109
109
  #
110
110
  # @param rule - the id of the rule which we're checking for exclusion
111
111
  def protection_rule? rule
112
- protect? &&
113
- (@exclusion.protection_rules.empty? ||
114
- @exclusion.protection_rules.include?(rule)
115
- )
112
+ protect? && (@exclusion.protection_rules.empty? || @exclusion.protection_rules.include?(rule))
116
113
  end
117
114
 
118
115
  # Determine if the given rule is excluded by this exclusion.
@@ -121,10 +118,7 @@ module Contrast
121
118
  #
122
119
  # @param rule - the id of the rule which we're checking for exclusion
123
120
  def assess_rule? rule
124
- assess? &&
125
- (@exclusion.assessment_rules.empty? ||
126
- @exclusion.assessment_rules.include?(rule)
127
- )
121
+ assess? && (@exclusion.assessment_rules.empty? || @exclusion.assessment_rules.include?(rule))
128
122
  end
129
123
 
130
124
  def match_code? stack_trace
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -10,6 +10,5 @@ module Contrast
10
10
  end
11
11
 
12
12
  require 'contrast/agent/inventory/dependencies'
13
- require 'contrast/agent/inventory/gemfile_digest_cache'
14
13
  require 'contrast/agent/inventory/dependency_usage_analysis'
15
14
  require 'contrast/agent/inventory/dependency_analysis'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Contrast
@@ -33,6 +33,7 @@ module Contrast
33
33
  # then contrast depends on it. If its array of dependents is 1, then contrast is the
34
34
  # only dependency in that list. Since only contrast depends on it, we should ignore it.
35
35
  def find_contrast_gems
36
+ # rubocop:disable Security/Module/Name -- here name is part of Ruby Gems.
36
37
  ignore = Set.new([CONTRAST_AGENT])
37
38
  contrast_specs = Gem::DependencyList.from_specs.specs.find do |dependency|
38
39
  dependency.name == CONTRAST_AGENT
@@ -43,6 +44,7 @@ module Contrast
43
44
  ignore.add(dependency.name) if contrast_dep_set.include?(dependency.name) && dependents.length == 1
44
45
  end
45
46
  ignore
47
+ # rubocop:enable Security/Module/Name
46
48
  end
47
49
  end
48
50
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/inventory/dependencies'
@@ -1,10 +1,10 @@
1
- # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
1
+ # Copyright (c) 2021 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/inventory/gemfile_digest_cache'
5
4
  require 'contrast/agent/inventory/dependencies'
6
5
  require 'contrast/components/interface'
7
6
  require 'contrast/utils/object_share'
7
+ require 'set'
8
8
 
9
9
  module Contrast
10
10
  module Agent
@@ -20,33 +20,35 @@ module Contrast
20
20
  def initialize
21
21
  return unless enabled?
22
22
 
23
- @gemdigest_cache = Contrast::Agent::Inventory::GemfileDigestCache.new
23
+ @lock = Mutex.new
24
+ @lock.synchronize { @gemdigest_cache = Hash.new { |hash, key| hash[key] = Set.new } }
24
25
  end
25
26
 
26
- # This method is invoked once, along with the rest of our catchup code
27
- # to report libraries and their associated files that have already been loaded pre-contrast
27
+ # This method is invoked once, along with the rest of our catchup code to report libraries and their associated
28
+ # files that have already been loaded pre-contrast.
28
29
  def catchup
29
30
  return unless enabled?
30
31
 
31
32
  loaded_specs.each do |_name, spec|
32
- # Get a digest of the Gem file itself
33
+ # Get a digest of the Gem file itself.
33
34
  next unless (digest = Contrast::Utils::Sha256Builder.instance.build_from_spec(spec))
34
35
 
35
- @gemdigest_cache.use_cache(digest) do |existing_files|
36
- loaded_files_from_gem = $LOADED_FEATURES.select { |f| f.start_with?(spec.full_gem_path) }
37
- loaded_files_from_gem.each do |file_path|
38
- logger.trace('Recording loaded file for inventory analysis', line: file_path)
39
- existing_files << adjust_path_for_reporting(file_path, spec)
40
- end
36
+ loaded_files_from_gem = $LOADED_FEATURES.select { |f| f.start_with?(spec.full_gem_path) }
37
+
38
+ new_files = loaded_files_from_gem.each_with_object(Set.new) do |file_path, set|
39
+ set << adjust_path_for_reporting(file_path, spec)
40
+ logger.trace('Recording loaded file for inventory analysis', line: file_path)
41
41
  end
42
+
43
+ # Even if new_files is empty, still need to add digest key for library discovery.
44
+ @lock.synchronize { @gemdigest_cache[digest].merge(new_files) }
42
45
  end
43
46
  end
44
47
 
45
- # This method is invoked once per TracePoint :end - to map a specific
46
- # file being required to the gem it belongs to
48
+ # This method is invoked once per TracePoint :end - to map a specific file being required to the gem to which
49
+ # it belongs.
47
50
  #
48
- # @param path [String] the result of TracePoint#path from the :end
49
- # event in which the Module was defined
51
+ # @param path [String] the result of TracePoint#path from the :end event in which the Module was defined.
50
52
  def associate_file path
51
53
  return unless enabled?
52
54
 
@@ -64,21 +66,31 @@ module Contrast
64
66
  return
65
67
  end
66
68
  report_path = adjust_path_for_reporting(path, spec)
67
- @gemdigest_cache.get(digest) << report_path
69
+ @lock.synchronize { @gemdigest_cache[digest] << report_path }
68
70
  rescue StandardError => e
69
71
  logger.error('Unable to inventory file path', e, path: path)
70
72
  end
71
73
 
72
- # Populate the library_usages filed of the Activity message using the
73
- # data stored in the @gemdigest_cache
74
+ # Populate the library_usages field of the Activity message using the data stored in the @gemdigest_cache.
74
75
  #
75
- # @param activity [Contrast::Api::Dtm::Activity] the message to which
76
- # to append the usage data
76
+ # @param activity [Contrast::Api::Dtm::Activity] the message to which to append the usage data
77
77
  def generate_library_usage activity
78
78
  return unless enabled?
79
- return if @gemdigest_cache.empty?
79
+ return unless activity
80
+
81
+ # Copy gemdigest_cache and clear it in sync.
82
+ gem_spec_digest_to_files = @lock.synchronize do
83
+ copy = @gemdigest_cache.dup
84
+ @gemdigest_cache.clear
85
+ copy
86
+ end
80
87
 
81
- @gemdigest_cache.generate_usage_data(activity)
88
+ gem_spec_digest_to_files.each_pair do |digest, files|
89
+ usage = Contrast::Api::Dtm::LibraryUsageUpdate.build(digest, files)
90
+ activity.library_usages[usage.hash_code] = usage
91
+ end
92
+ rescue StandardError => e
93
+ logger.error('Unable to generate library usage.', e)
82
94
  end
83
95
 
84
96
  private