contrast-agent 3.9.1 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. checksums.yaml +4 -4
  2. data/.flayignore +1 -0
  3. data/.simplecov +5 -2
  4. data/ext/build_funchook.rb +12 -7
  5. data/ext/cs__assess_active_record_named/cs__active_record_named.c +12 -14
  6. data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
  7. data/ext/cs__assess_active_record_named/extconf.rb +3 -0
  8. data/ext/cs__assess_array/cs__assess_array.c +5 -6
  9. data/ext/cs__assess_array/cs__assess_array.h +1 -0
  10. data/ext/cs__assess_array/extconf.rb +3 -0
  11. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +13 -11
  12. data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
  13. data/ext/cs__assess_basic_object/extconf.rb +3 -0
  14. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -3
  15. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +3 -3
  16. data/ext/cs__assess_fiber_track/extconf.rb +3 -0
  17. data/ext/cs__assess_hash/cs__assess_hash.c +40 -17
  18. data/ext/cs__assess_hash/cs__assess_hash.h +4 -6
  19. data/ext/cs__assess_hash/extconf.rb +3 -0
  20. data/ext/cs__assess_kernel/cs__assess_kernel.c +11 -9
  21. data/ext/cs__assess_kernel/cs__assess_kernel.h +1 -0
  22. data/ext/cs__assess_kernel/extconf.rb +3 -0
  23. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +3 -6
  24. data/ext/cs__assess_marshal_module/extconf.rb +3 -0
  25. data/ext/cs__assess_module/cs__assess_module.c +16 -14
  26. data/ext/cs__assess_module/cs__assess_module.h +3 -0
  27. data/ext/cs__assess_module/extconf.rb +3 -0
  28. data/ext/cs__assess_regexp/cs__assess_regexp.c +13 -9
  29. data/ext/cs__assess_regexp/cs__assess_regexp.h +1 -0
  30. data/ext/cs__assess_regexp/extconf.rb +3 -0
  31. data/ext/cs__assess_string/cs__assess_string.c +5 -8
  32. data/ext/cs__assess_string/cs__assess_string.h +2 -1
  33. data/ext/cs__assess_string/extconf.rb +3 -0
  34. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +2 -2
  35. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +3 -3
  36. data/ext/cs__assess_string_interpolation26/extconf.rb +3 -0
  37. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +1 -1
  38. data/ext/cs__assess_yield_track/extconf.rb +3 -0
  39. data/ext/cs__common/cs__common.c +80 -1
  40. data/ext/cs__common/cs__common.h +34 -0
  41. data/ext/cs__common/extconf.rb +9 -8
  42. data/ext/cs__contrast_patch/cs__contrast_patch.h +1 -6
  43. data/ext/cs__contrast_patch/extconf.rb +3 -0
  44. data/ext/cs__protect_kernel/cs__protect_kernel.c +23 -12
  45. data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
  46. data/ext/cs__protect_kernel/extconf.rb +3 -0
  47. data/ext/extconf_common.rb +10 -8
  48. data/funchook/autom4te.cache/requests +48 -48
  49. data/funchook/config.log +4 -4
  50. data/lib/contrast.rb +1 -1
  51. data/lib/contrast/agent.rb +32 -29
  52. data/lib/contrast/agent/assess.rb +1 -11
  53. data/lib/contrast/agent/assess/adjusted_span.rb +3 -1
  54. data/lib/contrast/agent/assess/contrast_event.rb +20 -68
  55. data/lib/contrast/agent/assess/events/event_factory.rb +25 -0
  56. data/lib/contrast/agent/assess/events/source_event.rb +83 -0
  57. data/lib/contrast/agent/assess/insulator.rb +0 -4
  58. data/lib/contrast/agent/assess/policy/patcher.rb +6 -2
  59. data/lib/contrast/agent/assess/policy/policy_node.rb +1 -8
  60. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -2
  61. data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
  62. data/lib/contrast/agent/assess/policy/propagation_method.rb +68 -33
  63. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -1
  64. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  65. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  66. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
  67. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +80 -0
  68. data/lib/contrast/agent/assess/policy/propagator/select.rb +35 -22
  69. data/lib/contrast/agent/assess/policy/propagator/split.rb +26 -6
  70. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -0
  71. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +40 -27
  72. data/lib/contrast/agent/assess/policy/source_method.rb +20 -20
  73. data/lib/contrast/agent/assess/policy/source_node.rb +0 -15
  74. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
  75. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
  76. data/lib/contrast/agent/assess/policy/trigger_method.rb +30 -45
  77. data/lib/contrast/agent/assess/policy/trigger_node.rb +7 -7
  78. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -31
  79. data/lib/contrast/agent/assess/properties.rb +5 -3
  80. data/lib/contrast/agent/assess/rule/base.rb +1 -20
  81. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +23 -6
  82. data/lib/contrast/agent/assess/rule/redos.rb +4 -5
  83. data/lib/contrast/agent/assess/tag.rb +24 -14
  84. data/lib/contrast/agent/at_exit_hook.rb +16 -13
  85. data/lib/contrast/agent/class_reopener.rb +24 -10
  86. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  87. data/lib/contrast/agent/disable_reaction.rb +3 -4
  88. data/lib/contrast/agent/exclusion_matcher.rb +7 -48
  89. data/lib/contrast/agent/inventory/policy/datastores.rb +54 -0
  90. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  91. data/lib/contrast/agent/middleware.rb +101 -260
  92. data/lib/contrast/agent/module_data.rb +2 -1
  93. data/lib/contrast/agent/patching/policy/after_load_patch.rb +13 -3
  94. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +59 -47
  95. data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
  96. data/lib/contrast/agent/patching/policy/module_policy.rb +0 -25
  97. data/lib/contrast/agent/patching/policy/patch.rb +97 -23
  98. data/lib/contrast/agent/patching/policy/patcher.rb +28 -30
  99. data/lib/contrast/agent/patching/policy/policy.rb +7 -7
  100. data/lib/contrast/agent/patching/policy/policy_node.rb +3 -11
  101. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -5
  102. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
  103. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
  104. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
  105. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
  106. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
  107. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
  108. data/lib/contrast/agent/protect/policy/policy.rb +6 -6
  109. data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
  110. data/lib/contrast/agent/protect/rule.rb +0 -5
  111. data/lib/contrast/agent/protect/rule/base.rb +19 -37
  112. data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
  113. data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -15
  114. data/lib/contrast/agent/protect/rule/default_scanner.rb +0 -13
  115. data/lib/contrast/agent/protect/rule/deserialization.rb +2 -0
  116. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -2
  117. data/lib/contrast/agent/protect/rule/no_sqli.rb +4 -4
  118. data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
  119. data/lib/contrast/agent/protect/rule/sqli.rb +5 -4
  120. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -0
  121. data/lib/contrast/agent/protect/rule/xss.rb +2 -0
  122. data/lib/contrast/agent/protect/rule/xxe.rb +10 -4
  123. data/lib/contrast/agent/railtie.rb +3 -8
  124. data/lib/contrast/agent/reaction_processor.rb +5 -5
  125. data/lib/contrast/agent/request.rb +11 -18
  126. data/lib/contrast/agent/request_context.rb +16 -19
  127. data/lib/contrast/agent/request_handler.rb +35 -0
  128. data/lib/contrast/agent/response.rb +39 -86
  129. data/lib/contrast/agent/rewriter.rb +25 -11
  130. data/lib/contrast/agent/rule_set.rb +49 -0
  131. data/lib/contrast/agent/scope.rb +4 -12
  132. data/lib/contrast/agent/service_heartbeat.rb +3 -4
  133. data/lib/contrast/agent/socket_client.rb +25 -19
  134. data/lib/contrast/agent/static_analysis.rb +41 -0
  135. data/lib/contrast/agent/thread.rb +1 -1
  136. data/lib/contrast/agent/tracepoint_hook.rb +1 -5
  137. data/lib/contrast/agent/version.rb +1 -1
  138. data/lib/contrast/api.rb +1 -1
  139. data/lib/contrast/api/decorators.rb +14 -0
  140. data/lib/contrast/api/decorators/application_settings.rb +37 -0
  141. data/lib/contrast/api/decorators/application_update.rb +66 -0
  142. data/lib/contrast/api/decorators/input_analysis.rb +17 -0
  143. data/lib/contrast/api/decorators/server_features.rb +24 -0
  144. data/lib/contrast/api/speedracer.rb +32 -30
  145. data/lib/contrast/api/tcp_socket.rb +0 -2
  146. data/lib/contrast/components/agent.rb +34 -24
  147. data/lib/contrast/components/app_context.rb +45 -38
  148. data/lib/contrast/components/assess.rb +25 -15
  149. data/lib/contrast/components/config.rb +7 -5
  150. data/lib/contrast/components/contrast_service.rb +23 -71
  151. data/lib/contrast/components/heap_dump.rb +12 -8
  152. data/lib/contrast/components/interface.rb +15 -22
  153. data/lib/contrast/components/inventory.rb +5 -1
  154. data/lib/contrast/components/logger.rb +3 -68
  155. data/lib/contrast/components/protect.rb +40 -4
  156. data/lib/contrast/components/sampling.rb +22 -11
  157. data/lib/contrast/components/scope.rb +2 -52
  158. data/lib/contrast/components/settings.rb +42 -23
  159. data/lib/contrast/config/base_configuration.rb +1 -0
  160. data/lib/contrast/config/default_value.rb +1 -0
  161. data/lib/contrast/config/protect_rule_configuration.rb +0 -14
  162. data/lib/contrast/config/protect_rules_configuration.rb +0 -1
  163. data/lib/contrast/configuration.rb +3 -5
  164. data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -15
  165. data/lib/contrast/extension/assess/array.rb +77 -0
  166. data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +29 -24
  167. data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -8
  168. data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
  169. data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +7 -9
  170. data/lib/contrast/extension/assess/fiber.rb +113 -0
  171. data/lib/contrast/extension/assess/hash.rb +39 -0
  172. data/lib/contrast/extension/assess/kernel.rb +110 -0
  173. data/lib/contrast/extension/assess/regexp.rb +84 -0
  174. data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +18 -10
  175. data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
  176. data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -2
  177. data/lib/contrast/extension/kernel.rb +54 -0
  178. data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
  179. data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
  180. data/lib/contrast/extension/protect/kernel.rb +44 -0
  181. data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
  182. data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
  183. data/lib/contrast/framework/base_support.rb +32 -0
  184. data/lib/contrast/framework/manager.rb +59 -8
  185. data/lib/contrast/framework/platform_version.rb +1 -0
  186. data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
  187. data/lib/contrast/framework/rack/patch/support.rb +24 -0
  188. data/lib/contrast/framework/rack/support.rb +22 -0
  189. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +43 -0
  190. data/lib/contrast/framework/rails/patch/assess_configuration.rb +103 -0
  191. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
  192. data/lib/contrast/framework/rails/patch/support.rb +67 -0
  193. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
  194. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
  195. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
  196. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
  197. data/lib/contrast/framework/rails/support.rb +115 -0
  198. data/lib/contrast/framework/sinatra/application_helper.rb +51 -0
  199. data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
  200. data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
  201. data/lib/contrast/framework/sinatra/support.rb +109 -0
  202. data/lib/contrast/framework/view_technologies_descriptor.rb +1 -0
  203. data/lib/contrast/logger/application.rb +80 -0
  204. data/lib/contrast/logger/log.rb +142 -0
  205. data/lib/contrast/logger/time.rb +50 -0
  206. data/lib/contrast/tasks/config.rb +54 -0
  207. data/lib/contrast/tasks/service.rb +3 -13
  208. data/lib/contrast/utils/assess/sampling_util.rb +4 -9
  209. data/lib/contrast/utils/assess/tracking_util.rb +7 -1
  210. data/lib/contrast/utils/boolean_util.rb +2 -5
  211. data/lib/contrast/utils/cache.rb +0 -11
  212. data/lib/contrast/utils/class_util.rb +21 -2
  213. data/lib/contrast/utils/gemfile_reader.rb +7 -5
  214. data/lib/contrast/utils/hash_digest.rb +2 -11
  215. data/lib/contrast/utils/heap_dump_util.rb +12 -11
  216. data/lib/contrast/utils/invalid_configuration_util.rb +4 -4
  217. data/lib/contrast/utils/inventory_util.rb +2 -2
  218. data/lib/contrast/utils/io_util.rb +1 -11
  219. data/lib/contrast/utils/job_servers_running.rb +6 -4
  220. data/lib/contrast/utils/object_share.rb +1 -38
  221. data/lib/contrast/utils/os.rb +1 -25
  222. data/lib/contrast/utils/ruby_ast_rewriter.rb +5 -1
  223. data/lib/contrast/utils/service_response_util.rb +36 -60
  224. data/lib/contrast/utils/service_sender_util.rb +84 -23
  225. data/lib/contrast/utils/sinatra_helper.rb +0 -6
  226. data/lib/contrast/utils/stack_trace_utils.rb +86 -182
  227. data/lib/contrast/utils/string_utils.rb +18 -2
  228. data/lib/contrast/utils/tag_util.rb +11 -1
  229. data/lib/contrast/utils/thread_tracker.rb +2 -2
  230. data/lib/contrast/utils/timer.rb +0 -40
  231. data/resources/assess/policy.json +42 -71
  232. data/resources/inventory/policy.json +2 -2
  233. data/resources/protect/policy.json +15 -15
  234. data/ruby-agent.gemspec +12 -5
  235. data/service_executables/VERSION +1 -1
  236. data/service_executables/linux/contrast-service +0 -0
  237. data/service_executables/mac/contrast-service +0 -0
  238. metadata +123 -112
  239. data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +0 -63
  240. data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +0 -29
  241. data/ext/cs__assess_regexp_track/extconf.rb +0 -2
  242. data/lib/contrast/agent/assess/frozen_properties.rb +0 -41
  243. data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
  244. data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
  245. data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -73
  246. data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -132
  247. data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
  248. data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
  249. data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
  250. data/lib/contrast/agent/feature_state.rb +0 -379
  251. data/lib/contrast/agent/logger_manager.rb +0 -116
  252. data/lib/contrast/agent/protect/rule/csrf.rb +0 -118
  253. data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -103
  254. data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
  255. data/lib/contrast/agent/settings_state.rb +0 -152
  256. data/lib/contrast/delegators.rb +0 -9
  257. data/lib/contrast/delegators/application_update.rb +0 -32
  258. data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
  259. data/lib/contrast/extensions/framework/rack/request.rb +0 -24
  260. data/lib/contrast/extensions/framework/rack/response.rb +0 -23
  261. data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
  262. data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
  263. data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -53
  264. data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
  265. data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
  266. data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
  267. data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
  268. data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
  269. data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
  270. data/lib/contrast/extensions/ruby_core/assess/fiber.rb +0 -124
  271. data/lib/contrast/extensions/ruby_core/assess/hash.rb +0 -22
  272. data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -95
  273. data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
  274. data/lib/contrast/extensions/ruby_core/assess/regexp.rb +0 -206
  275. data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -73
  276. data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
  277. data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -52
  278. data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
  279. data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -72
  280. data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -60
  281. data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -83
  282. data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -123
  283. data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -65
  284. data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -143
  285. data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
  286. data/lib/contrast/framework/rails_support.rb +0 -88
  287. data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
  288. data/lib/contrast/framework/sinatra_support.rb +0 -94
  289. data/lib/contrast/utils/comment_range.rb +0 -19
  290. data/lib/contrast/utils/data_store_util.rb +0 -23
  291. data/lib/contrast/utils/environment_util.rb +0 -82
  292. data/lib/contrast/utils/performs_logging.rb +0 -152
  293. data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
  294. data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
  295. data/lib/contrast/utils/random_util.rb +0 -22
  296. data/resources/csrf/inject.js +0 -44
  297. data/resources/factory-bot-spec/spec_helper.rb +0 -30
  298. data/resources/rubocops/kernel/catch_cop.rb +0 -37
  299. data/resources/rubocops/kernel/require_cop.rb +0 -37
  300. data/resources/rubocops/kernel/require_relative_cop.rb +0 -33
  301. data/resources/rubocops/module/autoload_cop.rb +0 -37
  302. data/resources/rubocops/module/const_defined_cop.rb +0 -37
  303. data/resources/rubocops/module/const_get_cop.rb +0 -37
  304. data/resources/rubocops/module/const_set_cop.rb +0 -37
  305. data/resources/rubocops/module/constants_cop.rb +0 -37
  306. data/resources/rubocops/module/name_cop.rb +0 -37
  307. data/resources/rubocops/object/class_cop.rb +0 -37
  308. data/resources/rubocops/object/freeze_cop.rb +0 -37
  309. data/resources/rubocops/object/frozen_cop.rb +0 -37
  310. data/resources/rubocops/object/is_a_cop.rb +0 -37
  311. data/resources/rubocops/object/method_cop.rb +0 -37
  312. data/resources/rubocops/object/respond_to_cop.rb +0 -37
  313. data/resources/rubocops/object/singleton_class_cop.rb +0 -37
  314. data/resources/rubocops/regexp/spelling_cop.rb +0 -44
  315. data/resources/rubocops/thread/new_cop.rb +0 -39
  316. data/resources/ruby-spec/ancestors_spec.rb +0 -70
  317. data/resources/ruby-spec/modulo_spec.rb +0 -831
  318. data/resources/ruby-spec/parameters_spec.rb +0 -261
  319. data/resources/ruby-spec/ruby_spec_spec_helper.rb +0 -35
