contrast-agent 6.7.0 → 6.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.simplecov +0 -1
  4. data/Rakefile +0 -1
  5. data/ext/cs__assess_array/cs__assess_array.c +41 -10
  6. data/ext/cs__assess_array/cs__assess_array.h +4 -1
  7. data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -3
  8. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  9. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  10. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
  11. data/lib/contrast/agent/assess/property/evented.rb +11 -11
  12. data/lib/contrast/agent/assess.rb +0 -1
  13. data/lib/contrast/agent/excluder.rb +53 -35
  14. data/lib/contrast/agent/exclusion_matcher.rb +21 -9
  15. data/lib/contrast/agent/middleware.rb +12 -6
  16. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -0
  17. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +146 -127
  18. data/lib/contrast/agent/protect/input_analyzer/worth_watching_analyzer.rb +116 -0
  19. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
  20. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  21. data/lib/contrast/agent/protect/rule/base.rb +47 -55
  22. data/lib/contrast/agent/protect/rule/base_service.rb +48 -24
  23. data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +98 -0
  24. data/lib/contrast/agent/protect/rule/bot_blocker.rb +81 -0
  25. data/lib/contrast/agent/protect/rule/cmd_injection.rb +20 -2
  26. data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +8 -5
  27. data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +22 -22
  28. data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +64 -0
  29. data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +63 -0
  30. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +2 -58
  31. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  32. data/lib/contrast/agent/protect/rule/deserialization.rb +3 -14
  33. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +2 -2
  34. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -11
  35. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +29 -34
  36. data/lib/contrast/agent/protect/rule/no_sqli.rb +25 -18
  37. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +61 -0
  38. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +114 -0
  39. data/lib/contrast/agent/protect/rule/path_traversal.rb +40 -13
  40. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +33 -15
  41. data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +0 -14
  42. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
  43. data/lib/contrast/agent/protect/rule/sqli.rb +74 -3
  44. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +39 -63
  45. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +6 -33
  46. data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +58 -0
  47. data/lib/contrast/agent/protect/rule/xss.rb +15 -20
  48. data/lib/contrast/agent/protect/rule/xxe.rb +4 -24
  49. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +19 -40
  50. data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
  51. data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +10 -2
  52. data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +8 -2
  53. data/lib/contrast/agent/reporting/input_analysis/details/bot_blocker_details.rb +27 -0
  54. data/lib/contrast/agent/reporting/input_analysis/details/protect_rule_details.rb +15 -0
  55. data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +1 -2
  56. data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +16 -2
  57. data/lib/contrast/agent/reporting/masker/masker.rb +2 -0
  58. data/lib/contrast/agent/reporting/report.rb +1 -0
  59. data/lib/contrast/agent/reporting/reporter.rb +35 -14
  60. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +3 -9
  61. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +16 -13
  62. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +12 -7
  63. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +3 -3
  64. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +1 -2
  65. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -1
  66. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
  67. data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +0 -1
  68. data/lib/contrast/agent/reporting/reporting_events/finding.rb +6 -6
  69. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +239 -93
  70. data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +10 -23
  71. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +10 -9
  72. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +0 -5
  73. data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
  74. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +12 -0
  75. data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
  76. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +0 -1
  77. data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +0 -1
  78. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +8 -0
  79. data/lib/contrast/agent/reporting/reporting_events/server_settings.rb +40 -0
  80. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +2 -2
  81. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  82. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +43 -1
  83. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +8 -4
  84. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
  85. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +58 -4
  86. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +4 -6
  87. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +77 -16
  88. data/lib/contrast/agent/reporting/server_settings_worker.rb +44 -0
  89. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +14 -2
  90. data/lib/contrast/agent/reporting/settings/code_exclusion.rb +6 -1
  91. data/lib/contrast/agent/reporting/settings/exclusion_base.rb +18 -0
  92. data/lib/contrast/agent/reporting/settings/exclusions.rb +2 -1
  93. data/lib/contrast/agent/reporting/settings/helpers.rb +7 -0
  94. data/lib/contrast/agent/reporting/settings/input_exclusion.rb +9 -3
  95. data/lib/contrast/agent/reporting/settings/protect.rb +15 -15
  96. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +39 -2
  97. data/lib/contrast/agent/reporting/settings/rule_definition.rb +3 -0
  98. data/lib/contrast/agent/reporting/settings/security_logger.rb +77 -0
  99. data/lib/contrast/agent/reporting/settings/server_features.rb +9 -0
  100. data/lib/contrast/agent/reporting/settings/syslog.rb +34 -5
  101. data/lib/contrast/agent/request.rb +3 -14
  102. data/lib/contrast/agent/request_context.rb +6 -9
  103. data/lib/contrast/agent/request_context_extend.rb +9 -148
  104. data/lib/contrast/agent/request_handler.rb +5 -10
  105. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +1 -1
  106. data/lib/contrast/agent/thread_watcher.rb +37 -18
  107. data/lib/contrast/agent/version.rb +1 -1
  108. data/lib/contrast/agent.rb +6 -11
  109. data/lib/contrast/agent_lib/api/command_injection.rb +46 -0
  110. data/lib/contrast/agent_lib/api/init.rb +101 -0
  111. data/lib/contrast/agent_lib/api/input_tracing.rb +267 -0
  112. data/lib/contrast/agent_lib/api/method_tempering.rb +29 -0
  113. data/lib/contrast/agent_lib/api/panic.rb +87 -0
  114. data/lib/contrast/agent_lib/api/path_semantic_file_security_bypass.rb +40 -0
  115. data/lib/contrast/agent_lib/interface.rb +260 -0
  116. data/lib/contrast/agent_lib/interface_base.rb +118 -0
  117. data/lib/contrast/agent_lib/return_types/eval_result.rb +44 -0
  118. data/lib/contrast/agent_lib/test.rb +29 -0
  119. data/lib/contrast/api/communication/connection_status.rb +20 -5
  120. data/lib/contrast/components/agent.rb +34 -14
  121. data/lib/contrast/components/api.rb +23 -0
  122. data/lib/contrast/components/app_context.rb +23 -5
  123. data/lib/contrast/components/app_context_extend.rb +0 -25
  124. data/lib/contrast/components/assess.rb +34 -4
  125. data/lib/contrast/components/assess_rules.rb +18 -0
  126. data/lib/contrast/components/base.rb +40 -0
  127. data/lib/contrast/components/config/sources.rb +95 -0
  128. data/lib/contrast/components/config.rb +19 -19
  129. data/lib/contrast/components/heap_dump.rb +10 -0
  130. data/lib/contrast/components/inventory.rb +15 -2
  131. data/lib/contrast/components/logger.rb +18 -0
  132. data/lib/contrast/components/polling.rb +36 -0
  133. data/lib/contrast/components/protect.rb +52 -2
  134. data/lib/contrast/components/ruby_component.rb +16 -1
  135. data/lib/contrast/components/sampling.rb +70 -13
  136. data/lib/contrast/components/security_logger.rb +13 -0
  137. data/lib/contrast/components/settings.rb +105 -90
  138. data/lib/contrast/config/certification_configuration.rb +14 -0
  139. data/lib/contrast/config/config.rb +46 -0
  140. data/lib/contrast/config/diagnostics.rb +114 -0
  141. data/lib/contrast/config/diagnostics_tools.rb +98 -0
  142. data/lib/contrast/config/effective_config.rb +65 -0
  143. data/lib/contrast/config/effective_config_value.rb +32 -0
  144. data/lib/contrast/config/exception_configuration.rb +12 -0
  145. data/lib/contrast/config/protect_rule_configuration.rb +8 -8
  146. data/lib/contrast/config/protect_rules_configuration.rb +23 -60
  147. data/lib/contrast/config/request_audit_configuration.rb +13 -0
  148. data/lib/contrast/config/server_configuration.rb +41 -2
  149. data/lib/contrast/configuration.rb +29 -12
  150. data/lib/contrast/extension/assess/array.rb +9 -0
  151. data/lib/contrast/extension/assess/erb.rb +1 -1
  152. data/lib/contrast/extension/delegator.rb +2 -0
  153. data/lib/contrast/framework/manager.rb +3 -1
  154. data/lib/contrast/framework/rails/railtie.rb +0 -1
  155. data/lib/contrast/framework/rails/support.rb +0 -1
  156. data/lib/contrast/tasks/config.rb +1 -8
  157. data/lib/contrast/utils/assess/event_limit_utils.rb +31 -9
  158. data/lib/contrast/utils/assess/trigger_method_utils.rb +5 -4
  159. data/lib/contrast/utils/duck_utils.rb +1 -0
  160. data/lib/contrast/utils/hash_digest.rb +2 -2
  161. data/lib/contrast/utils/input_classification_base.rb +155 -0
  162. data/lib/contrast/utils/os.rb +0 -20
  163. data/lib/contrast/utils/reporting/application_activity_batch_utils.rb +81 -0
  164. data/lib/contrast/utils/response_utils.rb +0 -16
  165. data/lib/contrast/utils/routes_sent.rb +60 -0
  166. data/lib/contrast/utils/stack_trace_utils.rb +3 -15
  167. data/lib/contrast/utils/string_utils.rb +10 -7
  168. data/lib/contrast/utils/telemetry_client.rb +1 -2
  169. data/lib/contrast/utils/timer.rb +16 -0
  170. data/lib/contrast.rb +5 -4
  171. data/resources/protect/policy.json +1 -2
  172. data/ruby-agent.gemspec +7 -6
  173. metadata +69 -130
  174. data/exe/contrast_service +0 -23
  175. data/lib/contrast/agent/assess/contrast_event.rb +0 -157
  176. data/lib/contrast/agent/assess/events/event_factory.rb +0 -34
  177. data/lib/contrast/agent/assess/events/source_event.rb +0 -46
  178. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +0 -64
  179. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +0 -118
  180. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +0 -45
  181. data/lib/contrast/agent/reaction_processor.rb +0 -47
  182. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +0 -36
  183. data/lib/contrast/agent/service_heartbeat.rb +0 -35
  184. data/lib/contrast/api/communication/messaging_queue.rb +0 -128
  185. data/lib/contrast/api/communication/response_processor.rb +0 -90
  186. data/lib/contrast/api/communication/service_lifecycle.rb +0 -77
  187. data/lib/contrast/api/communication/socket.rb +0 -44
  188. data/lib/contrast/api/communication/socket_client.rb +0 -130
  189. data/lib/contrast/api/communication/speedracer.rb +0 -138
  190. data/lib/contrast/api/communication/tcp_socket.rb +0 -32
  191. data/lib/contrast/api/communication/unix_socket.rb +0 -28
  192. data/lib/contrast/api/communication.rb +0 -20
  193. data/lib/contrast/api/decorators/address.rb +0 -59
  194. data/lib/contrast/api/decorators/agent_startup.rb +0 -56
  195. data/lib/contrast/api/decorators/application_settings.rb +0 -43
  196. data/lib/contrast/api/decorators/application_startup.rb +0 -56
  197. data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
  198. data/lib/contrast/api/decorators/http_request.rb +0 -137
  199. data/lib/contrast/api/decorators/input_analysis.rb +0 -18
  200. data/lib/contrast/api/decorators/instrumentation_mode.rb +0 -35
  201. data/lib/contrast/api/decorators/ip_denylist.rb +0 -37
  202. data/lib/contrast/api/decorators/message.rb +0 -67
  203. data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -52
  204. data/lib/contrast/api/decorators/response_type.rb +0 -17
  205. data/lib/contrast/api/decorators/server_features.rb +0 -25
  206. data/lib/contrast/api/decorators/user_input.rb +0 -51
  207. data/lib/contrast/api/decorators/virtual_patch.rb +0 -34
  208. data/lib/contrast/api/decorators.rb +0 -22
  209. data/lib/contrast/api/dtm.pb.rb +0 -363
  210. data/lib/contrast/api/settings.pb.rb +0 -500
  211. data/lib/contrast/api.rb +0 -16
  212. data/lib/contrast/components/contrast_service.rb +0 -88
  213. data/lib/contrast/components/service.rb +0 -55
  214. data/lib/contrast/tasks/service.rb +0 -84
  215. data/lib/contrast/utils/input_classification.rb +0 -73
  216. data/lib/protobuf/code_generator.rb +0 -129
  217. data/lib/protobuf/decoder.rb +0 -28
  218. data/lib/protobuf/deprecation.rb +0 -117
  219. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +0 -79
  220. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +0 -360
  221. data/lib/protobuf/descriptors.rb +0 -3
  222. data/lib/protobuf/encoder.rb +0 -11
  223. data/lib/protobuf/enum.rb +0 -365
  224. data/lib/protobuf/exceptions.rb +0 -9
  225. data/lib/protobuf/field/base_field.rb +0 -380
  226. data/lib/protobuf/field/base_field_object_definitions.rb +0 -504
  227. data/lib/protobuf/field/bool_field.rb +0 -64
  228. data/lib/protobuf/field/bytes_field.rb +0 -67
  229. data/lib/protobuf/field/double_field.rb +0 -25
  230. data/lib/protobuf/field/enum_field.rb +0 -56
  231. data/lib/protobuf/field/field_array.rb +0 -102
  232. data/lib/protobuf/field/field_hash.rb +0 -122
  233. data/lib/protobuf/field/fixed32_field.rb +0 -25
  234. data/lib/protobuf/field/fixed64_field.rb +0 -28
  235. data/lib/protobuf/field/float_field.rb +0 -43
  236. data/lib/protobuf/field/int32_field.rb +0 -21
  237. data/lib/protobuf/field/int64_field.rb +0 -34
  238. data/lib/protobuf/field/integer_field.rb +0 -23
  239. data/lib/protobuf/field/message_field.rb +0 -51
  240. data/lib/protobuf/field/sfixed32_field.rb +0 -27
  241. data/lib/protobuf/field/sfixed64_field.rb +0 -28
  242. data/lib/protobuf/field/signed_integer_field.rb +0 -29
  243. data/lib/protobuf/field/sint32_field.rb +0 -21
  244. data/lib/protobuf/field/sint64_field.rb +0 -21
  245. data/lib/protobuf/field/string_field.rb +0 -51
  246. data/lib/protobuf/field/uint32_field.rb +0 -21
  247. data/lib/protobuf/field/uint64_field.rb +0 -21
  248. data/lib/protobuf/field/varint_field.rb +0 -77
  249. data/lib/protobuf/field.rb +0 -74
  250. data/lib/protobuf/generators/base.rb +0 -85
  251. data/lib/protobuf/generators/enum_generator.rb +0 -39
  252. data/lib/protobuf/generators/extension_generator.rb +0 -27
  253. data/lib/protobuf/generators/field_generator.rb +0 -193
  254. data/lib/protobuf/generators/file_generator.rb +0 -262
  255. data/lib/protobuf/generators/group_generator.rb +0 -122
  256. data/lib/protobuf/generators/message_generator.rb +0 -104
  257. data/lib/protobuf/generators/option_generator.rb +0 -17
  258. data/lib/protobuf/generators/printable.rb +0 -160
  259. data/lib/protobuf/generators/service_generator.rb +0 -50
  260. data/lib/protobuf/lifecycle.rb +0 -33
  261. data/lib/protobuf/logging.rb +0 -39
  262. data/lib/protobuf/message/fields.rb +0 -233
  263. data/lib/protobuf/message/serialization.rb +0 -85
  264. data/lib/protobuf/message.rb +0 -241
  265. data/lib/protobuf/optionable.rb +0 -72
  266. data/lib/protobuf/tasks/compile.rake +0 -80
  267. data/lib/protobuf/tasks.rb +0 -1
  268. data/lib/protobuf/varint.rb +0 -20
  269. data/lib/protobuf/varint_pure.rb +0 -31
  270. data/lib/protobuf/version.rb +0 -3
  271. data/lib/protobuf/wire_type.rb +0 -10
  272. data/lib/protobuf.rb +0 -91
  273. data/proto/dynamic_discovery.proto +0 -46
  274. data/proto/google/protobuf/compiler/plugin.proto +0 -183
  275. data/proto/google/protobuf/descriptor.proto +0 -911
  276. data/proto/rpc.proto +0 -71
  277. data/service_executables/.gitkeep +0 -0
  278. data/service_executables/VERSION +0 -1
  279. data/service_executables/linux/contrast-service +0 -0
  280. data/service_executables/mac/contrast-service +0 -0
