contrast-agent 4.4.1 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (314) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.gitmodules +1 -1
  4. data/.simplecov +2 -1
  5. data/Gemfile +1 -1
  6. data/LICENSE.txt +1 -1
  7. data/Rakefile +2 -3
  8. data/exe/contrast_service +1 -1
  9. data/ext/build_funchook.rb +4 -4
  10. data/ext/cs__assess_active_record_named/cs__active_record_named.c +1 -1
  11. data/ext/cs__assess_active_record_named/extconf.rb +1 -1
  12. data/ext/cs__assess_array/cs__assess_array.c +1 -1
  13. data/ext/cs__assess_array/extconf.rb +1 -1
  14. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +1 -1
  15. data/ext/cs__assess_basic_object/extconf.rb +1 -1
  16. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  17. data/ext/cs__assess_fiber_track/extconf.rb +1 -1
  18. data/ext/cs__assess_hash/cs__assess_hash.c +4 -2
  19. data/ext/cs__assess_hash/extconf.rb +1 -1
  20. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
  21. data/ext/cs__assess_kernel/extconf.rb +1 -1
  22. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +1 -1
  23. data/ext/cs__assess_marshal_module/extconf.rb +1 -1
  24. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  25. data/ext/cs__assess_module/extconf.rb +1 -1
  26. data/ext/cs__assess_regexp/cs__assess_regexp.c +1 -1
  27. data/ext/cs__assess_regexp/extconf.rb +1 -1
  28. data/ext/cs__assess_string/cs__assess_string.c +1 -1
  29. data/ext/cs__assess_string/extconf.rb +1 -1
  30. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -1
  31. data/ext/cs__assess_string_interpolation26/extconf.rb +1 -1
  32. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -1
  33. data/ext/cs__assess_yield_track/extconf.rb +1 -1
  34. data/ext/cs__common/cs__common.c +5 -5
  35. data/ext/cs__common/cs__common.h +4 -4
  36. data/ext/cs__common/extconf.rb +1 -1
  37. data/ext/cs__contrast_patch/cs__contrast_patch.c +22 -25
  38. data/ext/cs__contrast_patch/extconf.rb +1 -1
  39. data/ext/cs__protect_kernel/cs__protect_kernel.c +1 -1
  40. data/ext/cs__protect_kernel/extconf.rb +1 -1
  41. data/ext/extconf_common.rb +2 -6
  42. data/lib/contrast-agent.rb +1 -1
  43. data/lib/contrast.rb +44 -15
  44. data/lib/contrast/agent.rb +1 -3
  45. data/lib/contrast/agent/assess.rb +2 -2
  46. data/lib/contrast/agent/assess/contrast_event.rb +54 -72
  47. data/lib/contrast/agent/assess/contrast_object.rb +3 -3
  48. data/lib/contrast/agent/assess/events/event_factory.rb +3 -2
  49. data/lib/contrast/agent/assess/events/source_event.rb +7 -2
  50. data/lib/contrast/agent/assess/finalizers/freeze.rb +1 -1
  51. data/lib/contrast/agent/assess/finalizers/hash.rb +28 -38
  52. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +24 -20
  53. data/lib/contrast/agent/assess/policy/patcher.rb +17 -22
  54. data/lib/contrast/agent/assess/policy/policy.rb +2 -2
  55. data/lib/contrast/agent/assess/policy/policy_node.rb +26 -34
  56. data/lib/contrast/agent/assess/policy/policy_scanner.rb +4 -6
  57. data/lib/contrast/agent/assess/policy/preshift.rb +8 -6
  58. data/lib/contrast/agent/assess/policy/propagation_method.rb +12 -25
  59. data/lib/contrast/agent/assess/policy/propagation_node.rb +20 -9
  60. data/lib/contrast/agent/assess/policy/propagator.rb +2 -1
  61. data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -1
  62. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/propagator/center.rb +3 -2
  64. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  65. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +4 -7
  66. data/lib/contrast/agent/assess/policy/propagator/insert.rb +4 -2
  67. data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -1
  68. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
  69. data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -1
  70. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -1
  71. data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
  72. data/lib/contrast/agent/assess/policy/propagator/remove.rb +23 -19
  73. data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -1
  74. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -1
  75. data/lib/contrast/agent/assess/policy/propagator/select.rb +3 -13
  76. data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
  77. data/lib/contrast/agent/assess/policy/propagator/split.rb +13 -14
  78. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -11
  79. data/lib/contrast/agent/assess/policy/propagator/trim.rb +64 -45
  80. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +14 -11
  81. data/lib/contrast/agent/assess/policy/source_method.rb +97 -86
  82. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  83. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +8 -6
  84. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +2 -4
  85. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -3
  86. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +7 -11
  87. data/lib/contrast/agent/assess/policy/trigger_method.rb +104 -77
  88. data/lib/contrast/agent/assess/policy/trigger_node.rb +6 -5
  89. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +5 -4
  90. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -3
  91. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +1 -1
  92. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +2 -9
  93. data/lib/contrast/agent/assess/properties.rb +1 -1
  94. data/lib/contrast/agent/assess/property/evented.rb +9 -6
  95. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  96. data/lib/contrast/agent/assess/property/updated.rb +1 -1
  97. data/lib/contrast/agent/assess/rule/provider.rb +1 -1
  98. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +12 -6
  99. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +5 -2
  100. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +8 -10
  101. data/lib/contrast/agent/assess/tag.rb +1 -1
  102. data/lib/contrast/agent/assess/tracker.rb +1 -1
  103. data/lib/contrast/agent/at_exit_hook.rb +4 -4
  104. data/lib/contrast/agent/class_reopener.rb +10 -7
  105. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  106. data/lib/contrast/agent/deadzone/policy/policy.rb +7 -3
  107. data/lib/contrast/agent/disable_reaction.rb +5 -8
  108. data/lib/contrast/agent/exclusion_matcher.rb +8 -15
  109. data/lib/contrast/agent/inventory.rb +1 -2
  110. data/lib/contrast/agent/inventory/dependencies.rb +3 -1
  111. data/lib/contrast/agent/inventory/dependency_analysis.rb +3 -7
  112. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +38 -28
  113. data/lib/contrast/agent/inventory/policy/datastores.rb +4 -5
  114. data/lib/contrast/agent/inventory/policy/policy.rb +2 -2
  115. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  116. data/lib/contrast/agent/middleware.rb +52 -80
  117. data/lib/contrast/agent/module_data.rb +4 -4
  118. data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
  119. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +10 -10
  120. data/lib/contrast/agent/patching/policy/method_policy.rb +7 -3
  121. data/lib/contrast/agent/patching/policy/module_policy.rb +15 -8
  122. data/lib/contrast/agent/patching/policy/patch.rb +32 -38
  123. data/lib/contrast/agent/patching/policy/patch_status.rb +7 -8
  124. data/lib/contrast/agent/patching/policy/patcher.rb +29 -28
  125. data/lib/contrast/agent/patching/policy/policy.rb +16 -25
  126. data/lib/contrast/agent/patching/policy/policy_node.rb +17 -8
  127. data/lib/contrast/agent/patching/policy/trigger_node.rb +22 -9
  128. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +2 -2
  129. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  130. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  131. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -4
  132. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  133. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +6 -10
  134. data/lib/contrast/agent/protect/policy/policy.rb +2 -2
  135. data/lib/contrast/agent/protect/policy/rule_applicator.rb +8 -10
  136. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  137. data/lib/contrast/agent/protect/rule.rb +1 -1
  138. data/lib/contrast/agent/protect/rule/base.rb +26 -40
  139. data/lib/contrast/agent/protect/rule/base_service.rb +10 -6
  140. data/lib/contrast/agent/protect/rule/cmd_injection.rb +19 -24
  141. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  142. data/lib/contrast/agent/protect/rule/deserialization.rb +7 -14
  143. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +4 -15
  144. data/lib/contrast/agent/protect/rule/no_sqli.rb +7 -3
  145. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +2 -4
  146. data/lib/contrast/agent/protect/rule/path_traversal.rb +7 -11
  147. data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
  148. data/lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb +1 -1
  149. data/lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb +1 -1
  150. data/lib/contrast/agent/protect/rule/sqli/postgres_sql_scanner.rb +2 -2
  151. data/lib/contrast/agent/protect/rule/sqli/sqlite_sql_scanner.rb +1 -1
  152. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -2
  153. data/lib/contrast/agent/protect/rule/xss.rb +2 -2
  154. data/lib/contrast/agent/protect/rule/xxe.rb +6 -13
  155. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -3
  156. data/lib/contrast/agent/reaction_processor.rb +14 -14
  157. data/lib/contrast/agent/request.rb +29 -27
  158. data/lib/contrast/agent/request_context.rb +20 -30
  159. data/lib/contrast/agent/request_handler.rb +6 -4
  160. data/lib/contrast/agent/response.rb +3 -4
  161. data/lib/contrast/agent/rewriter.rb +10 -7
  162. data/lib/contrast/agent/rule_set.rb +6 -5
  163. data/lib/contrast/agent/scope.rb +1 -1
  164. data/lib/contrast/agent/service_heartbeat.rb +5 -7
  165. data/lib/contrast/agent/static_analysis.rb +7 -6
  166. data/lib/contrast/agent/thread.rb +3 -5
  167. data/lib/contrast/agent/thread_watcher.rb +4 -5
  168. data/lib/contrast/agent/tracepoint_hook.rb +6 -6
  169. data/lib/contrast/agent/version.rb +2 -2
  170. data/lib/contrast/agent/worker_thread.rb +1 -1
  171. data/lib/contrast/api.rb +1 -1
  172. data/lib/contrast/api/communication.rb +1 -1
  173. data/lib/contrast/api/communication/connection_status.rb +1 -1
  174. data/lib/contrast/api/communication/messaging_queue.rb +5 -6
  175. data/lib/contrast/api/communication/response_processor.rb +13 -15
  176. data/lib/contrast/api/communication/service_lifecycle.rb +10 -7
  177. data/lib/contrast/api/communication/socket.rb +1 -1
  178. data/lib/contrast/api/communication/socket_client.rb +23 -32
  179. data/lib/contrast/api/communication/speedracer.rb +10 -15
  180. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  181. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  182. data/lib/contrast/api/decorators.rb +1 -1
  183. data/lib/contrast/api/decorators/address.rb +3 -4
  184. data/lib/contrast/api/decorators/agent_startup.rb +8 -10
  185. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  186. data/lib/contrast/api/decorators/application_startup.rb +14 -10
  187. data/lib/contrast/api/decorators/application_update.rb +1 -5
  188. data/lib/contrast/api/decorators/http_request.rb +4 -8
  189. data/lib/contrast/api/decorators/input_analysis.rb +1 -1
  190. data/lib/contrast/api/decorators/instrumentation_mode.rb +35 -0
  191. data/lib/contrast/api/decorators/library.rb +9 -7
  192. data/lib/contrast/api/decorators/library_usage_update.rb +1 -1
  193. data/lib/contrast/api/decorators/message.rb +10 -10
  194. data/lib/contrast/api/decorators/rasp_rule_sample.rb +1 -1
  195. data/lib/contrast/api/decorators/route_coverage.rb +1 -1
  196. data/lib/contrast/api/decorators/server_features.rb +1 -1
  197. data/lib/contrast/api/decorators/trace_event.rb +4 -2
  198. data/lib/contrast/api/decorators/trace_event_object.rb +4 -7
  199. data/lib/contrast/api/decorators/trace_event_signature.rb +1 -1
  200. data/lib/contrast/api/decorators/trace_taint_range.rb +1 -1
  201. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +2 -7
  202. data/lib/contrast/api/decorators/user_input.rb +1 -1
  203. data/lib/contrast/components/agent.rb +20 -26
  204. data/lib/contrast/components/app_context.rb +12 -16
  205. data/lib/contrast/components/assess.rb +20 -25
  206. data/lib/contrast/components/base.rb +40 -0
  207. data/lib/contrast/components/config.rb +3 -4
  208. data/lib/contrast/components/contrast_service.rb +13 -19
  209. data/lib/contrast/components/heap_dump.rb +6 -5
  210. data/lib/contrast/components/inventory.rb +3 -8
  211. data/lib/contrast/components/logger.rb +2 -3
  212. data/lib/contrast/components/protect.rb +14 -20
  213. data/lib/contrast/components/sampling.rb +14 -8
  214. data/lib/contrast/components/scope.rb +2 -5
  215. data/lib/contrast/components/settings.rb +28 -103
  216. data/lib/contrast/config.rb +1 -1
  217. data/lib/contrast/config/agent_configuration.rb +1 -1
  218. data/lib/contrast/config/application_configuration.rb +1 -1
  219. data/lib/contrast/config/assess_configuration.rb +1 -1
  220. data/lib/contrast/config/assess_rules_configuration.rb +2 -4
  221. data/lib/contrast/config/base_configuration.rb +5 -6
  222. data/lib/contrast/config/default_value.rb +1 -1
  223. data/lib/contrast/config/exception_configuration.rb +2 -6
  224. data/lib/contrast/config/heap_dump_configuration.rb +13 -7
  225. data/lib/contrast/config/inventory_configuration.rb +1 -1
  226. data/lib/contrast/config/logger_configuration.rb +2 -6
  227. data/lib/contrast/config/protect_configuration.rb +1 -1
  228. data/lib/contrast/config/protect_rule_configuration.rb +23 -1
  229. data/lib/contrast/config/protect_rules_configuration.rb +1 -1
  230. data/lib/contrast/config/root_configuration.rb +1 -1
  231. data/lib/contrast/config/ruby_configuration.rb +1 -1
  232. data/lib/contrast/config/sampling_configuration.rb +1 -1
  233. data/lib/contrast/config/server_configuration.rb +1 -1
  234. data/lib/contrast/config/service_configuration.rb +1 -1
  235. data/lib/contrast/configuration.rb +7 -19
  236. data/lib/contrast/extension/assess.rb +1 -1
  237. data/lib/contrast/extension/assess/array.rb +4 -11
  238. data/lib/contrast/extension/assess/erb.rb +2 -8
  239. data/lib/contrast/extension/assess/eval_trigger.rb +5 -14
  240. data/lib/contrast/extension/assess/exec_trigger.rb +4 -14
  241. data/lib/contrast/extension/assess/fiber.rb +9 -18
  242. data/lib/contrast/extension/assess/hash.rb +4 -4
  243. data/lib/contrast/extension/assess/kernel.rb +5 -14
  244. data/lib/contrast/extension/assess/marshal.rb +7 -15
  245. data/lib/contrast/extension/assess/regexp.rb +7 -11
  246. data/lib/contrast/extension/assess/string.rb +9 -7
  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 +3 -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 -6
  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 +7 -12
  257. data/lib/contrast/framework/platform_version.rb +1 -1
  258. data/lib/contrast/framework/rack/patch/session_cookie.rb +12 -25
  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 +13 -10
  263. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +4 -4
  264. data/lib/contrast/framework/rails/patch/support.rb +42 -36
  265. data/lib/contrast/framework/rails/railtie.rb +34 -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 +6 -5
  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 +6 -9
  273. data/lib/contrast/logger/application.rb +14 -16
  274. data/lib/contrast/logger/format.rb +3 -6
  275. data/lib/contrast/logger/log.rb +27 -10
  276. data/lib/contrast/logger/request.rb +2 -7
  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 +7 -8
  281. data/lib/contrast/utils/assess/sampling_util.rb +3 -4
  282. data/lib/contrast/utils/assess/tracking_util.rb +4 -7
  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 +6 -4
  288. data/lib/contrast/utils/invalid_configuration_util.rb +5 -4
  289. data/lib/contrast/utils/inventory_util.rb +3 -4
  290. data/lib/contrast/utils/io_util.rb +4 -6
  291. data/lib/contrast/utils/job_servers_running.rb +14 -8
  292. data/lib/contrast/utils/object_share.rb +1 -1
  293. data/lib/contrast/utils/os.rb +5 -5
  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 +3 -4
  300. data/lib/contrast/utils/tag_util.rb +26 -20
  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 -17
  305. data/ruby-agent.gemspec +25 -21
  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 +108 -51
  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
  314. data/lib/contrast/components/interface.rb +0 -195
