contrast-agent 5.1.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_array/cs__assess_array.c +7 -0
  3. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
  4. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  5. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  6. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -5
  7. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  8. data/ext/cs__assess_module/cs__assess_module.c +7 -7
  9. data/ext/cs__assess_string/cs__assess_string.c +13 -1
  10. data/ext/cs__common/cs__common.c +16 -11
  11. data/ext/cs__common/cs__common.h +1 -0
  12. data/ext/cs__contrast_patch/cs__contrast_patch.c +100 -64
  13. data/ext/cs__contrast_patch/cs__contrast_patch.h +2 -0
  14. data/ext/cs__os_information/cs__os_information.c +13 -10
  15. data/ext/cs__scope/cs__scope.c +796 -0
  16. data/ext/cs__scope/cs__scope.h +88 -0
  17. data/ext/cs__scope/extconf.rb +5 -0
  18. data/lib/contrast/agent/assess/contrast_event.rb +20 -13
  19. data/lib/contrast/agent/assess/contrast_object.rb +4 -1
  20. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
  21. data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
  22. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  23. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  24. data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
  25. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -5
  26. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
  27. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  28. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -0
  29. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  30. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  31. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  32. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  33. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  34. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  35. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  36. data/lib/contrast/agent/assess/policy/trigger_method.rb +6 -1
  37. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  38. data/lib/contrast/agent/assess/rule/response/{autocomplete_rule.rb → auto_complete_rule.rb} +4 -3
  39. data/lib/contrast/agent/assess/rule/response/base_rule.rb +12 -79
  40. data/lib/contrast/agent/assess/rule/response/body_rule.rb +109 -0
  41. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +157 -0
  42. data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +26 -0
  43. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +14 -15
  44. data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +5 -25
  45. data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +29 -0
  46. data/lib/contrast/agent/assess/rule/response/header_rule.rb +70 -0
  47. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +12 -36
  48. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +2 -1
  49. data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +26 -0
  50. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +35 -0
  51. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  52. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  53. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  54. data/lib/contrast/agent/middleware.rb +4 -1
  55. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +1 -3
  56. data/lib/contrast/agent/patching/policy/patch.rb +2 -6
  57. data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
  58. data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
  59. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  60. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +147 -0
  61. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
  62. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
  63. data/lib/contrast/agent/protect/rule/base.rb +61 -2
  64. data/lib/contrast/agent/protect/rule/base_service.rb +12 -1
  65. data/lib/contrast/agent/protect/rule/cmd_injection.rb +15 -0
  66. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  67. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  68. data/lib/contrast/agent/protect/rule/deserialization.rb +6 -0
  69. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  70. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +13 -1
  71. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  72. data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -0
  73. data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -0
  74. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +88 -0
  75. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +118 -0
  76. data/lib/contrast/agent/protect/rule/sqli.rb +33 -0
  77. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  78. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  79. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  80. data/lib/contrast/agent/protect/rule/xxe.rb +4 -0
  81. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  82. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  83. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  84. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  85. data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +44 -0
  86. data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +115 -0
  87. data/lib/contrast/agent/reporting/input_analysis/input_type.rb +44 -0
  88. data/lib/contrast/agent/reporting/input_analysis/score_level.rb +21 -0
  89. data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
  90. data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
  91. data/lib/contrast/agent/reporting/report.rb +3 -0
  92. data/lib/contrast/agent/reporting/reporter.rb +31 -12
  93. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
  94. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
  95. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
  96. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  97. data/lib/contrast/agent/reporting/reporting_events/finding.rb +69 -36
  98. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +88 -59
  99. data/lib/contrast/agent/reporting/reporting_events/{finding_object.rb → finding_event_object.rb} +24 -20
  100. data/lib/contrast/agent/reporting/reporting_events/finding_event_parent_object.rb +39 -0
  101. data/lib/contrast/agent/reporting/reporting_events/finding_event_property.rb +40 -0
  102. data/lib/contrast/agent/reporting/reporting_events/{finding_signature.rb → finding_event_signature.rb} +29 -24
  103. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +12 -8
  104. data/lib/contrast/agent/reporting/reporting_events/{finding_stack.rb → finding_event_stack.rb} +23 -19
  105. data/lib/contrast/agent/reporting/reporting_events/{finding_taint_range.rb → finding_event_taint_range.rb} +17 -15
  106. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +26 -53
  107. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  108. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
  109. data/lib/contrast/agent/reporting/reporting_events/poll.rb +29 -0
  110. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
  111. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +6 -4
  112. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  113. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +1 -0
  114. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +1 -1
  115. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +10 -3
  116. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +0 -1
  117. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +17 -5
  118. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -45
  119. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  120. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
  121. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +69 -7
  122. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  123. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +123 -85
  124. data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
  125. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
  126. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
  127. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  128. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  129. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  130. data/lib/contrast/agent/request_context.rb +7 -2
  131. data/lib/contrast/agent/request_context_extend.rb +85 -21
  132. data/lib/contrast/agent/request_handler.rb +4 -0
  133. data/lib/contrast/agent/scope.rb +102 -107
  134. data/lib/contrast/agent/service_heartbeat.rb +45 -2
  135. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
  136. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
  137. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
  138. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
  139. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
  140. data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
  141. data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
  142. data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
  143. data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
  144. data/lib/contrast/agent/thread_watcher.rb +1 -1
  145. data/lib/contrast/agent/version.rb +1 -1
  146. data/lib/contrast/agent.rb +3 -0
  147. data/lib/contrast/api/communication/speedracer.rb +1 -1
  148. data/lib/contrast/api/decorators/address.rb +1 -1
  149. data/lib/contrast/api/decorators/bot_blocker.rb +37 -0
  150. data/lib/contrast/api/decorators/ip_denylist.rb +37 -0
  151. data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
  152. data/lib/contrast/api/decorators/response_type.rb +30 -0
  153. data/lib/contrast/api/decorators/user_input.rb +11 -1
  154. data/lib/contrast/api/decorators/virtual_patch.rb +34 -0
  155. data/lib/contrast/api/decorators.rb +1 -0
  156. data/lib/contrast/components/app_context.rb +0 -4
  157. data/lib/contrast/components/assess.rb +14 -0
  158. data/lib/contrast/components/logger.rb +5 -0
  159. data/lib/contrast/components/protect.rb +6 -4
  160. data/lib/contrast/components/sampling.rb +7 -11
  161. data/lib/contrast/components/scope.rb +98 -91
  162. data/lib/contrast/components/settings.rb +106 -8
  163. data/lib/contrast/config/agent_configuration.rb +41 -12
  164. data/lib/contrast/config/api_configuration.rb +37 -12
  165. data/lib/contrast/config/api_proxy_configuration.rb +12 -3
  166. data/lib/contrast/config/application_configuration.rb +38 -14
  167. data/lib/contrast/config/assess_configuration.rb +47 -12
  168. data/lib/contrast/config/assess_rules_configuration.rb +15 -3
  169. data/lib/contrast/config/base_configuration.rb +18 -50
  170. data/lib/contrast/config/certification_configuration.rb +17 -3
  171. data/lib/contrast/config/exception_configuration.rb +14 -3
  172. data/lib/contrast/config/heap_dump_configuration.rb +43 -17
  173. data/lib/contrast/config/inventory_configuration.rb +17 -3
  174. data/lib/contrast/config/logger_configuration.rb +10 -3
  175. data/lib/contrast/config/protect_configuration.rb +17 -7
  176. data/lib/contrast/config/protect_rule_configuration.rb +17 -8
  177. data/lib/contrast/config/protect_rules_configuration.rb +115 -17
  178. data/lib/contrast/config/request_audit_configuration.rb +26 -3
  179. data/lib/contrast/config/root_configuration.rb +52 -12
  180. data/lib/contrast/config/ruby_configuration.rb +60 -22
  181. data/lib/contrast/config/sampling_configuration.rb +19 -9
  182. data/lib/contrast/config/server_configuration.rb +19 -10
  183. data/lib/contrast/config/service_configuration.rb +27 -11
  184. data/lib/contrast/configuration.rb +5 -3
  185. data/lib/contrast/extension/assess/string.rb +20 -1
  186. data/lib/contrast/extension/module.rb +0 -1
  187. data/lib/contrast/framework/manager.rb +2 -2
  188. data/lib/contrast/logger/application.rb +1 -1
  189. data/lib/contrast/logger/cef_log.rb +151 -0
  190. data/lib/contrast/tasks/config.rb +90 -3
  191. data/lib/contrast/utils/assess/object_store.rb +36 -0
  192. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  193. data/lib/contrast/utils/class_util.rb +3 -12
  194. data/lib/contrast/utils/hash_digest.rb +14 -6
  195. data/lib/contrast/utils/input_classification.rb +73 -0
  196. data/lib/contrast/utils/log_utils.rb +114 -0
  197. data/lib/contrast/utils/middleware_utils.rb +9 -9
  198. data/lib/contrast/utils/net_http_base.rb +13 -10
  199. data/lib/contrast/utils/object_share.rb +2 -1
  200. data/lib/contrast/utils/os.rb +0 -5
  201. data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -9
  202. data/lib/contrast/utils/response_utils.rb +18 -33
  203. data/lib/contrast/utils/telemetry.rb +1 -1
  204. data/lib/contrast/utils/telemetry_client.rb +1 -1
  205. data/lib/contrast/utils/telemetry_identifier.rb +1 -1
  206. data/lib/contrast.rb +4 -3
  207. data/resources/assess/policy.json +98 -0
  208. data/resources/deadzone/policy.json +0 -86
  209. data/ruby-agent.gemspec +9 -8
  210. data/service_executables/VERSION +1 -1
  211. data/service_executables/linux/contrast-service +0 -0
  212. data/service_executables/mac/contrast-service +0 -0
  213. metadata +103 -38
  214. data/lib/contrast/agent/assess/rule/response/cachecontrol_rule.rb +0 -184
  215. data/lib/contrast/agent/assess/rule/response/clickjacking_rule.rb +0 -66
  216. data/lib/contrast/agent/assess/rule/response/x_content_type_rule.rb +0 -52
  217. data/lib/contrast/agent/assess/rule/response/x_xss_protection_rule.rb +0 -53
  218. data/lib/contrast/extension/kernel.rb +0 -54