@@ -13,6 +13,14 @@ module Contrast
13
13
  Contrast::Logger::Log.instance.logger
14
14
  end
15
15
 
16
+ # When calling this method from any instance
17
+ # The CEF logger will be initialized and it's
18
+ # path and level will be set. Since we don't
19
+ # call this method unless protect is started,
20
+ # on Agent Startup no file is created before is
21
+ # needed.
22
+ #
23
+ # @return [Logger]
16
24
  def cef_logger
17
25
  @_cef_logger ||= Contrast::Logger::CEFLog.instance.tap(&:build_logger)
18
26
  end
@@ -23,6 +31,10 @@ module Contrast
23
31
  # instance methods and will initialize new instances for where they're needed
24
32
  class Interface
25
33
  include InstanceMethods
34
+ include Contrast::Components::ComponentBase
35
+
36
+ CANON_NAME = 'agent.logger'
37
+ CONFIG_VALUES = %w[path level progname].cs__freeze
26
38
 
27
39
  # @return [String, nil]
28
40
  attr_accessor :path
@@ -30,8 +42,14 @@ module Contrast
30
42
  attr_accessor :level
31
43
  # @return [String, nil]
32
44
  attr_accessor :progname
45
+ # @return [String]
46
+ attr_reader :canon_name
47
+ # @return [Array]
48
+ attr_reader :config_values
33
49
 