@@ -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/method_policy'
@@ -27,6 +27,9 @@ module Contrast
27
27
  class_name = klass.cs__name
28
28
  instance_methods = klass.instance_methods
29
29
  instance_methods.concat(klass.private_instance_methods)
30
+ current_context = Contrast::Agent::REQUEST_TRACKER.current
31
+ current_request = current_context&.request
32
+
30
33
  tainted_columns.each_pair do |field, properties|
31
34
  next unless properties
32
35
 
@@ -34,14 +37,14 @@ module Contrast
34
37
  # Move on if we already know about this Dynamic Source
35
38
  next if Contrast::Agent::Assess::Policy::Policy.instance.find_source_node(class_name, method_name, true)
36
39
 
37
- dynamic_source_node = create_source_node(class_name, method_name, Set.new(properties.tag_keys))
40
+ dynamic_source_node = create_source_node(class_name, method_name, Set.new(properties.tag_keys),
41
+ current_request)
38
42
  Contrast::Agent::Assess::Policy::Policy.instance.add_node(dynamic_source_node, :dynamic_source)
39
43
  method_policy = build_source_policy(method_name, dynamic_source_node)
40
44
  Contrast::Agent::Patching::Policy::Patcher.patch_method(klass, instance_methods, method_policy)
41
- current_context = Contrast::Agent::REQUEST_TRACKER.current
42
45
  next unless current_context
