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,8 +1,9 @@
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/propagation_node'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/logger'
6
+ require 'contrast/components/scope'
6
7
 
7
8
  # In order to instrument some difficult methods like String#gsub, as it
8
9
  # returns an enumerator, we need to instrument methods on Fiber.
@@ -16,9 +17,9 @@ module Contrast
16
17
  # Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
17
18
  # Fiber Class or exposing our methods there.
18
19
  class FiberPropagator
19
- include Contrast::Components::Interface
20
+ extend Contrast::Components::Logger::InstanceMethods
21
+ extend Contrast::Components::Scope::InstanceMethods
20
22
 
21
- access_component :analysis, :logging, :scope
22
23
 
23
24
  # we use funchook to patch rb_fiber_new the initialize method is not exposed by Ruby core
24
25
  FIBER_NEW_NODE_HASH = {
@@ -53,7 +54,7 @@ module Contrast
53
54
 
54
55
  class << self
55
56
  def track_rb_fiber_yield fiber, _method, results
56
- return unless ASSESS.enabled?
57
+ return unless ::Contrast::ASSESS.enabled?
57
58
 
58
59
  # results will be nil if StopIteration was raised,
59
60
  # otherwise an Array of the yielded arguments
@@ -64,12 +65,7 @@ module Contrast
64
65
  next unless (result_properties = Contrast::Agent::Assess::Tracker.properties!(result))
65
66
 
66
67
  result_properties.splat_from(fiber, result)
67
- result_properties.build_event(
68
- FIBER_YIELD_NODE,
69
- result,
70
- fiber,
71
- result,
72
- [])
68
+ result_properties.build_event(FIBER_YIELD_NODE, result, fiber, result, [])
73
69
  end
74
70
  end
75
71
  rescue Exception => e # rubocop:disable Lint/RescueException
@@ -77,7 +73,7 @@ module Contrast
77
73
  end
78
74
 
79
75
  def track_rb_fiber_new fiber, _enum, _enum_method, underlying, _underlying_method
80
- return unless ASSESS.enabled?
76
+ return unless ::Contrast::ASSESS.enabled?
81
77
  return unless underlying.is_a?(String) && !underlying.empty?
82
78
 
83
79
  with_contrast_scope do
@@ -85,12 +81,7 @@ module Contrast
85
81
  return unless properties
86
82
 
87
83
  properties.splat_from(underlying, fiber)
88
- properties.build_event(
89
- FIBER_NEW_NODE,
90
- fiber,
91
- underlying,
92
- fiber,
93
- [])
84
+ properties.build_event(FIBER_NEW_NODE, fiber, underlying, fiber, [])
94
85
  end
95
86
  rescue Exception => e # rubocop:disable Lint/RescueException
96
87
  logger.error('Unable to propagate during Fiber.new', e)
@@ -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 Extension
@@ -10,8 +10,8 @@ module Contrast
10
10
  # methods which are too complex to fit into one of the standard
11
11
  # Contrast::Agent::Assess::Policy::Propagator molds.
12
12
  class HashPropagator
13
- include Contrast::Components::Interface
14
- access_component :logging
13
+ include Contrast::Components::Logger::InstanceMethods
14
+
15
15
  class << self
16
16
  def cs__duplicate_and_freeze object
17
17
  return object unless object.is_a?(String) && !object.cs__frozen?
@@ -1,8 +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
- require 'contrast/components/interface'
5
4
  require 'contrast/extension/assess/exec_trigger'
5
+ require 'contrast/components/logger'
6
6
 
7
7
  module Contrast
8
8
  module Extension
@@ -13,11 +13,9 @@ module Contrast
13
13
  # Kernel Module or exposing our methods there.
14
14
  module KernelPropagator
15
15
  class << self
16
- include Contrast::Components::Interface
16
+ extend Contrast::Components::Logger::InstanceMethods
17
17
  include Contrast::Extension::Assess::ExecTrigger
18
18
 
19
- access_component :logging
20
-
21
19
  # We're 'tracking' sprintf now, meaning if anything is tracked on the way
22
20
  # in, the entire result will be tracked out. We're going to take this
23
21
  # approach for now b/c it's fast and easy. I don't super love it, and by
@@ -47,13 +45,7 @@ module Contrast
47
45
  parent_events = []
48
46
  track_sprintf(ret, format_string, args, parent_events)
49
47
 
50
- properties.build_event(
51
- patcher,
52
- ret,
53
- preshift.object,
54
- ret,
55
- preshift.args,
56
- 1)
48
+ properties.build_event(patcher, ret, preshift.object, ret, preshift.args, 1)
57
49
 
58
50
  properties.event.instance_variable_set(:@_parent_events, parent_events)
59
51
  ret
@@ -70,8 +62,7 @@ module Contrast
70
62
  handle_sprintf_array(args, result, parent_events)
71
63
  end
72
64
  rescue StandardError => e
73
- logger.error(
74
- 'Unable to track dataflow through sprintf', e)
65
+ logger.error('Unable to track dataflow through sprintf', e)
75
66
  end
76
67
 
77
68
  def instrument_kernel_track
@@ -1,7 +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
- require 'contrast/components/interface'
4
+ require 'contrast/components/logger'
5
+ require 'contrast/components/scope'
5
6
 
6
7
  module Contrast
7
8
  module Extension
@@ -11,9 +12,8 @@ module Contrast
11
12
  # Hopefully, we'll be in a 'get it right' state soon.
12
13
  # This module is used for our Marshal.load patches
13
14
  class MarshalPropagator
14
- include Contrast::Components::Interface
15
-
16
- access_component :logging, :scope
15
+ extend Contrast::Components::Logger::InstanceMethods
16
+ extend Contrast::Components::Scope::InstanceMethods
17
17
 
18
18
  class << self
19
19
  def cs__load_protect arg
@@ -27,20 +27,12 @@ module Contrast
27
27
 
28
28
  def cs__load_assess source, ret
29
29
  with_contrast_scope do
30
- current_context = Contrast::Agent::REQUEST_TRACKER.current
31
- return unless current_context
32
-
33
30
  args = [source]
34
31
  # source might not be all the args passed in, but it is the one we care
35
32
  # about. we could pass in all the args in the last param here if it
36
33
  # becomes an issue in rendering on TS
37
- Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
38
- current_context,
39
- trigger_node('Marshal', :load),
40
- source,
41
- self,
42
- ret,
43
- *args)
34
+ Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node('Marshal', :load), source,
35
+ self, ret, *args)
44
36
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
45
37
 