@@ -6,10 +6,22 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # disabled assess rule functionality of the Agent.
8
8
  class AssessRulesConfiguration < BaseConfiguration
9
- KEYS = { disabled_rules: EMPTY_VALUE }.cs__freeze
9
+ SPEC_KEY = :disabled_rules.cs__freeze
10
+ # @return [Array, nil] list of disabled assess rules
11
+ attr_accessor :disabled_rules
10
12
 
11
- def initialize hsh
12
- super(hsh, KEYS)
13
+ def initialize hsh = {}
14
+ @disabled_rules = cast_disabled_rules hsh
15
+ end
16
+
17
+ private
18
+
19
+ def cast_disabled_rules hsh
20
+ return unless hsh
21
+ return unless hsh.key?(SPEC_KEY)
22
+ return hsh[SPEC_KEY] if hsh[SPEC_KEY].cs__is_a?(Array)
23
+
24
+ hsh[SPEC_KEY].split(',').map(&:strip) if hsh[SPEC_KEY].cs__is_a?(String)
13
25
  end
14
26
  end
15
27
  end
@@ -12,24 +12,28 @@ module Contrast
12
12
  class BaseConfiguration
13
13
  extend Forwardable
14
14
 
15
- attr_reader :configuration_map
16
-
17
- alias_method :to_hash, :configuration_map
18
- def_delegators :@configuration_map, :empty?, :key?, :delete, :fetch,
19
- :[], :[]=, :each, :each_pair, :each_key, :each_value
20
-
21
15
  EMPTY_VALUE = :EMPTY_VALUE