43
46
 
44
- dynamic_source = create_dynamic_source(current_context, dynamic_source_node, field, properties)
47
+ dynamic_source = create_dynamic_source(current_request, dynamic_source_node, field, properties)
45
48
  node_id = Contrast::Utils::StringUtils.force_utf8(dynamic_source_node.id)
46
49
  current_context.activity.dynamic_sources[node_id] = dynamic_source
47
50
  end
@@ -56,8 +59,10 @@ module Contrast
56
59
  # @param class_name [String] the name of the Class to patch
57
60
  # @param method_name [Symbol] the name of the Method to patch
58
61
  # @param tags [Set<String>] the tags this event should apply
62
+ # @param request [Contrast::Agent::Request] the request during
63
+ # which this source is to be created.
59
64
  # @return [Contrast::Agent::Assess::Policy::SourceNode]
60
- def create_source_node class_name, method_name, tags
65
+ def create_source_node class_name, method_name, tags, request
61
66
  node = Contrast::Agent::Assess::Policy::SourceNode.new
62
67
  node.class_name = class_name
63
68
  node.instance_method = true
@@ -72,8 +77,7 @@ module Contrast
72
77
  node.add_property(READ_TABLE, class_name)
73
78
  node.add_property(READ_COLUMN, method_name)
74
79
  node.add_property(WRITE_QUERY_TIME, Contrast::Utils::Timer.now_ms)