34
50
  def initialize hsh = {}
51
+ @config_values = CONFIG_VALUES
52
+ @canon_name = CANON_NAME
35
53
  return unless hsh
36
54
 
37
55
  @path = hsh[:path]
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/components/base'
5
+
6
+ module Contrast
7
+ module Components
8
+ module Polling
9
+ # A wrapper build around the agent.polling config
10
+ class Interface
11
+ include Contrast::Components::ComponentBase
12
+
13
+ # @return [Integer, nil]
14
+ attr_reader :server_settings_ms
15
+ # @return [String]
16
+ attr_reader :canon_name
17
+ # @return [Array]
18
+ attr_reader :config_values
19
+ # @return [Integer, nil]
20
+ attr_reader :batch_reporting_interval_ms
21
+
22
+ CANON_NAME = 'agent.polling'
23
+ CONFIG_VALUES = %w[server_settings_ms batch_reporting_interval_ms].cs__freeze
24
+
25
+ def initialize hsh = {}
26
+ @config_values = CONFIG_VALUES
27
+ @canon_name = CANON_NAME
28
+ return unless hsh
29
+
30
+ @server_settings_ms = hsh[:server_settings_ms]
31
+ @batch_reporting_interval_ms = hsh[:batch_reporting_interval_ms]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -14,15 +14,29 @@ module Contrast
14
14
  include Contrast::Components::ComponentBase