22
16
 
23
17
  def initialize hsh = {}, keys = {}
24
18
  # holds configuration key value pairs
25
19
  # each configuration class can contain nested BaseConfigurations
26
- @configuration_map = {}
27
20
  traverse_config(hsh, keys)
28
21
  end
29
22
 
23
+ def to_hash
24
+ hsh = {}
25
+ instance_variables.each do |iv|
26
+ # strip the '@' to get the key
27
+ key = iv.to_s[1..]
28
+ hsh[key] = send(key.to_sym)
29
+ end
30
+ hsh
31
+ end
32
+
30
33
  def assign_value_to_path_array dot_path_array, value
31
34
  current_level = self
32
35
  dot_path_array[0...-1].each do |segment|
36
+ segment = segment.tr('-', '_')
33
37
  current_level = current_level.send(segment) if current_level.cs__respond_to?(segment)
34
38
  end
35
39
  last_entry = dot_path_array[-1]
@@ -39,10 +43,6 @@ module Contrast
39
43
  nil
40
44
  end
41
45
 
42
- def nil?
43
- @configuration_map.empty?
44
- end
45
-
46
46
  private
47
47
 
48
48
  # Traverse the given entity to build out the configuration graph.
@@ -51,51 +51,19 @@ module Contrast
51
51
  # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
52
52
  # leaf node.
53
53
  #
54
- # The spec_keys are the Contrast defined keys used to access a given
55
- # configuration. Each child of this class maintains its own set of keys,
56
- # as well as Objects to which those keys map.
57
- def traverse_config values, spec_keys
54
+ # The spec_key are the Contrast defined keys based on the instance variables of
55
+ # a given configuration.
56
+ def traverse_config values, spec_key
58
57
  internal_nodes = values.cs__respond_to?(:has_key?)