75
- url = Contrast::Agent::REQUEST_TRACKER.current&.request&.normalized_uri
76
- node.add_property(WRITE_QUERY_URL, url)
80
+ node.add_property(WRITE_QUERY_URL, request&.normalized_uri)
77
81
  node
78
82
  end
79
83
 
@@ -92,8 +96,8 @@ module Contrast
92
96
  method_policy
93
97
  end
94
98
 
95
- # @param current_context [Contrast::Agent::RequestContext] the
96
- # context of the request in which this source is to be created.
99
+ # @param request [Contrast::Agent::Request] the request during
100
+ # which this source is to be created.
97
101
  # @param source_node [Contrast::Agent::Assess::Policy::SourceNode]
98
102
  # the SourceNode that applies to this method
99
103
  # @param field [String] the name of the method to which this source
@@ -104,13 +108,13 @@ module Contrast
104
108
  # @return [Contrast::Api::Dtm::DynamicSource] the message to send
105
109
  # to the Service to allow it to report the events leading up to
106
110
  # the creation of the Dynamic Source
107
- def create_dynamic_source current_context, source_node, field, properties
111
+ def create_dynamic_source request, source_node, field, properties
108
112
  dynamic_source = Contrast::Api::Dtm::DynamicSource.new
109
113
  dynamic_source.class_name = Contrast::Utils::StringUtils.force_utf8(source_node.class_name)