15
15
  include Contrast::Config::BaseConfiguration
16
16
 
17
+ CANON_NAME = 'protect'
18
+ CONFIG_VALUES = %w[enabled?].cs__freeze
19
+ RULES = 'rules'
20
+ MODE = 'mode'
21
+
17
22
  # @return [Boolean, nil]
18
23
  attr_accessor :enable
24
+ # @return [String]
25
+ attr_reader :canon_name
26
+ # @return [Array]
27
+ attr_reader :config_values
28
+ # @return [Boolean, nil]
29
+ attr_accessor :agent_lib
19
30
 
20
31
  def initialize hsh = {}
32
+ @config_values = CONFIG_VALUES
33
+ @canon_name = CANON_NAME
21
34
  return unless hsh
22
35
 
23
36
  @_exceptions = Contrast::Config::ExceptionConfiguration.new(hsh[:exceptions])
24
37
  @_rules = Contrast::Config::ProtectRulesConfiguration.new(hsh[:rules])
25
38
  @enable = hsh[:enable]
39
+ @agent_lib = hsh[:agent_lib]
26
40
  end
27
41
 
28
42
  # @return [Contrast::Config::ExceptionConfiguration]
@@ -54,6 +68,9 @@ module Contrast
54
68
  ::Contrast::SETTINGS.protect_state.enabled == true
55
69
  end
56
70
 
71
+ # Current Configuration for the protect rules
72
+ #
73
+ # @return [Contrast::Config::ProtectRulesConfiguration]
57
74
  def rule_config
58
75
  ::Contrast::CONFIG.protect.rules
59
76
  end
@@ -62,18 +79,27 @@ module Contrast
62
79
  # protect rules.
63
80
  #
64
81
  # @return defend_rules[Hash<Contrast::SETTINGS.protect_state.rules>]
65
- #
66
82
  def defend_rules
67
83
  ::Contrast::SETTINGS.protect_state.rules
68
84
  end
69
85
 
86
+ # The Contrast::CONFIG.protect.rules is object so we need to check it's
87
+ # corresponding method call for each rule of interest. If there is no
88
+ # status available we search for any Settings available received form
89
+ # TS response.
90
+ #
91
+ # @param rule_id [String]
92
+ # @return mode [Symbol]
70
93
  def rule_mode rule_id
71
94
  str = rule_id.tr('-', '_')
72
95
  ::Contrast::CONFIG.protect.rules[str]&.applicable_mode ||
73
96
  ::Contrast::SETTINGS.application_state.modes_by_id[rule_id] ||
74
- Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
97
+ :NO_ACTION
75
98
  end
76
99
 
100
+ # Name of the protect rule
101
+ #
102
+ # @return [String]
77
103
  def rule name
78
104
  ::Contrast::SETTINGS.protect_state.rules[name]
79
105
  end
@@ -101,8 +127,32 @@ module Contrast
101
127
  @_forcibly_disabled = false?(::Contrast::CONFIG.protect.enable)
102
128
  end
103
129
 
130
+ # Converts current configuration to effective config values class and appends them to
131
+ # EffectiveConfig class.
132
+ #
133
+ # @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
134
+ def to_effective_config effective_config
135
+ super
136
+ protect_rules_to_effective_config(effective_config)
137
+ end
138
+
104
139
  private
105
140
 
141
+ # @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
142
+ def protect_rules_to_effective_config effective_config
143
+ return unless defend_rules
144
+
145
+ defend_rules.each do |key, value|
146
+ next unless key && value
147
+
148
+ config_prefix = "#{ CANON_NAME }.#{ RULES }.#{ key }"
149
+ name_prefix = "#{ CONTRAST }.#{ CANON_NAME }.#{ RULES }.#{ key }"
150
+ add_single_effective_value(effective_config, ENABLE, value.enabled?, config_prefix, name_prefix)
151
+ # Get the mode by checking Current Configs or Settings received:
152
+ add_single_effective_value(effective_config, MODE, rule_mode(key), config_prefix, name_prefix)
153
+ end
154
+ end
155
+
106
156
  def forcibly_enabled?
107
157
  return @_forcibly_enabled unless @_forcibly_enabled.nil?
108
158
 
@@ -1,6 +1,8 @@
1
1
  # Copyright (c) 2022 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/base'