@@ -11,9 +11,13 @@ module Contrast
11
11
  # product.
12
12
  class Interface
13
13
  include Contrast::Components::ComponentBase
14
+ include Contrast::Components::Interface
15
+
16
+ access_component :config
14
17
 
15
18
  def enabled?
16
- state.inventory_enabled?
19
+ @_enabled = !false?(CONFIG.root.inventory.enable) if @_enabled.nil?
20
+ @_enabled
17
21
  end
18
22
  end
19
23
 
@@ -1,12 +1,14 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ cs__scoped_require 'contrast/logger/log'
5
+
4
6
  module Contrast
5
7
  module Components
6
8
  module Logger
7
9
  module InstanceMethods #:nodoc:
8
10
  def logger
9
- Contrast::Components::Logger::COMPONENT_INTERFACE
11
+ Contrast::Logger::Log.instance.logger
10
12
  end
11
13
  end
12
14
  ClassMethods = InstanceMethods
@@ -17,73 +19,6 @@ module Contrast
17
19
  # Specifically, this allows for querying the state of the Agent Logger.
18
20
  class Interface
19
21
  include Contrast::Components::ComponentBase
20
-
21
- %w[error? warn? info? debug?].each do |level|
22
- define_method(level) { state.logger.send(level) }
23
- end
24
-
25
- # def trace? # TODO: RUBY-547
26
- # config&.agent&.logger&.level && config.agent.logger.level.to_s.casecmp('TRACE').to_i.zero?
27
- # end
28
-
29
- def error *args
30
- log_with_level(*args, :error)
31
- end
32
-
33
- def warn *args
34
- log_with_level(*args, :warn)
35
- end
36
-
37
- def info *args
38
- log_with_level(*args, :info)
39
- end
40
-
41
- def debug *args
42
- log_with_level(*args, :debug)
43
- end
44
-
45
- def with_level *args
46
- log_with_level(*args)
47
- end
48
-
49
- def debug_with_time msg
50
- ret = nil
51
- a = Contrast::Utils::Timer.now_ms
52
- ret = yield if block_given?
53
- z = Contrast::Utils::Timer.now_ms
54
- log_with_level(nil, "#{ msg }: pid=#{ Process.pid }, elapsed=#{ z - a }ms", :debug)
55
- ret
56
- end
57
-
58
- # def trace_with_time msg # TODO: RUBY-547
59
- # ret = nil
60
- # unless trace?
61
- # ret = yield if block_given?
62
- # return ret
63
- # end
64
- #
65
- # a = Contrast::Utils::Timer.now_ms
66
- # ret = yield if block_given?
67
- # z = Contrast::Utils::Timer.now_ms
68
- # log_with_level(nil, "#{ msg }: pid=#{ Process.pid }, elapsed=#{ z - a }ms", :debug)
69
- # ret
70
- # end
71
-
72
- private
73
-
74
- def log_with_level *args
75
- if args.length == 2
76
- msg, level = *args
77
- state.cs__class.log_with_level(nil, msg, level)
78
- elsif args.length == 3
79
- exception, msg, level = *args
80
- state.cs__class.log_with_level(exception, msg, level)
81
- end
82
-
83
- nil
84
- rescue StandardError
85
- nil
86
- end
87
22
  end