46
38
  properties.copy_from(source, ret)
@@ -1,8 +1,9 @@
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/propagation_node'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/logger'
6
+ require 'contrast/components/scope'
6
7
 
7
8
  module Contrast
8
9
  module Extension
@@ -12,9 +13,9 @@ module Contrast
12
13
  # Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
13
14
  # Regexp Class or exposing our methods there.
14
15
  class RegexpPropagator
15
- include Contrast::Components::Interface
16
+ extend Contrast::Components::Logger::InstanceMethods
17
+ extend Contrast::Components::Scope::InstanceMethods
16
18
 
17
- access_component :analysis, :logging, :scope
18
19
 
19
20
  REGEXP_EQUAL_SQUIGGLE_HASH = {
20
21
  'id' => 'regexp_100',
@@ -34,7 +35,7 @@ module Contrast
34
35
 
35
36
  class << self
36
37
  def track_equal_squiggle info_hash
37
- return unless ASSESS.enabled?
38
+ return unless ::Contrast::ASSESS.enabled?
38
39
 
39
40
  # Because we have a special case for this propagation,
40
41
  # it falls out of regular scoping. As such, any patch to the `=~` method
@@ -53,12 +54,7 @@ module Contrast
53
54
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))
54
55
 
55
56
  properties.splat_from(string, target)
56
- properties.build_event(
57
- REGEXP_EQUAL_SQUIGGLE_NODE,
58
- target,
59
- self,
60
- result,
61
- [string])
57
+ properties.build_event(REGEXP_EQUAL_SQUIGGLE_NODE, target, self, result, [string])
62
58
  end
63
59
  rescue Exception => e # rubocop:disable Lint/RescueException
64
60
  logger.error('Unable to propagate during Regexp#=~', e)
@@ -1,8 +1,9 @@
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/propagation_node'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/logger'
6
+ require 'contrast/components/scope'
6
7
 
7
8
  module Contrast
8
9
  module Extension