5
+
4
6
  module Contrast
5
7
  module Components
6
8
  module Ruby
@@ -19,15 +21,28 @@ module Contrast
19
21
  log:clear middleware notes notes:custom rails:template rails:update routes secret spec spec:features
20
22
  spec:requests spec:controllers spec:helpers spec:models spec:views spec:routing spec:rcov stats
21
23
  test test:all test:all:db test:recent test:single test:uncommitted time:zones:all tmp:clear
22
- tmp:create webpacker:compile contrast:service:start contrast:service:status contrast:service:stop
24
+ tmp:create webpacker:compile
23
25
  ].cs__freeze
24
26
 
25
27
  DEFAULT_UNINSTRUMENTED_NAMESPACES = %w[FactoryGirl FactoryBot].cs__freeze
28
+ CANON_NAME = 'agent.ruby'
29
+ CONFIG_VALUES = %w[
30
+ disabled_agent_rake_tasks
31
+ propagate_yield require_scan
32
+ non_request_tracking
33
+ uninstrument_namespace
34
+ ].cs__freeze
26
35
 
27
36
  attr_writer :disabled_agent_rake_tasks, :exceptions, :propagate_yield, :require_scan,
28
37
  :non_request_tracking, :uninstrument_namespace
38
+ # @return [String]
39
+ attr_reader :canon_name
40
+ # @return [Array]
41
+ attr_reader :config_values
29
42
 
30
43
  def initialize hsh = {}
44
+ @config_values = CONFIG_VALUES
45
+ @canon_name = CANON_NAME
31
46
  return unless hsh
32
47
 
33
48
  @disabled_agent_rake_tasks = hsh[:disabled_agent_rake_tasks]
@@ -28,10 +28,10 @@ module Contrast
28
28
  settings = ::Contrast::SETTINGS&.assess_state&.sampling_settings
29
29
  {
30
30
  enabled: enabled?(config_settings, settings),
31
- baseline: baseline(config_settings, settings),
32
- request_frequency: request_frequency(config_settings, settings),
33
- response_frequency: response_frequency(config_settings, settings),
34
- window: window(config_settings, settings)
31
+ baseline: check_baseline(config_settings, settings),
32
+ request_frequency: check_request_frequency(config_settings, settings),
33
+ response_frequency: check_response_frequency(config_settings, settings),
34
+ window: check_window(config_settings, settings)
35
35
  }
36
36
  end
37
37
  end
@@ -45,7 +45,8 @@ module Contrast
45
45
 
46
46
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
47
47
  # local user input
48
- # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
48
+ # @param settings [Contrast::Agent::Reporting::Settings::Sampling, nil] the Sampling settings as provided by
49
+ # TeamServer
49
50
  # @return [Boolean] the resolution of the config_settings, settings, and default value
50
51
  def enabled? config_settings, settings
51
52
  true?([config_settings&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED].compact[0])
@@ -53,35 +54,39 @@ module Contrast
53
54
 
54
55
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
55
56
  # local user input
56
- # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
57
+ # @param settings [Contrast::Agent::Reporting::Settings::Sampling] the Sampling settings as provided by
58
+ # TeamServer
57
59
  # @return [Integer] the resolution of the config_settings, settings, and default value
58
- def baseline config_settings, settings
60
+ def check_baseline config_settings, settings
59
61
  [config_settings&.baseline, settings&.baseline].map(&:to_i).find(&:positive?) || DEFAULT_SAMPLING_BASELINE
60
62
  end
61
63
 
62
64
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
63
65
  # local user input
64
- # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
66
+ # @param settings [Contrast::Agent::Reporting::Settings::Sampling] the Sampling settings as provided by
67
+ # TeamServer
65
68
  # @return [Integer] the resolution of the config_settings, settings, and default value
66
- def request_frequency config_settings, settings
69
+ def check_request_frequency config_settings, settings
67
70
  [config_settings&.request_frequency, settings&.request_frequency].map(&:to_i).find(&:positive?) ||
68
71
  DEFAULT_SAMPLING_REQUEST_FREQUENCY
69
72
  end
70
73
 
71
74
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
72
75
  # local user input
73
- # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
76
+ # @param settings [Contrast::Agent::Reporting::Settings::Sampling] the Sampling settings as provided by
77
+ # TeamServer
74
78
  # @return [Integer] the resolution of the config_settings, settings, and default value
75
- def response_frequency config_settings, settings
79
+ def check_response_frequency config_settings, settings
76
80
  [config_settings&.response_frequency, settings&.response_frequency].map(&:to_i).find(&:positive?) ||
77
81
  DEFAULT_SAMPLING_RESPONSE_FREQUENCY
78
82
  end
79
83
 
80
84
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
81
85
  # local user input
82
- # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
86
+ # @param settings [Contrast::Agent::Reporting::Settings::Sampling] the Sampling settings as provided by
87
+ # TeamServer
83
88
  # @return [Integer] the resolution of the config_settings, settings, and default value
84
- def window config_settings, settings
89
+ def check_window config_settings, settings
85
90
  [config_settings&.window_ms, settings&.window_ms].map(&:to_i).find(&:positive?) || DEFAULT_SAMPLING_WINDOW_MS
86
91
  end
87
92
  end
@@ -94,8 +99,13 @@ module Contrast
94
99
 
95
100
  class Interface # :nodoc:
96
101
  include InstanceMethods
102
+ extend ClassMethods
97
103
  include Contrast::Config::BaseConfiguration
98
104
 
105
+ CANON_NAME = 'assess.sampling'
106
+ NAME_PREFIX = "#{ CONTRAST }.#{ CANON_NAME }"
107
+ CONFIG_VALUES = %w[enable baseline request_frequency response_frequency window_ms].cs__freeze
108
+
99
109
  # @return [Integer, nil]
100
110
  attr_reader :baseline
101
111
  # @return [Integer, nil]