59
- spec_keys.each_pair do |spec_key, spec_value|
60
- user_provided_value = internal_nodes ? value_from_key_config(spec_key, values) : EMPTY_VALUE
61
- define_methods(spec_key, spec_value, user_provided_value)
62
- end
63
- end
64
-
65
- def define_methods spec_key, spec_value, user_provided_value
66
- str_key = spec_key.to_s
67
- assign_config_value(str_key, spec_value, user_provided_value)
68
- define_getter(str_key)
69
- define_setter(str_key)
70
- end
71
-
72
- def assign_config_value str_key, spec_value, user_provided_value
73
- @configuration_map[str_key] = if spec_value.is_a?(Class) && spec_value <= Contrast::Config::BaseConfiguration
74
- spec_value.new(user_provided_value)
75
- elsif user_provided_value == EMPTY_VALUE
76
- spec_value
77
- else
78
- user_provided_value
79
- end
58
+ val = internal_nodes ? value_from_key_config(spec_key, values) : nil
59
+ val == EMPTY_VALUE ? nil : val
80
60
  end
81
61
 
82
62
  def value_from_key_config key, config_hash
83
63
  return config_hash[key] if config_hash.key?(key)
84
- return config_hash.fetch(key.to_sym, EMPTY_VALUE) if key.is_a?(String)
85
-
86
- config_hash.fetch(key.to_s, EMPTY_VALUE)
87
- end
64
+ return config_hash.fetch(key.to_sym, nil) if key.is_a?(String)
88
65
 
89
- def define_getter str_key
90
- define_singleton_method str_key.to_sym do
91
- @configuration_map[str_key] == EMPTY_VALUE ? nil : @configuration_map[str_key]
92
- end
93
- end
94
-
95
- def define_setter str_key
96
- define_singleton_method "#{ str_key }=".to_sym do |new_value|
97
- @configuration_map[str_key] = new_value
98
- end
66
+ config_hash.fetch(key.to_s, nil)
99
67
  end
100
68
  end
101
69
  end
@@ -5,10 +5,24 @@ module Contrast
5
5
  module Config
6
6
  # Certificate Configuration
7
7
  class CertificationConfiguration < BaseConfiguration
8
- KEYS = { enable: false, ca_file: EMPTY_VALUE, cert_file: EMPTY_VALUE, key_file: EMPTY_VALUE }.cs__freeze
8
+ # @return [String] path to CA Cert file
9
+ attr_accessor :ca_file
10
+ # @return [String] path to Certification file
11
+ attr_accessor :cert_file
12
+ # @return [String] path to Certification Key file
13
+ attr_accessor :key_file
14
+ attr_writer :enable
9
15
 
10
- def initialize hsh
11
- super(hsh, KEYS)
16
+ def initialize hsh = {}
17
+ @enable = traverse_config(hsh, :enable)
18
+ @ca_file = traverse_config(hsh, :ca_file)
19
+ @cert_file = traverse_config(hsh, :cert_file)
20
+ @key_file = traverse_config(hsh, :key_file)
21
+ end
22
+
23
+ # @return [Boolean, false]
24
+ def enable
25
+ @enable.nil? ? false : @enable
12
26
  end
13
27
  end
14
28
  end
@@ -7,10 +7,21 @@ module Contrast
7
7
  # exception handling in Ruby, allowing for the override of Response Code
8
8
  # and Message when Security Exceptions are raised.
9
9
  class ExceptionConfiguration < BaseConfiguration
10
- KEYS = { capture: EMPTY_VALUE, override_status: EMPTY_VALUE, override_message: EMPTY_VALUE }.cs__freeze
10
+ # @return [Integer] the HTTP status code override
11
+ attr_accessor :override_status
12
+ # @return [String] the message text override
13
+ attr_accessor :override_message
14
+ attr_writer :capture
11
15
 
12
- def initialize hsh
13
- super(hsh, KEYS)
16
+ def initialize hsh = {}
17
+ @capture = traverse_config(hsh, :capture)
18
+ @override_status = traverse_config(hsh, :override_status)
19
+ @override_message = traverse_config(hsh, :override_message)
20
+ end
21
+
22
+ # @return [Boolean, false]
23
+ def capture
24
+ !!@capture
14
25
  end
15
26
  end
16
27
  end
@@ -6,23 +6,49 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # Heap Dump collection functionality of the Agent.
8
8
  class HeapDumpConfiguration < BaseConfiguration