@@ -12,9 +13,8 @@ module Contrast
12
13
  # Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
13
14
  # String Class or exposing our methods there.
14
15
  class StringPropagator
15
- include Contrast::Components::Interface
16
-
17
- access_component :agent, :analysis, :logging, :scope
16
+ extend Contrast::Components::Logger::InstanceMethods
17
+ extend Contrast::Components::Scope::InstanceMethods
18
18
 
19
19
  NODE_HASH = {
20
20
  'class_name' => 'String',
@@ -31,7 +31,7 @@ module Contrast
31
31
 
32
32
  class << self
33
33
  def track_interpolation inputs, result
34
- return unless AGENT.interpolation_enabled?
34
+ return unless ::Contrast::AGENT.interpolation_enabled?
35
35
  return if in_contrast_scope?
36
36
  return unless inputs.any? { |input| Contrast::Agent::Assess::Tracker.tracked?(input) }
37
37
 
@@ -66,7 +66,9 @@ module Contrast
66
66
  def instrument_string_interpolation
67
67
  if @_instrument_string_interpolation.nil?
68
68
  @_instrument_string_interpolation = begin
69
- require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26' if AGENT.patch_interpolation? && Funchook.available?
69
+ if ::Contrast::AGENT.patch_interpolation? && Funchook.available?
70
+ require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26'
71
+ end
70
72
  true
71
73
  rescue StandardError, LoadError => e
72
74
  logger.error('Error loading interpolation patch', e)
@@ -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
  # Some developers override various methods on Delegator, which can often
@@ -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/components/scope'
@@ -41,13 +41,13 @@ module Kernel # :nodoc:
41
41
 
42
42
  def catch *args, &block
43
43
  # Save current scope level
44
- scope_level = Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_get(:@contrast_scope)
44
+ scope_level = ::Contrast::SCOPE.scope_for_current_ec.instance_variable_get(:@contrast_scope)
45
45
 
46
46
  # Run original catch with block.
47
47
  retval = cs__catch(*args, &block)
48
48
 
49
49
  # Restore scope.
50
- Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_set(:@contrast_scope, scope_level)
50
+ ::Contrast::SCOPE.scope_for_current_ec.instance_variable_set(:@contrast_scope, scope_level)
51
51
 
52
52
  retval
53
53
  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/utils/object_share'
@@ -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,8 +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
-
6
4
  module Contrast
7
5
  module Extension
8
6
  module Protect
@@ -10,9 +8,6 @@ module Contrast
10
8
  # allowing us to track activity as it crosses spawned processes.
11
9
  module Kernel
12
10
  class << self
13
- include Contrast::Components::Interface
14
- access_component :contrast_service
15
-
16
11
  def build_wrapper
17
12
  lambda {
18
13
  proc_start
@@ -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
  if defined?(Psych)
@@ -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
  # ensure that we're being loaded with an agent
@@ -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,26 +1,24 @@
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/logger'
4
5
  require 'contrast/framework/platform_version'
5
6
  require 'contrast/framework/rack/support'
6
7
  require 'contrast/framework/rails/support'
7
8
  require 'contrast/framework/sinatra/support'
8
- require 'contrast/components/interface'
9
9
  require 'contrast/utils/class_util'
10
10
 
11
11
  module Contrast
12
12
  module Framework
13
13
  # Allows access to framework specific information
14
14
  class Manager
15
- include Contrast::Components::Interface
16
- access_component :analysis, :logging
15
+ include Contrast::Components::Logger::InstanceMethods
17
16
 
18
17
  # Order here does matter as the first framework listed will be the first one we pull information from
19
18
  # Rack will be a special case that may involve updating some logic to handle only applying Rack if Rails/Sinatra
20
19
  # do not exist
21
20
  SUPPORTED_FRAMEWORKS = [
22
- Contrast::Framework::Rails::Support,
23
- Contrast::Framework::Sinatra::Support,
21
+ Contrast::Framework::Rails::Support, Contrast::Framework::Sinatra::Support,
24
22
  Contrast::Framework::Rack::Support
25
23
  ].cs__freeze
26
24
 
@@ -81,7 +79,7 @@ module Contrast
81
79
 
82
80
  # If we have 0 or n > 1 frameworks, we need to use the default rack request
83
81
  #
84
- # @param env [Hash] the various variables stored by this and other Middlewares to know the state and values
82
+ # @param env [Hash] the various variables stored by this and other Middlewares to know the state and values
85
83
  # of this particular Request
86
84
  # @return [::Rack::Request] either a rack request or subclass thereof.
87
85
  def retrieve_request env
@@ -102,16 +100,13 @@ module Contrast
102
100
  result
103
101
  end
104
102
 
105
- # Iterate through current frameworks and return the current request's route. This will be the first
103
+ # Iterate through current frameworks and return the current request's route. This will be the first
106
104
  # non-nil result.
107
105
  #
108
106
  # @param request [Contrast::Agent::Request] the current request.
109
107
  # @return [Contrast::Api::Dtm::RouteCoverage] the current route as a Dtm.
110
- # TODO: RUBY-1075 add unit test.
111
108
  def get_route_dtm request
112
- result = nil
113
- @_frameworks.find { |framework_klass| result = framework_klass.current_route(request) }
114
- result
109
+ @_frameworks.lazy.map { |framework_support| framework_support.current_route(request) }.reject(&:nil?).first
115
110
  end
116
111
 
117
112
  private
@@ -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,7 +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
- require 'contrast/components/interface'
4
+ require 'contrast/components/logger'
5
+ require 'contrast/components/scope'
5
6
 
6
7
  module Contrast
7
8
  module Framework
@@ -11,9 +12,8 @@ module Contrast
11
12
  # runtime detection of insecure configurations on individual cookies
12
13
  # within the application
13
14
  class SessionCookie
14
- include Contrast::Components::Interface
15
-
16
- access_component :agent, :analysis, :logging, :scope
15
+ extend Contrast::Components::Logger::InstanceMethods
16
+ extend Contrast::Components::Scope::InstanceMethods
17
17
 
18
18
  CS__SECURE_RULE_NAME = 'secure-flag-missing'
19
19
  CS__HTTPONLY_NAME = 'rails-http-only-disabled'
@@ -36,8 +36,8 @@ module Contrast
36
36
  end
37
37
 
38
38
  def analyze options
39
- return unless AGENT.enabled?
40
- return if ASSESS.forcibly_disabled?
39
+ return unless ::Contrast::AGENT.enabled?
40
+ return if ::Contrast::ASSESS.forcibly_disabled?
41
41
 
42
42
  apply_session_timeout(options)
43
43
  apply_httponly(options)
@@ -61,16 +61,9 @@ module Contrast
61
61
  end
62
62
 
63
63
  def apply_secure_session options
64
- return unless vulnerable_setting?(
65
- :secure,
66
- true,
67
- options,
68
- safe_default: false)
69
-
70
- cs__report_finding(
71
- CS__SECURE_RULE_NAME,
72
- options,
73
- caller_locations(10, 9)[0])
64
+ return unless vulnerable_setting?(:secure, true, options, safe_default: false)
65
+
66
+ cs__report_finding(CS__SECURE_RULE_NAME, options, caller_locations(10, 9)[0])
74
67
  rescue StandardError => e
75
68
  begin
76
69
  logger.error('Unable to track call to secure session', e)
@@ -86,10 +79,7 @@ module Contrast
86
79
  safe_default: false,
87
80
  comparison_type: :greater_than)
88
81
 
89
- cs__report_finding(
90
- CS__SESSION_TIMEOUT_NAME,
91
- options,
92
- caller_locations(10, 9)[0])
82
+ cs__report_finding(CS__SESSION_TIMEOUT_NAME, options, caller_locations(10, 9)[0])
93
83
  rescue StandardError => e
94
84
  begin
95
85
  logger.error('Unable to track call to set session timeout', e)
@@ -101,10 +91,7 @@ module Contrast
101
91
  def apply_httponly options
102
92
  return unless vulnerable_setting?(:httponly, true, options)
103
93
 
104
- cs__report_finding(
105
- CS__HTTPONLY_NAME,
106
- options,
107
- caller_locations(10, 9)[0])
94
+ cs__report_finding(CS__HTTPONLY_NAME, options, caller_locations(10, 9)[0])
108
95
  rescue StandardError => e
109
96
  begin
110
97
  logger.error('Unable to track call to httponly', e)