@@ -104,8 +114,11 @@ module Contrast
104
114
  attr_reader :response_frequency
105
115
  # @return [Integer, nil]
106
116
  attr_reader :window_ms
117
+ # @return [String]
118
+ attr_reader :canon_name
107
119
 
108
120
  def initialize hsh = {}
121
+ @canon_name = CANON_NAME
109
122
  return unless hsh
110
123
 
111
124
  @enable = hsh[:enable]
@@ -119,6 +132,50 @@ module Contrast
119
132
  def enable
120
133
  !!@enable
121
134
  end
135
+
136
+ # Converts current configuration to effective config values class and appends them to
137
+ # EffectiveConfig class.
138
+ #
139
+ # @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
140
+ def to_effective_config effective_config
141
+ confirm_sources
142
+
143
+ add_single_effective_value(effective_config, 'enable', sampling_control[:enabled], canon_name, NAME_PREFIX)
144
+ add_single_effective_value(effective_config, 'baseline', sampling_control[:baseline], canon_name, NAME_PREFIX)
145
+ add_single_effective_value(effective_config, 'window_ms', sampling_control[:window], canon_name, NAME_PREFIX)
146
+ add_single_effective_value(effective_config,
147
+ 'request_frequency',
148
+ sampling_control[:request_frequency],
149
+ canon_name,
150
+ NAME_PREFIX)
151
+ add_single_effective_value(effective_config,
152
+ 'response_frequency',
153
+ sampling_control[:response_frequency],
154
+ canon_name,
155
+ NAME_PREFIX)
156
+ end
157
+
158
+ private
159
+
160
+ # Confirm the sources for the sample entries to ensure that we use 'Default' if we've fallen
161
+ # back to the default values.
162
+ def confirm_sources
163
+ if sampling_control[:enabled] == DEFAULT_SAMPLING_ENABLED
164
+ Contrast::CONFIG.sources.set('assess.sampling.enable', Contrast::Components::Config::Sources::DEFAULT)
165
+ end
166
+ if sampling_control[:window] == DEFAULT_SAMPLING_WINDOW_MS
167
+ Contrast::CONFIG.sources.set('assess.sampling.window_ms', Contrast::Components::Config::Sources::DEFAULT)
168
+ end
169
+ {
170
+ 'baseline' => :baseline,
171
+ 'request_frequency' => :request_frequency,
172
+ 'response_frequency' => :response_frequency
173
+ }.each do |k, v|
174
+ if sampling_control[v] == cs__class.cs__const_get("DEFAULT_SAMPLING_#{ v.upcase }")
175
+ Contrast::CONFIG.sources.set("assess.sampling.#{ k }", Contrast::Components::Config::Sources::DEFAULT)
176
+ end
177
+ end
178
+ end
122
179
  end
123
180
  end
124
181
  end
@@ -1,17 +1,30 @@
1
1
  # Copyright (c) 2022 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/base'
5
+
4
6
  module Contrast
5
7
  module Components
6
8
  module SecurityLogger
7
9
  # Here we will read and store the setting for the CEF Logging functionality
8
10
  class Interface
11
+ include Contrast::Components::ComponentBase
12
+
13
+ CANON_NAME = 'agent.security_logger'
14
+ CONFIG_VALUES = %w[path level].cs__freeze
15
+
9
16
  # @return [String, nil]
10
17
  attr_accessor :path
11
18
  # @return [String, nil]
12
19
  attr_accessor :level
20
+ # @return [String]
21
+ attr_reader :canon_name
22
+ # @return [Array]
23
+ attr_reader :config_values
13
24
 
14
25
  def initialize hsh = {}
26
+ @config_values = CONFIG_VALUES
27
+ @canon_name = CANON_NAME
15
28
  return unless hsh
16
29
 
17
30
  @path = hsh[:path]
@@ -1,10 +1,10 @@
1
1
  # Copyright (c) 2022 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/api/settings.pb'
5
4
  require 'contrast/agent/excluder'
6
5
  require 'contrast/agent/reporting/settings/sensitive_data_masking'
7
6
  require 'contrast/components/config'
7
+ require 'contrast/components/logger'
8
8
 
9
9
  module Contrast
10
10
  module Components
@@ -13,8 +13,7 @@ module Contrast
13
13
  # directives (likely provided by TeamServer) about product operation.
14
14
  # 'Settings' is not a generic term for 'configurable stuff'.
15
15
  module Settings
16
- APPLICATION_STATE_BASE = Struct.new(:modes_by_id, :exclusion_matchers).
17
- new(Hash.new(Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION), [])
16
+ APPLICATION_STATE_BASE = Struct.new(:modes_by_id).new(Hash.new(:NO_ACTION))
18
17
  PROTECT_STATE_BASE = Struct.new(:enabled, :rules).new(false, {})
19
18
  ASSESS_STATE_BASE = Struct.new(:enabled, :sampling_settings, :disabled_assess_rules, :session_id).new(false, nil,
20
19
  [], nil) do
@@ -27,6 +26,7 @@ module Contrast
27
26
 
28
27
  # This is a class.
29
28
  class Interface # rubocop:disable Metrics/ClassLength
29
+ include Contrast::Components::Logger::InstanceMethods
30
30
  extend Contrast::Components::Config
31
31
 
32
32
  # tainted_columns are database columns that receive unsanitized input.
@@ -55,30 +55,6 @@ module Contrast
55
55
  # Current Application State.
56
56
  #
57
57
  # modes_by_id [Hash<Rule_id => Mode] Returns Hash with rules and their current mode.