9
- KEYS = {
10
- enable: # should dumps be taken
11
- Contrast::Utils::ObjectShare::FALSE,
12
- path: # dir to which dumps should be
13
- 'contrast_heap_dumps', # saved
14
- delay_ms: # time, in ms, after initialization
15
- 10_000, # to delay before taking dump
16
- window_ms: # ms between each dump
17
- 10_000, #
18
- count: # number of dumps to take
19
- 5, #
20
- clean: # remove temporary objects or not
21
- Contrast::Utils::ObjectShare::FALSE #
22
- }.cs__freeze
23
-
24
- def initialize hsh
25
- super(hsh, KEYS)
9
+ DEFAULT_PATH = 'contrast_heap_dumps' # saved
10
+ DEFAULT_MS = 10_000
11
+ DEFAULT_COUNT = 5
12
+
13
+ attr_writer :enable, :path, :delay_ms, :window_ms, :count, :clean
14
+
15
+ def initialize hsh = {}
16
+ @enable = traverse_config(hsh, :enable)
17
+ @path = traverse_config(hsh, :path)
18
+ @delay_ms = traverse_config(hsh, :delay_ms)
19
+ @window_ms = traverse_config(hsh, :window_ms)
20
+ @count = traverse_config(hsh, :count)
21
+ @clean = traverse_config(hsh, :clean)
22
+ end
23
+
24
+ # @return [Boolean, Contrast::Utils::ObjectShare::FALSE] should dumps be taken
25
+ def enable
26
+ @enable.nil? ? Contrast::Utils::ObjectShare::FALSE : @enable
27
+ end
28
+
29
+ # @return [String, DEFAULT_PATH] dir to which dumps should be
30
+ def path
31
+ @path ||= DEFAULT_PATH
32
+ end
33
+
34
+ # @return [Integer, DEFAULT_MS] time, in ms, after initialization
35
+ def delay_ms
36
+ @delay_ms ||= DEFAULT_MS
37
+ end
38
+
39
+ # @return [Integer, DEFAULT_MS] ms between each dump
40
+ def window_ms
41
+ @window_ms ||= DEFAULT_MS
42
+ end
43
+
44
+ # @return [Integer, DEFAULT_MS] number of dumps to take
45
+ def count
46
+ @count ||= DEFAULT_COUNT
47
+ end
48
+
49
+ # @return [Boolean, Contrast::Utils::ObjectShare::FALSE] remove temporary objects or not
50
+ def clean
51
+ @clean.nil? ? Contrast::Utils::ObjectShare::FALSE : @clean
26
52
  end
27
53
  end
28
54
  end
@@ -6,10 +6,24 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # inventory functionality of the Agent.
8
8
  class InventoryConfiguration < BaseConfiguration
9
- KEYS = { enable: true, analyze_libraries: true, tags: EMPTY_VALUE }.cs__freeze
9
+ # @return [Array, nil] tags
10
+ attr_accessor :tags
11
+ attr_writer :enable, :analyze_libraries
10
12
 
11
- def initialize hsh
12
- super(hsh, KEYS)
13
+ def initialize hsh = {}
14
+ @enable = traverse_config(hsh, :enable)
15
+ @analyze_libraries = traverse_config(hsh, :analyze_libraries)
16
+ @tags = traverse_config(hsh, :tags)
17
+ end
18
+
19
+ # @return [Boolean, true]
20
+ def enable
21
+ @enable.nil? ? true : @enable
22
+ end
23
+
24
+ # @return [Boolean, true]
25
+ def analyze_libraries
26
+ @analyze_libraries.nil? ? true : @analyze_libraries
13
27
  end
14
28
  end
15
29
  end
@@ -6,10 +6,17 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # logging in the Agent.
8
8
  class LoggerConfiguration < BaseConfiguration
9
- KEYS = { path: EMPTY_VALUE, level: EMPTY_VALUE, progname: EMPTY_VALUE }.cs__freeze
9
+ # @return [String, nil]
10
+ attr_accessor :path
11
+ # @return [String, nil]
12
+ attr_accessor :level
13
+ # @return [String, nil]
14
+ attr_accessor :progname
10
15
 
11
- def initialize hsh
12
- super(hsh, KEYS)
16
+ def initialize hsh = {}
17
+ @path = traverse_config(hsh, :path)
18
+ @level = traverse_config(hsh, :level)
19
+ @progname = traverse_config(hsh, :progname)
13
20
  end
14
21
  end
15
22
  end
@@ -6,14 +6,24 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # protect functionality of the Agent.
8
8
  class ProtectConfiguration < BaseConfiguration