88
23
 
89
24
  COMPONENT_INTERFACE = Interface.new
@@ -13,23 +13,59 @@ module Contrast
13
13
  include Contrast::Components::ComponentBase
14
14
  include Contrast::Components::Interface
15
15
 
16
- access_component :settings
16
+ access_component :config, :settings
17
17
 
18
18
  def enabled?
19
- state.protect_enabled?
19
+ # config overrides if forcibly set
20
+ return false if forcibly_disabled?
21
+ return true if forcibly_enabled?
22
+
23
+ SETTINGS.protect_enabled?
20
24
  end
21
25
 
22
- def forcibly_disabled?
23
- state.protect_forcibly_disabled?
26
+ def rule_config
27
+ CONFIG.root.protect.rules
24
28
  end
25
29
 
26
30
  def rules
27
31
  SETTINGS.protect_rules
28
32
  end
29
33
 
34
+ def rule_mode rule_id
35
+ CONFIG.root.protect.rules[rule_id]&.mode || SETTINGS.modes_by_id[rule_id] || :NO_ACTION
36
+ end
37
+
30
38
  def rule name
31
39
  SETTINGS.protect_rules[name]
32
40
  end
41
+
42
+ def report_any_command_execution?
43
+ if @_report_any_command_execution.nil?
44
+ ctrl = rule_config[Contrast::Agent::Protect::Rule::CmdInjection::NAME]
45
+ @_report_any_command_execution = true?(ctrl.disable_system_commands)
46
+ end
47
+ @_report_any_command_execution
48
+ end
49
+
50
+ def report_custom_code_sysfile_access?
51
+ if @_report_custom_code_sysfile_access.nil?
52
+ ctrl = rule_config[Contrast::Agent::Protect::Rule::PathTraversal::NAME]
53
+ @_report_custom_code_sysfile_access = true?(ctrl.detect_custom_code_accessing_system_files)
54
+ end
55
+ @_report_custom_code_sysfile_access
56
+ end
57
+
58
+ def forcibly_disabled?
59
+ @_forcibly_disabled = false?(CONFIG.root.protect.enable) if @_forcibly_disabled.nil?
60
+ @_forcibly_disabled
61
+ end
62
+
63
+ private
64
+
65
+ def forcibly_enabled?
66
+ @_forcibly_enabled = true?(CONFIG.root.protect.enable) if @_forcibly_enabled.nil?
67
+ @_forcibly_enabled
68
+ end
33
69
  end