58
- # exclusion_matchers [Array] Array of all the exclusions.
59
- # code_exclusions [Array<CodeExclusion>] Array of CodeExclusion: {
60
- # name [String] The name of the exclusion as defined by the user in TS.
61
- # modes [String] If this exclusion applies to assess or protect. [assess, defend]
62
- # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
63
- # denylist [String] The call, if in the stack, should result in the agent not taking action.
64
- # input_exclusions [Array<InputExclusions>] Array of InputExclusions: {
65
- # name [String] The name of the input.
66
- # modes [String] If this exclusion applies to assess or protect. [assess, defend]
67
- # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
68
- # protect_rules [Array] Array of ProtectRuleID [String] The protect rules to which this exclusion applies.
69
- # urls [Array] Array of URLs to which the exclusions apply. URL [String]
70
- # match_strategy [String] If this exclusion applies to all URLs or only those specified. [ALL, ONLY]
71
- # type [String] The type of the input [COOKIE, PARAMETER, HEADER, BODY, QUERYSTRING]
72
- # }
73
- # url_exclusions [Array<UrlExclusions>] Array of UrlExclusions: {
74
- # name [String] The name of the input.
75
- # modes [String] If this exclusion applies to assess or protect. [assess, defend]
76
- # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
77
- # protect_rules [Array] Array of ProtectRuleID [String] The protect rules to which this exclusion applies.
78
- # urls [Array] Array of URLs to which the exclusions apply. URL [String]
79
- # match_strategy [String] If this exclusion applies to all URLs or only those specified. [ALL, ONLY]
80
- # type [String] The type of the input [COOKIE, PARAMETER, HEADER, BODY, QUERYSTRING]
81
- # }
82
58
  attr_reader :application_state
83
59
  # This the structure that will hold the masking rules send from TS.
84
60
  #
@@ -94,43 +70,75 @@ module Contrast
94
70
  attr_reader :last_server_update_ms
95
71
  # @return [Contrast::Agent::Excluder] a wrapper around the exclusion rules for the application
96
72
  attr_reader :excluder
73
+ # @return [String] The last update but in string format used to build request header.
74
+ # This value should be sent be TS in the Last-Modified header to sync and save resources if the
75
+ # two dates are the same.
76
+ # format: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
77
+ attr_reader :server_settings_last_httpdate
97
78
 
98
79
  def initialize
99
80
  reset_state
100
81
  end
101
82
 
102
83
  def code_exclusions
103
- @application_state.exclusion_matchers.select(&:code?)
84
+ excluder&.exclusions&.select(&:code?)
104
85
  end
105
86
 
106
- # @param features_response [Contrast::Api::Settings::ServerFeatures, Contrast::Agent::Reporting::Response]
87
+ # @param features_response [Contrast::Agent::Reporting::Response]
107
88
  def update_from_server_features features_response
108
- if features_response.cs__is_a?(Contrast::Agent::Reporting::Response)
109
- update_from_response(features_response)
110
- else
111
- @protect_state.enabled = features_response.protect_enabled?
112
- @assess_state.enabled = features_response.assess_enabled?
113
- @assess_state.sampling_settings = features_response.assess.sampling
114
- @last_server_update_ms = Contrast::Utils::Timer.now_ms
89
+ return unless (server_features = features_response&.server_features)
90
+
91
+ log_file = server_features.log_file
92
+ log_level = server_features.log_level
93
+ # Update logger:
94
+ Contrast::Logger::Log.instance.update(log_file, log_level) if log_file || log_level
95
+ # Update CEFlogger:
96
+ unless server_features.security_logger.settings_blank?
97
+ cef_logger.build_logger(server_features.security_logger.log_level, server_features.security_logger.log_file)
98
+ end
99
+ # TODO: RUBY-99999 Update Bot-Blocker from server settings - check enable value.
100
+ # For now all protection rules are rebuild on Application update. Bot blocker uses the default
101
+ # enable from the base rule, and update it's mode on app settings update.
102
+ # Here we receive also bots for that rule.
103
+ unless settings_empty?(server_features.protect.enabled?)
104
+ @protect_state.enabled = server_features.protect.enabled?
105
+ store_in_config(%i[protect enable], server_features.protect.enabled?)
115
106
  end
107
+ update_assess_server_features(server_features.assess)
116
108
  @last_server_update_ms = Contrast::Utils::Timer.now_ms
109
+ # update via response header. We receive header from TS with last update info, setting the
110
+ # next request's header with the same time will save needless update of settings if there
111
+ # are no new server features updates after the said time.
112
+ @server_settings_last_httpdate = header_last_update
117
113
  end
118
114
 
119
- # @param settings_response [Contrast::Api::Settings::ApplicationSettings, Contrast::Agent::Reporting::Response]
120
- def update_from_application_settings settings_response
121
- if settings_response&.cs__class == Contrast::Agent::Reporting::Response
122
- update_from_response(settings_response)
123
- else
124
- new_vals = settings_response.application_state_translation
125
- @application_state.modes_by_id = new_vals[:modes_by_id]
126
- @application_state.exclusion_matchers = new_vals[:exclusion_matchers]
127
- @excluder = Contrast::Agent::Excluder.new(@application_state.exclusion_matchers)
128
- @assess_state.disabled_assess_rules = new_vals[:disabled_assess_rules]
129
- if settings_response.session_id && !settings_response.session_id.blank?
130
- @assess_state.session_id = settings_response.session_id
131
- end
132
- @last_app_update_ms = Contrast::Utils::Timer.now_ms
115
+ # Update Assess server features
116
+ #
117
+ # @param assess [Contrast::Agent::Reporting::Settings::AssessServerFeature]
118
+ def update_assess_server_features assess
119
+ return if settings_empty?(assess.enabled?)
120
+
121
+ @assess_state.enabled = assess.enabled?
122
+ store_in_config(%i[assess enable], assess.enabled?)
123
+ @assess_state.sampling_settings = assess.sampling
124
+
125
+ Contrast::Components::Sampling::Interface::CONFIG_VALUES.each do |field|
126
+ lookup_field = field == 'enable' ? :enabled : field.to_sym
127
+ store_in_config(Contrast::Components::Sampling::Interface::CANON_NAME.split('.') + [field.to_sym],
128
+ assess.sampling.send(lookup_field))
133
129
  end