9
- KEYS = {
10
- exceptions: Contrast::Config::ExceptionConfiguration,
11
- rules: Contrast::Config::ProtectRulesConfiguration,
12
- enable: EMPTY_VALUE
13
- }.cs__freeze
9
+ # @return [Boolean, nil]
10
+ attr_accessor :enable
11
+ attr_writer :exceptions, :rules
14
12
 
15
- def initialize hsh
16
- super(hsh, KEYS)
13
+ def initialize hsh = {}
14
+ @exceptions = Contrast::Config::ExceptionConfiguration.new(traverse_config(hsh, :exceptions))
15
+ @rules = Contrast::Config::ProtectRulesConfiguration.new(traverse_config(hsh, :rules))
16
+ @enable = traverse_config(hsh, :enable)
17
+ end
18
+
19
+ # @return [Contrast::Config::ExceptionConfiguration]
20
+ def exceptions
21
+ @exceptions ||= Contrast::Config::ExceptionConfiguration.new
22
+ end
23
+
24
+ # @return [Contrast::Config::ProtectRulesConfiguration]
25
+ def rules
26
+ @rules ||= Contrast::Config::ProtectRulesConfiguration.new
17
27
  end
18
28
  end
19
29
  end
@@ -8,15 +8,24 @@ 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
- KEYS = {
12
- enable: EMPTY_VALUE,
13
- mode: EMPTY_VALUE,
14
- disable_system_commands: EMPTY_VALUE,
15
- detect_custom_code_accessing_system_files: true
16
- }.cs__freeze
11
+ # @return [Boolean, nil]
12
+ attr_accessor :enable
13
+ # @return [String, nil]
14
+ attr_accessor :mode
15
+ # @retrun [Boolean, nil]
16
+ attr_accessor :disable_system_commands
17
+ attr_writer :detect_custom_code_accessing_system_files
17
18
 
18
- def initialize hsh
19
- super(hsh, KEYS)
19
+ def initialize hsh = {}
20
+ @enable = traverse_config(hsh, :enable)
21
+ @mode = traverse_config(hsh, :mode)
22
+ @disable_system_commands = traverse_config(hsh, :disable_system_commands)
23
+ @detect_custom_code_accessing_system_files = traverse_config(hsh, :detect_custom_code_accessing_system_files)
24
+ end
25
+
26
+ # @return [Boolean, true]
27
+ def detect_custom_code_accessing_system_files
28
+ @detect_custom_code_accessing_system_files.nil? ? true : @detect_custom_code_accessing_system_files
20
29
  end
21
30
 
22
31
  # To convert the user input mode from config to a standard format used by TS & SR, we need to convert the given
@@ -1,28 +1,126 @@
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/config/protect_rule_configuration'
5
+
4
6
  module Contrast
5
7
  module Config
6
8
  # Common Configuration settings. Those in this section pertain to the
7
9
  # protect rule modes of the Agent.
8
10
  class ProtectRulesConfiguration < BaseConfiguration