34
70
 
35
71
  COMPONENT_INTERFACE = Interface.new
@@ -9,7 +9,7 @@ module Contrast
9
9
  DEFAULT_SAMPLING_BASELINE = 5
10
10
  DEFAULT_SAMPLING_REQUEST_FREQUENCY = 5
11
11
  DEFAULT_SAMPLING_RESPONSE_FREQUENCY = 25
12
- DEFAULT_SAMPLING_WINDOW_MS = 180_000 # 3 minutes, arbitrary value from Java agent
12
+ DEFAULT_SAMPLING_WINDOW_MS = 180_000
13
13
  end
14
14
 
15
15
  module ClassMethods #:nodoc:
@@ -17,18 +17,29 @@ module Contrast
17
17
  include Constants
18
18
  include Contrast::Components::Interface
19
19
 
20
- access_component :config
20
+ access_component :config, :settings
21
21
 
22
- def sampling_control settings = @sampling_features
23
- cas = CONFIG.root.assess&.sampling
22
+ def sampling_enabled?
23
+ sampling_control[:enabled]
24
+ end
25
+
26
+ def sampling_control
27
+ @_sampling_control ||= begin
28
+ cas = CONFIG.root.assess&.sampling
29
+ settings = SETTINGS&.assess_state&.[](:sampling_settings)
30
+ {
31
+ enabled: true?([cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED].reject(&:nil?)[0]),
32
+ baseline: [cas&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE].map(&:to_i).find(&:positive?),
33
+ request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY].map(&:to_i).find(&:positive?),
34
+ response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
35
+ window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS].map(&:to_i).find(&:positive?)
36
+ }
37
+ end
38
+ end
24
39
 