110
114
  dynamic_source.method_name = Contrast::Utils::StringUtils.force_utf8(field)
111
115
  dynamic_source.instance_method = source_node.instance_method?
112
116
  dynamic_source.target = Contrast::Utils::StringUtils.force_utf8(source_node.target_string)
113
- append_properties!(dynamic_source, current_context, source_node, field)
117
+ append_properties!(dynamic_source, request, source_node, field)
114
118
  append_events!(dynamic_source, properties.event)
115
119
  dynamic_source
116
120
  end
@@ -119,18 +123,18 @@ module Contrast
119
123
  # in TeamServer
120
124
  #
121
125
  # @param dynamic_source [Contrast::Api::Dtm::DynamicSource] the message to send to the Service to allow it
122
- # to report the events leading up to the creation of the Dynamic Source
123
- # @param current_context [Contrast::Agent::RequestContext] the context of the request in which this source
124
- # is to be created.
126
+ # to report the events leading up to the creation of the Dynamic Source.
127
+ # @param request [Contrast::Agent::Request] the request during which this source is to be created.
125
128
  # @param source_node [Contrast::Agent::Assess::Policy::SourceNode] the SourceNode that applies to this
126
- # method
127
- # @param field [String] the name of the method to which this source applies
128
- def append_properties! dynamic_source, current_context, source_node, field
129
+ # method.
130
+ # @param field [String] the name of the method to which this source applies.
131
+ def append_properties! dynamic_source, request, source_node, field
129
132
  dynamic_source.properties[READ_TABLE] = Contrast::Utils::StringUtils.force_utf8(source_node.class_name)
130
133
  dynamic_source.properties[READ_COLUMN] = Contrast::Utils::StringUtils.force_utf8(field)
131
- dynamic_source.properties[WRITE_QUERY_TIME] = Contrast::Utils::StringUtils.force_utf8(Contrast::Utils::Timer.now_ms)
132
- url = current_context.request.normalized_uri
133
- dynamic_source.properties[WRITE_QUERY_URL] = Contrast::Utils::StringUtils.force_utf8(url)
134
+ dynamic_source.properties[WRITE_QUERY_TIME] =
135
+ Contrast::Utils::StringUtils.force_utf8(Contrast::Utils::Timer.now_ms)
136
+ dynamic_source.properties[WRITE_QUERY_URL] =
137
+ Contrast::Utils::StringUtils.force_utf8(request&.normalized_uri)
134
138
  end
135
139
 
136
140
  def append_events! dynamic_source, event
@@ -1,11 +1,12 @@
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/policy'
5
5
  require 'contrast/agent/patching/policy/patcher'
6
6
  require 'contrast/agent/patching/policy/method_policy'
7
7
  require 'contrast/agent/patching/policy/module_policy'
8
- require 'contrast/components/interface'
8
+ require 'contrast/components/logger'
9
+ require 'contrast/components/scope'
9
10
 
10
11
  module Contrast
11
12
  module Agent