9
- KEYS = {
10
- disabled_rules: EMPTY_VALUE,
11
- 'bot-blocker' => Contrast::Config::ProtectRuleConfiguration,
12
- 'cmd-injection' => Contrast::Config::ProtectRuleConfiguration,
13
- 'sql-injection' => Contrast::Config::ProtectRuleConfiguration,
14
- 'nosql-injection' => Contrast::Config::ProtectRuleConfiguration,
15
- 'untrusted-deserialization' => Contrast::Config::ProtectRuleConfiguration,
16
- 'method-tampering' => Contrast::Config::ProtectRuleConfiguration,
17
- xxe: Contrast::Config::ProtectRuleConfiguration,
18
- 'path-traversal' => Contrast::Config::ProtectRuleConfiguration,
19
- 'reflected-xss' => Contrast::Config::ProtectRuleConfiguration,
20
- 'unsafe-file-upload' => Contrast::Config::ProtectRuleConfiguration,
21
- 'Contrast::Agent::Protect::Rule::Base' => Contrast::Config::ProtectRuleConfiguration
22
- }.cs__freeze
23
-
24
- def initialize hsh
25
- super(hsh, KEYS)
11
+ attr_accessor :disabled_rules
12
+ attr_writer :bot_blocker, :cmd_injection, :sql_injection, :nosql_injection, :untrusted_deserialization,
13
+ :method_tampering, :xxe, :path_traversal, :reflected_xss, :unsafe_file_upload, :rule_base
14
+
15
+ BASE_RULE = 'Contrast::Agent::Protect::Rule::Base'.cs__freeze
16
+
17
+ def initialize hsh = {}
18
+ @disabled_rules = traverse_config(hsh, :disabled_rules)
19
+ @bot_blocker = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'bot-blocker'))
20
+ @cmd_injection = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'cmd-injection'))
21
+ @sql_injection = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'sql-injection'))
22
+ @nosql_injection = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'nosql-injection'))
23
+ @untrusted_deserialization = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(
24
+ hsh,
25
+ 'untrusted-deserialization'))
26
+ @method_tampering = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'method-tampering'))
27
+ @xxe = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, :xxe))
28
+ @path_traversal = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'path-traversal'))
29
+ @reflected_xss = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'reflected-xss'))
30
+ @unsafe_file_upload = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, 'unsafe-file-upload'))
31
+ @rule_base = Contrast::Config::ProtectRuleConfiguration.new(traverse_config(hsh, BASE_RULE))
32
+ end
33
+
34
+ def bot_blocker
35
+ @bot_blocker ||= Contrast::Config::ProtectRuleConfiguration.new
36
+ end
37
+
38
+ def cmd_injection
39
+ @cmd_injection ||= Contrast::Config::ProtectRuleConfiguration.new
40
+ end
41
+
42
+ def sql_injection
43
+ @sql_injection ||= Contrast::Config::ProtectRuleConfiguration.new
44
+ end
45
+
46
+ def nosql_injection
47
+ @nosql_injection ||= Contrast::Config::ProtectRuleConfiguration.new
48
+ end
49
+
50
+ def untrusted_deserialization
51
+ @untrusted_deserialization ||= Contrast::Config::ProtectRuleConfiguration.new
52
+ end
53
+
54
+ def method_tampering
55
+ @method_tampering ||= Contrast::Config::ProtectRuleConfiguration.new
56
+ end
57
+
58
+ def xxe
59
+ @xxe ||= Contrast::Config::ProtectRuleConfiguration.new
60
+ end
61
+
62
+ def path_traversal
63
+ @path_traversal ||= Contrast::Config::ProtectRuleConfiguration.new
64
+ end
65
+
66
+ def reflected_xss
67
+ @reflected_xss ||= Contrast::Config::ProtectRuleConfiguration.new
68
+ end
69
+
70
+ def unsafe_file_upload
71
+ @unsafe_file_upload ||= Contrast::Config::ProtectRuleConfiguration.new
72
+ end
73
+
74
+ def rule_base
75
+ @rule_base ||= Contrast::Config::ProtectRuleConfiguration.new
76
+ end
77
+
78
+ def []= key, value
79
+ instance_variable_set("@#{ convert_key(key) }".to_sym, value)
80
+ end
81
+
82
+ def [] key
83
+ send(convert_key(key).to_sym)
84
+ end
85
+
86
+ def convert_key key
87
+ return_proper_class(key).to_s.tr('-', '_')
88
+ end
89
+
90
+ # Convert instance variable names to format expected by TS
91
+ # for adding to the hash
92
+ def to_hash
93
+ hsh = {}
94
+ instance_variables.each do |iv|
95
+ # strip the '@' to get the key
96
+ key = return_proper_class(iv.to_s.delete('@'))
97
+ hsh[key.tr('_', '-')] = send(key.to_sym)
98
+ end
99
+ hsh
100
+ end
101
+
102
+ # This method is to handle the specific case of
103
+ # Contrast::Agent::Protect::Rule::Base from protect/base.rb#initialize
104
+ #
105
+ # @param str_key [String] the key we want to check form the config
106
+ # @return String
107
+ def return_proper_class str_key
108
+ return BASE_RULE if str_key == 'rule_base'
109
+ return 'rule_base' if str_key == BASE_RULE
110
+
111
+ str_key
112
+ end
113
+
114
+ # if method 'Contrast::Agent::Protect::Rule::Base' is being called from convert_to_hash
115
+ # handle missing method and call original getter
116
+ def method_missing name, *_args
117
+ return unless name.to_s.include?('Base') || name.to_s.start_with?('Contrast')
118
+
119
+ @rule_base
120
+ end
121
+
122
+ def respond_to_missing? method_name, include_private = false
123
+ (method_name.to_s.include?('Base') || method_name.to_s.start_with?('Contrast')) || super
26
124
  end
27
125
  end
28
126
  end
@@ -8,10 +8,33 @@ module Contrast
8
8
  class RequestAuditConfiguration < BaseConfiguration
9
9
  DEFAULT_PATH = './messages'
10
10
 
11
- KEYS = { enable: false, requests: false, responses: false, path: DEFAULT_PATH }.cs__freeze
11
+ attr_writer :enable, :requests, :responses, :path
12
12
 