25
- {
26
- enabled: [cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED] .reject(&:nil?).first,
27
- baseline: [cas&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE] .map(&:to_i).find(&:positive?),
28
- request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY] .map(&:to_i).find(&:positive?),
29
- response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
30
- window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS] .map(&:to_i).find(&:positive?)
31
- }
40
+ # Used to reset sampling when settings from TeamServer change
41
+ def reset_sampling_control
42
+ @_sampling_control = nil
32
43
  end
33
44
  end
34
45
 
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'monitor'
5
4
  cs__scoped_require 'fiber'
5
+ cs__scoped_require 'monitor'
6
6
  cs__scoped_require 'contrast/agent/scope'
7
7
 
8
8
  # This is the Scope component.
@@ -54,7 +54,7 @@ module Contrast
54
54
  end
55
55
  end
56
56
 
57
- # TODO: https://contrast.atlassian.net/browse/RUBY-290
57
+ # TODO: RUBY-572
58
58
  #
59
59
  # Current behavior is to no-op if we're not "in a request context".
60
60
  # Our C functions were previously checking to see if we had a scope, because
@@ -84,53 +84,3 @@ module Contrast
84
84
  end
85
85
  end
86
86
  end
87
-
88
- # This is a reasonable place for the Kernel#catch hook to live.
89
- # No current plans for component re-design, but if we had some kind of
90
- # "do this when a component is hooked in" thing, this would live there.
91
- # For now, it's over-engineering to live anywhere else. -ajm
92
- module Kernel # :nodoc:
93
- alias_method :cs__catch, :catch
94
-
95
- # In the event of a `throw`, we need to override `catch`
96
- # to save & restore scope state:
97
- #
98
- # scope_level == 0
99
- #
100
- # catch(:abc) do
101
- # with_contrast_scope do
102
- # throw :abc # will leak
103
- # end
104
- # end
105
- #
106
- # scope_level == 1
107
- #
108
- # Frankly, this isn't how scope should be used. This is in place of
109
- # proper `ensure` blocks within the instrumentation call stack.
110
- # This will actually /create/ scope leaks if you're doing something like:
111
- #
112
- # catch(:ohno) do
113
- # enter scope
114
- # end
115
- #
116
- # abc()
117
- #
118
- # exit scope
119
- #
120
- # i.e. if you intend to change net scope across a catch block boundary.
121
-
122
- private
123
-
124
- def catch *args, &block
125
- # Save current scope level
126
- scope_level = Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_get(:@contrast_scope)
127
-
128
- # Run original catch with block.
129
- retval = cs__catch(*args, &block)
130
-
131
- # Restore scope.
132
- Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_set(:@contrast_scope, scope_level)
133
-
134
- retval
135
- end
136
- end
@@ -23,11 +23,6 @@ module Contrast
23
23
  # this statefulness