@@ -16,8 +17,9 @@ module Contrast
16
17
  # provides a map for which methods our renamed functions need to call
17
18
  # and how.
18
19
  module Patcher
19
- include Contrast::Components::Interface
20
- access_component :logging, :analysis, :agent, :scope
20
+ extend Contrast::Components::Logger::InstanceMethods
21
+ extend Contrast::Components::Scope::InstanceMethods
22
+
21
23
 
22
24
  class << self
23
25
  def policy
@@ -34,24 +36,18 @@ module Contrast
34
36
  # called. This hook is provided so that patches to those methods can
35
37
  # pass us execution flow once a new method has been made available.
36
38
  def patch_assess_on_eval mod
37
- return unless ASSESS.enabled?
39
+ return unless ::Contrast::ASSESS.enabled?
38
40
  return if in_contrast_scope?
39
41
 
40
42
  patcher.patch_specific_module(mod)
41
43
  rescue StandardError => e
42
- logger.warn(
43
- 'Unable to patch assess during eval',
44
- e,
45
- module: mod.cs__name)
44
+ logger.warn('Unable to patch assess during eval', e, module: mod.cs__name)
46
45
  end
47
46
 
48
47
  # Exposed so that methods can be dynamically patched on creation at
49
48
  # runtime, like those generated by
50
49
  # ActiveRecord::AttributeMethods::Read::ClassMethods#define_method_attribute
51
- CLASS_TYPES = [
52
- Contrast::Utils::ObjectShare::CLASS,
53
- Contrast::Utils::ObjectShare::MODULE
54
- ].cs__freeze
50
+ CLASS_TYPES = [Contrast::Utils::ObjectShare::CLASS, Contrast::Utils::ObjectShare::MODULE].cs__freeze
55
51
  def patch_assess_method mod, method_name
56
52
  # Module.define_method is called a lot in Class and Module. We
57
53
  # currently do not expect these define_methods to result in methods
@@ -62,7 +58,8 @@ module Contrast
62
58
  return if CLASS_TYPES.include?(class_name)
63
59
  return unless ASSESS.enabled?
64
60
 
65
- source_nodes = Contrast::Agent::Patching::Policy::ModulePolicy.nodes_for_module(policy.sources, class_name)
61
+ source_nodes = Contrast::Agent::Patching::Policy::ModulePolicy.nodes_for_module(policy.sources,
62
+ class_name)
66
63
  return if source_nodes.empty?
67
64
 
68
65
  method_array = []
@@ -70,17 +67,15 @@ module Contrast
70
67
  source_nodes.each do |source_node|
71
68
  next unless source_node.method_name.to_s == method_name
72
69
 
73
- method_policy = Contrast::Agent::Patching::Policy::MethodPolicy.new(source_node: source_node,
74
- method_name: source_node.method_name,
75
- method_visibility: source_node.method_visibility,
76
- instance_method: true)
70
+ method_policy =
71
+ Contrast::Agent::Patching::Policy::MethodPolicy.new(source_node: source_node,
72
+ method_name: source_node.method_name,
73
+ method_visibility: source_node.method_visibility,
74
+ instance_method: true)
77
75
  patcher.patch_method(mod, method_array, method_policy)
78
76
  end
79
77
  rescue StandardError => e
80
- logger.warn(
81
- 'Unable to patch assess during define_method_attribute',
82
- e,
83
- module: mod.cs__name)
78
+ logger.warn('Unable to patch assess during define_method_attribute', e, module: mod.cs__name)
84
79
  end
85
80
  end
86
81
  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 'json'
@@ -26,7 +26,7 @@ module Contrast
26
26
  # Indicates is this feature has been disabled by the configuration,
27
27
  # read at startup, and therefore can never be enabled.
28
28
  def disabled_globally?
29
- ASSESS.forcibly_disabled?
29
+ ::Contrast::ASSESS.forcibly_disabled?
30
30
  end
31
31
 
32
32
  def node_type
@@ -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'
@@ -35,16 +35,6 @@ module Contrast
35
35
  :TYPE_METHOD
36
36
  end
37
37
 
38
- def target
39
- @_target ||= begin
40
- if targets&.any?
41
- targets[0]
42
- elsif sources&.any?
43
- sources[0]
44
- end
45
- end
46
- end
47
-
48
38
  def target_string= value
49
39
  @target_string = value
50
40
  @targets = convert_policy_markers(value)
@@ -85,8 +75,7 @@ module Contrast
85
75
  next if Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
86
76
  Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
87
77
 