13
- def initialize hsh
14
- super(hsh, KEYS)
13
+ def initialize hsh = {}
14
+ @enable = traverse_config(hsh, :enable)
15
+ @requests = traverse_config(hsh, :requests)
16
+ @responses = traverse_config(hsh, :responses)
17
+ @path = traverse_config(hsh, :path)
18
+ end
19
+
20
+ # @return [Boolean, false]
21
+ def enable
22
+ @enable.nil? ? false : @enable
23
+ end
24
+
25
+ # @return [Boolean, false]
26
+ def requests
27
+ @requests.nil? ? false : @requests
28
+ end
29
+
30
+ # @return [Boolean, false]
31
+ def responses
32
+ @responses.nil? ? false : @responses
33
+ end
34
+
35
+ # @return [String, ::DEFAULT_PATH]
36
+ def path
37
+ @path.nil? ? DEFAULT_PATH : @path
15
38
  end
16
39
  end
17
40
  end
@@ -5,22 +5,62 @@ module Contrast
5
5
  module Config
6
6
  # The base of the Common Configuration settings.
7
7
  class RootConfiguration < BaseConfiguration
8
- KEYS = {
9
- api: Contrast::Config::ApiConfiguration,
10
- enable: BaseConfiguration::EMPTY_VALUE,
11
- agent: Contrast::Config::AgentConfiguration,
12
- application: Contrast::Config::ApplicationConfiguration,
13
- server: Contrast::Config::ServerConfiguration,
14
- assess: Contrast::Config::AssessConfiguration,
15
- inventory: Contrast::Config::InventoryConfiguration,
16
- protect: Contrast::Config::ProtectConfiguration,
17
- service: Contrast::Config::ServiceConfiguration
18
- }.cs__freeze
8
+ attr_writer :api, :agent, :application, :server, :assess, :inventory, :protect, :service
9
+ # @return [Boolean, nil]
10
+ attr_accessor :enable
19
11
 
20
12
  def initialize hsh = {}
21
13
  raise ArgumentError, 'Expected a hash' unless hsh.is_a?(Hash)
22
14
 
23
- super(hsh, KEYS)
15
+ @api = Contrast::Config::ApiConfiguration.new(traverse_config(hsh, :api))
16
+ @enable = traverse_config(hsh, :enable)
17
+ @agent = Contrast::Config::AgentConfiguration.new(traverse_config(hsh, :agent))
18
+ @application = Contrast::Config::ApplicationConfiguration.new(traverse_config(hsh, :application))
19
+ @server = Contrast::Config::ServerConfiguration.new(traverse_config(hsh, :server))
20
+ @assess = Contrast::Config::AssessConfiguration.new(traverse_config(hsh, :assess))
21
+ @inventory = Contrast::Config::InventoryConfiguration.new(traverse_config(hsh, :inventory))
22
+ @protect = Contrast::Config::ProtectConfiguration.new(traverse_config(hsh, :protect))
23
+ @service = Contrast::Config::ServiceConfiguration.new(traverse_config(hsh, :service))
24
+ end
25
+
26
+ # @return [Contrast::Config::ApiConfiguration]
27
+ def api
28
+ @api ||= Contrast::Config::ApiConfiguration.new
29
+ end
30
+
31
+ # @return [Contrast::Config::AgentConfiguration]
32
+ def agent
33
+ @agent ||= Contrast::Config::AgentConfiguration.new
34
+ end
35
+
36
+ # @return [Contrast::Config::ApplicationConfiguration]
37
+ def application
38
+ @application ||= Contrast::Config::ApplicationConfiguration.new
39
+ end
40
+
41
+ # @return [Contrast::Config::ServerConfiguration]
42
+ def server
43
+ @server ||= Contrast::Config::ServerConfiguration.new
44
+ end
45
+
46
+ # @return [Contrast::Config::AssessConfiguration]
47
+ def assess
48
+ @assess ||= Contrast::Config::AssessConfiguration.new
49
+ end
50
+
51
+ # @return [Contrast::Config::InventoryConfiguration]
52
+ def inventory
53
+ @inventory ||= Contrast::Config::InventoryConfiguration.new
54
+ end
55
+
56
+ # @return [Contrast::Config::ProtectConfiguration]
57
+ def protect
58
+ @protect ||= Contrast::Config::ProtectConfiguration.new
59
+ end
60
+
61
+ # @return [Contrast::Config::ServiceConfiguration]
62
+ def service
63
+ @service ||= Contrast::Config::ServiceConfiguration.new
24
64
  end
25
65
  end
26
66
  end