24
24
  attr_reader :tainted_columns # This can probably go into assess_state?
25
25
 
26
- # a vulnerability like padding oracle is exploited across
27
- # multiple requests, as a timing attack. these attempts must be
28
- # accumulated, in order to recognize the pattern and block the attack.
29
- attr_reader :accumulator_settings
30
-
31
26
  # These three 'state' variables represent atomic config/setting state,
32
27
  # outside of things like rule defs.
33
28
 
@@ -40,8 +35,7 @@ module Contrast
40
35
 
41
36
  def protect_state
42
37
  @protect_state ||= { # rubocop:disable Naming/MemoizedInstanceVariableName
43
- enabled: false,
44
- accumulator_settings: Contrast::Api::Settings::AccumulatorSettings.new
38
+ enabled: false
45
39
  }
46
40
  end
47
41
 
@@ -58,8 +52,7 @@ module Contrast
58
52
  # So, between this block and rules, that's setting state.
59
53
  PROTECT_STATE_ATTRS = %i[].cs__freeze
60
54
  ASSESS_STATE_ATTRS = %i[sampling_features].cs__freeze
61
- APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules session_id].cs__freeze
62
- STATE_ATTRS = PROTECT_STATE_ATTRS | ASSESS_STATE_ATTRS | APPLICATION_STATE_ATTRS
55
+ APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules].cs__freeze
63
56
 