130
+ end
131
+
132
+ # @param settings_response [Contrast::Agent::Reporting::Response]
133
+ def update_from_application_settings settings_response
134
+ return unless (app_settings = settings_response&.application_settings)
135
+
136
+ @application_state.modes_by_id = app_settings.protect.protection_rules_to_settings_hash
137
+ update_exclusion_matchers(app_settings.exclusions)
138
+ update_sensitive_data_policy(app_settings.sensitive_data_masking)
139
+ @assess_state.disabled_assess_rules = app_settings.assess.disabled_rules
140
+ new_session_id = app_settings.assess.session_id
141
+ @assess_state.session_id = new_session_id if new_session_id && !new_session_id.blank?
134
142
  @last_app_update_ms = Contrast::Utils::Timer.now_ms
135
143
  end
136
144
 
@@ -148,17 +156,36 @@ module Contrast
148
156
  @protect_state.rules = {}
149
157
 
150
158
  # Rules. They add themselves on initialize.
151
- Contrast::Agent::Protect::Rule::CmdInjection.new
159
+ Contrast::Agent::Protect::Rule::BotBlocker.new
160
+ cmdi = Contrast::Agent::Protect::Rule::CmdInjection.new
161
+ cmdi.sub_rules
152
162
  Contrast::Agent::Protect::Rule::Deserialization.new
153
163
  Contrast::Agent::Protect::Rule::HttpMethodTampering.new
154
164
  Contrast::Agent::Protect::Rule::NoSqli.new
155
- Contrast::Agent::Protect::Rule::PathTraversal.new
156
- Contrast::Agent::Protect::Rule::Sqli.new
165
+ path = Contrast::Agent::Protect::Rule::PathTraversal.new
166
+ path.sub_rules
167
+ sqli = Contrast::Agent::Protect::Rule::Sqli.new
168
+ sqli.sub_rules
157
169
  Contrast::Agent::Protect::Rule::UnsafeFileUpload.new
158
170
  Contrast::Agent::Protect::Rule::Xss.new
159
171
  Contrast::Agent::Protect::Rule::Xxe.new
160
172
  end
161
173
 
174
+ # @param exclusions [Contrast::Agent::Reporting::Settings::Exclusions]
175
+ def update_exclusion_matchers exclusions
176
+ matchers = []
177
+ exclusions.url_exclusions.each do |exclusion|
178
+ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion)
179
+ end
180
+ exclusions.input_exclusions.each do |exclusion|
181
+ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion)
182
+ end
183
+ exclusions.code_exclusions.each do |exclusion|
184
+ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion)
185
+ end
186
+ @excluder = Contrast::Agent::Excluder.new(matchers)
187
+ end
188
+
162
189
  # Update the sensitive data masking policy from settings,
163
190
  # received from TS. In case the settings are empty,
164
191
  # keep current ones.
@@ -179,43 +206,6 @@ module Contrast
179
206
 
180
207
  private
181
208
 
182
- # @param response [Contrast::Agent::Reporting::Response]
183
- def update_from_response response
184
- if (server_features = response.server_features)
185
- update_server_features(server_features)
186
- end
187
- return unless (app_settings = response.application_settings)
188
-
189
- update_application_settings(app_settings)
190
- end
191
-
192
- # @param server_features [Contrast::Agent::Reporting::Settings::FeatureSettings]
193
- def update_server_features server_features
194
- return unless server_features
195
-
196
- log_file = server_features.log_file
197
- log_level = server_features.log_level
198
- Contrast::Logger::Log.instance.update(log_file, log_level) if log_file || log_level
199
- @protect_state.enabled = server_features.protect.enabled?
200
- @assess_state.enabled = server_features.assess.enabled?
201
- @assess_state.sampling_settings = server_features.assess.sampling
202
- @last_server_update_ms = Contrast::Utils::Timer.now_ms
203
- end
204
-
205
- # @param app_settings [Contrast::Agent::Reporting::Settings::ApplicationSettings]
206
- def update_application_settings app_settings
207
- return unless app_settings
208
-
209
- @application_state.modes_by_id = app_settings.protect.protection_rules_to_settings_hash
210
- # TODO: RUBY-1438 this needs to be translated
211
- # @application_state.exclusion_matchers = new_vals[:exclusion_matchers]
212
- update_sensitive_data_policy(app_settings.sensitive_data_masking)
213
- @assess_state.disabled_assess_rules = app_settings.assess.disabled_rules
214
- new_session_id = app_settings.assess.session_id
215
- @assess_state.session_id = new_session_id if new_session_id && !new_session_id.blank?
216
- @last_app_update_ms = Contrast::Utils::Timer.now_ms
217
- end
218
-
219
209
  # check if settings are empty and return true if so.
220
210
  #
221
211
  # @param settings [String, Boolean, Array, Hash]
@@ -226,6 +216,31 @@ module Contrast
226
216
 
227
217
  false
228
218
  end
219
+
220
+ # update via response header.
221
+ # Used to build the next request header.
222
+ #
223
+ # @return [String]
224
+ def header_last_update
225
+ Contrast::Agent.reporter.client.response_handler.last_server_modified
226
+ end
227
+
228
+ # Update the stored config values to ensure that we know about the correct values,
229
+ # and that the sources are correct for entries updated from the UI.
230
+ #
231
+ # @param parts [Array] the path to the setting in config
232
+ # @param value [String, Integer, Array, nil] the value for the configuration setting
233
+ def store_in_config parts, value
234
+ level = Contrast::CONFIG.config.loaded_config
235
+ parts[0...-1].each do |segment|
236
+ level[segment] ||= {}
237
+ level = level[segment]
238
+ end
239
+ return unless level.cs__is_a?(Hash)
240
+
241
+ level[parts[-1]] = value
242
+ Contrast::CONFIG.sources.set(parts.join('.'), Contrast::Components::Config::Sources::CONTRASTUI)
243
+ end
229
244
  end
230
245
  end
231
246
  end