88
- raise(ArgumentError,
89
- "#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
78
+ raise(ArgumentError, "#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
90
79
  end
91
80
  end
92
81
 
@@ -100,27 +89,26 @@ module Contrast
100
89
  # Trigger (trigger nodes) don't have targets (they are the target)
101
90
  # Everything else (propagation nodes) are Source2Target
102
91
  def build_action
103
- @event_action ||= begin
104
- case node_class
105
- when Contrast::Agent::Assess::Policy::SourceNode::SOURCE
106
- :CREATION
107
- when Contrast::Agent::Assess::Policy::TriggerNode::TRIGGER
108
- :TRIGGER
109
- else
110
- if source_string.nil?
111
- :CREATION
112
- elsif target_string.nil?
113
- :TRIGGER
114
- else
115
- # TeamServer can't handle the multi-source or multi-target
116
- # values. Give it some help by changing them to 'A'
117
- source = source_string.include?(Contrast::Utils::ObjectShare::COMMA) ? ALL_TYPE : source_string
118
- target = target_string.include?(Contrast::Utils::ObjectShare::COMMA) ? ALL_TYPE : target_string
119
- str = source[0] + TO_MARKER + target[0]
120
- str.to_sym
121
- end
122
- end
123
- end
92
+ @event_action ||= case node_class
93
+ when Contrast::Agent::Assess::Policy::SourceNode::SOURCE
94
+ :CREATION
95
+ when Contrast::Agent::Assess::Policy::TriggerNode::TRIGGER
96
+ :TRIGGER
97
+ else
98
+ if source_string.nil?
99
+ :CREATION
100
+ elsif target_string.nil?
101
+ :TRIGGER
102
+ else
103
+ # TeamServer can't handle the multi-source or multi-target values. Give it some help
104
+ # by changing them to 'A'
105
+ source = all_type?(source_string) ? ALL_TYPE : source_string
106
+ target = all_type?(target_string) ? ALL_TYPE : target_string
107
+ str = source[0] + TO_MARKER + target[0]
108
+ str.to_sym
109
+ end
110
+ end
111
+
124
112
  @event_action
125
113
  end
126
114
 
@@ -158,6 +146,10 @@ module Contrast
158
146
  end
159
147
  converted
160
148
  end
149
+
150
+ def all_type? marker
151
+ marker.include?(Contrast::Utils::ObjectShare::COMMA)
152
+ end
161
153
  end
162
154
  end
163
155
  end
@@ -1,7 +1,6 @@
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/components/interface'
5
4
  require 'contrast/utils/object_share'
6
5
 
7
6
  module Contrast
@@ -13,8 +12,7 @@ module Contrast
13
12
  # of a file vs data flow, such as the detection of Hardcoded Passwords
14
13
  # or Keys.
15
14
  module PolicyScanner
16
- include Contrast::Components::Interface
17
- access_component :analysis
15
+
18
16
 
19
17
  class << self
20
18
  # Use the given trace_point, built from an :end event, to determine
@@ -24,8 +22,8 @@ module Contrast
24
22
  # @param trace_point [TracePoint] the TracePoint generated by an
25
23
  # :end event at the end of a Module definition.
26
24
  def scan trace_point
27
- return unless ASSESS.enabled?
28
- return unless ASSESS.require_scan?
25
+ return unless ::Contrast::ASSESS.enabled?
26
+ return unless ::Contrast::ASSESS.require_scan?
29
27
 
30
28
  provider_values = policy.providers.values
31
29
  return if provider_values.all?(&:disabled?)
@@ -1,7 +1,7 @@
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/components/interface'
4
+ require 'contrast/components/logger'
5
5
 
6
6
  module Contrast
7
7
  module Agent
@@ -9,8 +9,8 @@ module Contrast
9
9
  # In order to properly shift tags to account for the changes this method
10
10
  # caused, we'll need to store the state before the change occurred.
11
11
  class PreShift
12
- include Contrast::Components::Interface
13
- access_component :analysis, :logging
12
+ include Contrast::Components::Logger::InstanceMethods
13
+
14
14
 
15
15
  UNDUPLICABLE_MODULES = [
16
16
  Enumerator # dup'ing results in 'can't copy execution context'
@@ -37,7 +37,7 @@ module Contrast
37
37
  # being called or nil if one is not required.
38
38
  def build_preshift propagation_node, object, args
39
39
  return unless propagation_node
40
- return unless ASSESS.enabled?
40
+ return unless ::Contrast::ASSESS.enabled?
41
41
 
42
42
  initializing = propagation_node.method_name == :initialize
43
43
  return if unsafe_io_object?(object, initializing)
@@ -91,7 +91,9 @@ module Contrast
91
91
 
92
92
  Contrast::Agent::Assess::Tracker.copy(original_arg, preshift_arg)
93
93
  end
94
- preshift.arg_lengths = preshift.args.map { |preshift_arg| Contrast::Utils::DuckUtils.quacks_to?(preshift_arg, :length) ? preshift_arg.length : 0 }
94
+ preshift.arg_lengths = preshift.args.map do |preshift_arg|
95
+ Contrast::Utils::DuckUtils.quacks_to?(preshift_arg, :length) ? preshift_arg.length : 0
96
+ end
95
97
  end
96
98
  end
97
99
  end
@@ -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
4
  require 'set'
5
5
 
6
6
  require 'contrast/agent/assess/policy/propagator'
7
- require 'contrast/components/interface'
7
+ require 'contrast/components/logger'
8
8
  require 'contrast/utils/object_share'
9
9
  require 'contrast/utils/sha256_builder'
10
10
 
@@ -17,8 +17,8 @@ module Contrast
17
17
  # general, these methods work on the String class or a holder of
18
18
  # Strings
19
19
  module PropagationMethod
20
- include Contrast::Components::Interface
21
- access_component :analysis, :logging
20
+ extend Contrast::Components::Logger::InstanceMethods
21
+
22
22
 
23
23
  APPEND_ACTION = 'APPEND'
24
24
  CENTER_ACTION = 'CENTER'
@@ -86,10 +86,6 @@ module Contrast
86
86
  SPLIT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Split
87
87
  }.cs__freeze
88
88
 
89
- def context_available?
90
- !!Contrast::Agent::REQUEST_TRACKER.current
91
- end
92
-
93
89
  # I lied above. We had to figure out what the target of the
94
90
  # propagation was. Now that we know, we'll actually do things to
95
91
  # it. Note that the return of this method will replace the original
@@ -144,13 +140,7 @@ module Contrast
144
140
  !!target
145
141
  end
146
142
 
147
- ZERO_LENGTH_ACTIONS = [
148
- DB_WRITE_ACTION,
149
- CUSTOM_ACTION,
150
- KEEP_ACTION,
151
- REPLACE_ACTION,
152
- SPLAT_ACTION
153
- ].cs__freeze
143
+ ZERO_LENGTH_ACTIONS = [DB_WRITE_ACTION, CUSTOM_ACTION, KEEP_ACTION, REPLACE_ACTION, SPLAT_ACTION].cs__freeze
154
144
  # If the action required needs a length and the target does not have
155
145
  # one, the length is not valid
156
146
  def valid_length? target, action
@@ -225,7 +215,7 @@ module Contrast
225
215
 
226
216
  # This is checked right before actual propagation
227
217
  def propagation_possible? propagation_node, target
228
- return false unless context_available? && propagation_node && valid_target?(target, propagation_node)
218
+ return false unless propagation_node && valid_target?(target, propagation_node)
229
219
  return false unless valid_length?(target, propagation_node.action)
230
220
 
231
221
  true
@@ -249,7 +239,7 @@ module Contrast
249
239
 
250
240
  def handle_enumerable_propagation propagation_node, preshift, target, object, ret, args, block
251
241
  target.each do |value|
252
- next if target == value # Some Enumerable#each are overridden to return self the first time which leads to infinite propagation
242
+ next if target == value
253
243
 
254
244
  apply_propagator(propagation_node, preshift, value, object, ret, args, block)
255
245
  end
@@ -287,9 +277,7 @@ module Contrast
287
277
 
288
278
  properties.add_properties(propagation_node.properties)
289
279
  properties.build_event(propagation_node, target, object, ret, args)
290
- logger.trace('Propagation detected',
291
- node_id: propagation_node.id,
292
- target_id: target.__id__)
280
+ logger.trace('Propagation detected', node_id: propagation_node.id, target_id: target.__id__)
293
281
  restore_frozen_state ? ret : nil
294
282
  end
295
283
 
@@ -300,10 +288,9 @@ module Contrast
300
288
  # @return [Contrast::Agent::Assess::Policy::Propagator, nil]
301
289
  def find_propagation_class propagation_node
302
290
  unless (propagation_class = PROPAGATION_ACTIONS.fetch(propagation_node.action, nil))
303
- logger.warn(
304
- 'Unknown propagation action received. Unable to propagate.',
305
- node_id: propagation_node.id,
306
- action: propagation_node.action)
291
+ logger.warn('Unknown propagation action received. Unable to propagate.',
292
+ node_id: propagation_node.id,
293
+ action: propagation_node.action)
307
294
  end
308
295
  propagation_class
309
296
  end
@@ -315,7 +302,7 @@ module Contrast
315
302
  # propagation event.
316
303
  # @return [Boolean]
317
304
  def can_handle_frozen? propagation_node
318
- ASSESS.track_frozen_sources? && propagation_node.targets[0] == Contrast::Utils::ObjectShare::RETURN_KEY
305
+ ::Contrast::ASSESS.track_frozen_sources? && propagation_node.targets[0] == Contrast::Utils::ObjectShare::RETURN_KEY
319
306
  end
320
307
  end
321
308
  end