64
57
  # Meta-define an accessor for each state attribute.
65
58
  begin
@@ -82,10 +75,50 @@ module Contrast
82
75
  end
83
76
  end
84
77
 
78
+ def session_id
79
+ # TODO: RUBY-900 we shouldn't send things w/o having session id,
80
+ # figure out how this happened and fix it.
81
+ application_state[:session_id] || Contrast::Utils::ObjectShare::EMPTY_STRING
82
+ end
83
+
85
84
  def initialize
86
85
  reset_state
87
86
  end
88
87
 
88
+ def protect_enabled?
89
+ @_protect_enabled = !!protect_state[:enabled] if @_protect_enabled.nil?
90
+ @_protect_enabled
91
+ end
92
+
93
+ def assess_enabled?
94
+ @_assess_enabled = !!assess_state[:enabled] if @_assess_enabled.nil?
95
+ @_assess_enabled
96
+ end
97
+
98
+ def code_exclusions
99
+ exclusion_matchers.select(&:code?)
100
+ end
101
+
102
+ def update_from_server_features server_features
103
+ # protect
104
+ begin
105
+ @_protect_enabled = nil
106
+ protect_state[:enabled] = server_features.protect_enabled?
107
+ end
108
+
109
+ # assess
110
+ begin
111
+ @_assess_enabled = nil
112
+ assess_state[:enabled] = server_features.assess_enabled?
113
+ assess_state[:sampling_settings] = server_features.assess.sampling
114
+ Contrast::Utils::Assess::SamplingUtil.instance.update
115
+ end
116
+ end
117
+
118
+ def update_from_application_settings application_settings
119
+ application_state.merge!(application_settings.application_state_translation)
120
+ end
121
+
89
122
  # Wipe state to zero.
90
123
  def reset_state
91
124
  @assess_rules = {}
@@ -101,7 +134,6 @@ module Contrast
101
134
  def build_assess_rules
102
135
  @assess_rules = {}
103
136
 
104
- Contrast::Agent::Assess::Rule::Csrf.new
105
137
  Contrast::Agent::Assess::Rule::Redos.new
106
138
  end
107
139
 
@@ -118,19 +150,6 @@ module Contrast
118
150
  Contrast::Agent::Protect::Rule::UnsafeFileUpload.new
119
151
  Contrast::Agent::Protect::Rule::Xss.new
120
152
  Contrast::Agent::Protect::Rule::Xxe.new
121
-
122
- # Beta Rules
123
- Contrast::Agent::Protect::Rule::Csrf.new
124
- end
125
-
126
- def protect_rule name
127
- @protect_rules[name]
128
- end
129
-
130
- # these are less 'settings' and more 'how do I behave.'
131
- # relocate to Agent or Assess/Protect.
132
- def protect_rule_mode rule_id
133
- CONFIG.root.protect.rules[rule_id]&.mode || modes_by_id[rule_id] || :NO_ACTION
134
153
  end
135
154
  end
136
155
 
@@ -15,6 +15,7 @@ module Contrast
15
15
  BOOLEANS = [true, false].cs__freeze
16
16
 
17
17
  attr_reader :map
18
+
18
19
  alias_method :to_hash, :map
19
20
  def_delegators :@map, :empty?, :key?,
20
21
  :delete,
@@ -8,6 +8,7 @@ module Contrast
8
8
  # explicitly to false.
9
9
  class DefaultValue
10
10
  attr_reader :value
11
+
11
12
  def initialize value
12
13
  @value = value
13
14
  end
@@ -8,12 +8,6 @@ module Contrast
8
8
  # Common Configuration settings. Those in this section pertain to the
9
9
  # rule mode of a single protect rule in the Agent.
10
10
  class ProtectRuleConfiguration < BaseConfiguration
11
- # rubocop:disable Style/SymbolArray, Layout/SpaceBeforeComma, Layout/SpaceInsideArrayLiteralBrackets:
12
- BLOCKING_RULES = ::Set.new([:BLOCK , :BLOCK_AT_PERIMETER ]).cs__freeze
13
- PREFILTER_RULES = ::Set.new([ :BLOCK_AT_PERIMETER ]).cs__freeze
14
- POSTFILTER_RULES = ::Set.new([:BLOCK , :PERMIT, :MONITOR]).cs__freeze
15
- # rubocop:enable Style/SymbolArray, Layout/SpaceBeforeComma, Layout/SpaceInsideArrayLiteralBrackets:
16
-
17
11
  KEYS = {
18
12
  enable: EMPTY_VALUE,
19
13
  mode: EMPTY_VALUE,
@@ -24,14 +18,6 @@ module Contrast
24
18
  def initialize hsh
25
19
  super(hsh, KEYS)
26
20
  end
27
-
28
- def off?
29
- mode == 'off'
30
- end
31
-
32
- def on?
33
- !off?
34
- end
35
21
  end
36
22
  end
37
23
  end
@@ -14,7 +14,6 @@ module Contrast
14
14
  'nosql-injection' => Contrast::Config::ProtectRuleConfiguration,
15
15
  'untrusted-deserialization' => Contrast::Config::ProtectRuleConfiguration,
16
16
  'method-tampering' => Contrast::Config::ProtectRuleConfiguration,
17
- csrf: Contrast::Config::ProtectRuleConfiguration,
18
17
  xxe: Contrast::Config::ProtectRuleConfiguration,
19
18
  'path-traversal' => Contrast::Config::ProtectRuleConfiguration,
20
19
  'reflected-xss' => Contrast::Config::ProtectRuleConfiguration,