contrast-agent 6.3.0 → 6.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -3
  3. data/.simplecov +1 -0
  4. data/Rakefile +0 -27
  5. data/ext/cs__contrast_patch/cs__contrast_patch.c +14 -1
  6. data/lib/contrast/agent/assess/finalizers/hash.rb +1 -0
  7. data/lib/contrast/agent/assess/policy/propagation_method.rb +5 -3
  8. data/lib/contrast/agent/assess/policy/propagator/custom.rb +4 -0
  9. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +5 -0
  10. data/lib/contrast/agent/assess/policy/propagator/split.rb +3 -0
  11. data/lib/contrast/agent/assess/policy/source_method.rb +5 -0
  12. data/lib/contrast/agent/assess/policy/trigger_method.rb +9 -3
  13. data/lib/contrast/agent/assess/tracker.rb +12 -0
  14. data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -2
  15. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +1 -1
  16. data/lib/contrast/agent/inventory/policy/datastores.rb +1 -1
  17. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  18. data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
  19. data/lib/contrast/agent/protect/rule/base.rb +1 -1
  20. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +1 -3
  21. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +17 -21
  22. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +1 -1
  23. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +26 -3
  24. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +5 -5
  25. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -1
  26. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +1 -1
  27. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +1 -1
  28. data/lib/contrast/agent/request_context.rb +8 -0
  29. data/lib/contrast/agent/service_heartbeat.rb +2 -3
  30. data/lib/contrast/agent/static_analysis.rb +1 -1
  31. data/lib/contrast/agent/version.rb +1 -1
  32. data/lib/contrast/agent/worker_thread.rb +10 -0
  33. data/lib/contrast/api/communication/response_processor.rb +1 -1
  34. data/lib/contrast/api/dtm.pb.rb +1 -1
  35. data/lib/contrast/api/settings.pb.rb +1 -1
  36. data/lib/contrast/components/agent.rb +52 -14
  37. data/lib/contrast/components/api.rb +60 -23
  38. data/lib/contrast/components/assess.rb +16 -0
  39. data/lib/contrast/components/contrast_service.rb +1 -1
  40. data/lib/contrast/components/heap_dump.rb +51 -1
  41. data/lib/contrast/components/inventory.rb +19 -13
  42. data/lib/contrast/components/logger.rb +18 -0
  43. data/lib/contrast/components/protect.rb +41 -1
  44. data/lib/contrast/components/sampling.rb +29 -0
  45. data/lib/contrast/config/assess_configuration.rb +33 -3
  46. data/lib/contrast/config/base_configuration.rb +8 -2
  47. data/lib/contrast/config/root_configuration.rb +19 -16
  48. data/lib/contrast/config/service_configuration.rb +4 -4
  49. data/lib/contrast/config.rb +0 -9
  50. data/lib/contrast/extension/object.rb +19 -0
  51. data/lib/contrast/framework/rails/support.rb +4 -1
  52. data/lib/contrast/logger/log.rb +2 -1
  53. data/lib/contrast/utils/assess/event_limit_utils.rb +96 -0
  54. data/lib/contrast/utils/assess/propagation_method_utils.rb +27 -7
  55. data/lib/contrast/utils/log_utils.rb +2 -2
  56. data/lib/contrast/utils/net_http_base.rb +2 -2
  57. data/lib/contrast/utils/patching/policy/patch_utils.rb +6 -23
  58. data/lib/contrast.rb +39 -20
  59. data/lib/protobuf/code_generator.rb +129 -0
  60. data/lib/protobuf/decoder.rb +28 -0
  61. data/lib/protobuf/deprecation.rb +117 -0
  62. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +79 -0
  63. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +360 -0
  64. data/lib/protobuf/descriptors.rb +3 -0
  65. data/lib/protobuf/encoder.rb +11 -0
  66. data/lib/protobuf/enum.rb +365 -0
  67. data/lib/protobuf/exceptions.rb +9 -0
  68. data/lib/protobuf/field/base_field.rb +380 -0
  69. data/lib/protobuf/field/base_field_object_definitions.rb +504 -0
  70. data/lib/protobuf/field/bool_field.rb +64 -0
  71. data/lib/protobuf/field/bytes_field.rb +67 -0
  72. data/lib/protobuf/field/double_field.rb +25 -0
  73. data/lib/protobuf/field/enum_field.rb +56 -0
  74. data/lib/protobuf/field/field_array.rb +102 -0
  75. data/lib/protobuf/field/field_hash.rb +122 -0
  76. data/lib/protobuf/field/fixed32_field.rb +25 -0
  77. data/lib/protobuf/field/fixed64_field.rb +28 -0
  78. data/lib/protobuf/field/float_field.rb +43 -0
  79. data/lib/protobuf/field/int32_field.rb +21 -0
  80. data/lib/protobuf/field/int64_field.rb +34 -0
  81. data/lib/protobuf/field/integer_field.rb +23 -0
  82. data/lib/protobuf/field/message_field.rb +51 -0
  83. data/lib/protobuf/field/sfixed32_field.rb +27 -0
  84. data/lib/protobuf/field/sfixed64_field.rb +28 -0
  85. data/lib/protobuf/field/signed_integer_field.rb +29 -0
  86. data/lib/protobuf/field/sint32_field.rb +21 -0
  87. data/lib/protobuf/field/sint64_field.rb +21 -0
  88. data/lib/protobuf/field/string_field.rb +51 -0
  89. data/lib/protobuf/field/uint32_field.rb +21 -0
  90. data/lib/protobuf/field/uint64_field.rb +21 -0
  91. data/lib/protobuf/field/varint_field.rb +77 -0
  92. data/lib/protobuf/field.rb +74 -0
  93. data/lib/protobuf/generators/base.rb +85 -0
  94. data/lib/protobuf/generators/enum_generator.rb +39 -0
  95. data/lib/protobuf/generators/extension_generator.rb +27 -0
  96. data/lib/protobuf/generators/field_generator.rb +193 -0
  97. data/lib/protobuf/generators/file_generator.rb +262 -0
  98. data/lib/protobuf/generators/group_generator.rb +122 -0
  99. data/lib/protobuf/generators/message_generator.rb +104 -0
  100. data/lib/protobuf/generators/option_generator.rb +17 -0
  101. data/lib/protobuf/generators/printable.rb +160 -0
  102. data/lib/protobuf/generators/service_generator.rb +50 -0
  103. data/lib/protobuf/lifecycle.rb +33 -0
  104. data/lib/protobuf/logging.rb +39 -0
  105. data/lib/protobuf/message/fields.rb +233 -0
  106. data/lib/protobuf/message/serialization.rb +85 -0
  107. data/lib/protobuf/message.rb +241 -0
  108. data/lib/protobuf/optionable.rb +72 -0
  109. data/lib/protobuf/tasks/compile.rake +80 -0
  110. data/lib/protobuf/tasks.rb +1 -0
  111. data/lib/protobuf/varint.rb +20 -0
  112. data/lib/protobuf/varint_pure.rb +31 -0
  113. data/lib/protobuf/version.rb +3 -0
  114. data/lib/protobuf/wire_type.rb +10 -0
  115. data/lib/protobuf.rb +91 -0
  116. data/proto/dynamic_discovery.proto +46 -0
  117. data/proto/google/protobuf/compiler/plugin.proto +183 -0
  118. data/proto/google/protobuf/descriptor.proto +911 -0
  119. data/proto/rpc.proto +71 -0
  120. data/resources/assess/policy.json +15 -12
  121. data/resources/deadzone/policy.json +132 -19
  122. data/ruby-agent.gemspec +3 -1
  123. metadata +112 -28
  124. data/lib/contrast/config/agent_configuration.rb +0 -63
  125. data/lib/contrast/config/api_configuration.rb +0 -56
  126. data/lib/contrast/config/heap_dump_configuration.rb +0 -59
  127. data/lib/contrast/config/inventory_configuration.rb +0 -33
  128. data/lib/contrast/config/logger_configuration.rb +0 -26
  129. data/lib/contrast/config/protect_configuration.rb +0 -33
  130. data/lib/contrast/config/sampling_configuration.rb +0 -35
@@ -43,6 +43,8 @@ module Contrast
43
43
  # @return [Contrast::Utils::Timer] when the context was created
44
44
  attr_reader :timer
45
45
 
46
+ attr_accessor :propagation_event_count, :source_event_count
47
+
46
48
  def initialize rack_request, app_loaded: true
47
49
  with_contrast_scope do
48
50
  # all requests get a timer and hash
@@ -68,6 +70,12 @@ module Contrast
68
70
  # generic holder for properties that can be set throughout this request
69
71
  @_properties = {}
70
72
 
73
+ # count of propagation events
74
+ @propagation_event_count = 0
75
+
76
+ # count of source events
77
+ @source_event_count = 0
78
+
71
79
  if ::Contrast::ASSESS.enabled?
72
80
  @sample_req, @sample_res = Contrast::Utils::Assess::SamplingUtil.instance.sample?(@request)
73
81
  end
@@ -1,7 +1,6 @@
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/logger'
5
4
  require 'contrast/agent/worker_thread'
6
5
  require 'contrast/agent/reporting/report'
7
6
 
@@ -10,8 +9,6 @@ module Contrast
10
9
  # The ServiceHeartbeat functions to keep the Contrast Service alive and ensure that it maintains this Agent's
11
10
  # ApplicationContext.
12
11
  class ServiceHeartbeat < WorkerThread
13
- include Contrast::Components::Logger::InstanceMethods
14
-
15
12
  # Spec recommends 30 seconds, we're going with 15.
16
13
  REFRESH_INTERVAL_SEC = 15
17
14
 
@@ -22,7 +19,9 @@ module Contrast
22
19
  @_thread = Contrast::Agent::Thread.new do
23
20
  logger.info('Starting heartbeat thread.')
24
21
  loop do
22
+ logger.info("Queue Size: #{ Contrast::Agent.messaging_queue.queue&.length }")
25
23
  Contrast::Agent.messaging_queue&.send_event_eventually(poll_message)
24
+ clean_properties
26
25
  sleep(REFRESH_INTERVAL_SEC)
27
26
  end
28
27
  end
@@ -24,7 +24,7 @@ module Contrast
24
24
  end
25
25
 
26
26
  def send_inventory_message
27
- return unless ::Contrast::INVENTORY.enabled?
27
+ return unless ::Contrast::INVENTORY.enable
28
28
 
29
29
  report = Contrast::Agent::Reporting::ApplicationUpdate.new
30
30
  # This convert here is left as it'll be easier to be replaced when the Library is being changed
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Contrast
5
5
  module Agent
6
- VERSION = '6.3.0'
6
+ VERSION = '6.5.1'
7
7
  end
8
8
  end
@@ -1,10 +1,14 @@
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/logger'
5
+
4
6
  module Contrast
5
7
  module Agent
6
8
  # Base class for threads that do async processing
7
9
  class WorkerThread
10
+ include Contrast::Components::Logger::InstanceMethods
11
+
8
12
  def initialize
9
13
  @_thread = nil
10
14
  end
@@ -27,6 +31,12 @@ module Contrast
27
31
  def attempt_to_start?
28
32
  true
29
33
  end
34
+
35
+ def clean_properties
36
+ logger.debug("Cleaning PROPERTIES_HASH size: #{ Contrast::Agent::Assess::Tracker::PROPERTIES_HASH.size }")
37
+ Contrast::Agent::Assess::Tracker.cleanup!
38
+ logger.debug("Cleaned PROPERTIES_HASH size: #{ Contrast::Agent::Assess::Tracker::PROPERTIES_HASH.size }")
39
+ end
30
40
  end
31
41
  end
32
42
  end
@@ -80,7 +80,7 @@ module Contrast
80
80
 
81
81
  logger.info('Current rule settings:')
82
82
 
83
- ::Contrast::PROTECT.rules.each { |k, v| logger.info('Protect Rule mode set', rule: k, mode: v.mode) }
83
+ ::Contrast::PROTECT.defend_rules.each { |k, v| logger.info('Protect Rule mode set', rule: k, mode: v.mode) }
84
84
  logger.info('Disabled Assess Rules', rules: ::Contrast::ASSESS.disabled_rules)
85
85
  end
86
86
  end
@@ -8,7 +8,7 @@ require 'protobuf'
8
8
  module Contrast
9
9
  module Api
10
10
  module Dtm
11
- ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
11
+ ::Protobuf::Optionable.inject(self) { ::CSGoogle::Protobuf::FileOptions }
12
12
 
13
13
  ##
14
14
  # Message Classes
@@ -8,7 +8,7 @@ require 'protobuf'
8
8
  module Contrast
9
9
  module Api
10
10
  module Settings
11
- ::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
11
+ ::Protobuf::Optionable.inject(self) { ::CSGoogle::Protobuf::FileOptions }
12
12
 
13
13
  ##
14
14
  # Enum Classes
@@ -3,6 +3,8 @@
3
3
 
4
4
  require 'rubygems/version'
5
5
  require 'contrast/agent/rule_set'
6
+ require 'contrast/components/logger'
7
+ require 'contrast/components/heap_dump'
6
8
 
7
9
  module Contrast
8
10
  module Components
@@ -13,9 +15,50 @@ module Contrast
13
15
  class Interface
14
16
  include Contrast::Components::ComponentBase
15
17
 
18
+ def initialize hsh = {}
19
+ return unless hsh
20
+
21
+ @_enable = hsh[:enable]
22
+ @_start_bundled_service = hsh[:start_bundled_service]
23
+ @_omit_body = hsh[:omit_body]
24
+ @_service = Contrast::Config::ServiceConfiguration.new(hsh[:service])
25
+ @_logger = Contrast::Components::Logger::Interface.new(hsh[:logger])
26
+ @_ruby = Contrast::Config::RubyConfiguration.new(hsh[:ruby])
27
+ @_heap_dump = Contrast::Components::HeapDump::Interface.new(hsh[:heap_dump])
28
+ end
29
+
30
+ # @return [Boolean, true]
31
+ def start_bundled_service?
32
+ @_start_bundled_service.nil? ? true : @_start_bundled_service
33
+ end
34
+
35
+ def service
36
+ return @_service unless @_service.nil?
37
+
38
+ @_service = Contrast::Config::ServiceConfiguration.new
39
+ end
40
+
41
+ def logger
42
+ return @_logger unless @_logger.nil?
43
+
44
+ @_logger = Contrast::Components::Logger::Interface.new
45
+ end
46
+
47
+ def ruby
48
+ return @_ruby unless @_ruby.nil?
49
+
50
+ @_ruby = Contrast::Config::RubyConfiguration.new
51
+ end
52
+
53
+ def heap_dump
54
+ return @_heap_dump unless @_heap_dump.nil?
55
+
56
+ @_heap_dump = Contrast::Components::HeapDump::Interface.new
57
+ end
58
+
16
59
  def enabled?
17
- @_enabled = !false?(::Contrast::CONFIG.root.enable) if @_enabled.nil?
18
- @_enabled
60
+ @_enable = !false?(::Contrast::CONFIG.root.enable) if @_enable.nil?
61
+ @_enable
19
62
  end
20
63
 
21
64
  def disabled?
@@ -23,11 +66,11 @@ module Contrast
23
66
  end
24
67
 
25
68
  def enable!
26
- @_enabled = true
69
+ @_enable = true
27
70
  end
28
71
 
29
72
  def disable!
30
- @_enabled = false
73
+ @_enable = false
31
74
  Contrast::Agent::TracePointHook.disable
32
75
  Contrast::Agent.thread_watcher&.shutdown!
33
76
  end
@@ -41,8 +84,7 @@ module Contrast
41
84
  end
42
85
 
43
86
  def patch_yield?
44
- @_patch_yield = !false?(::Contrast::CONFIG.root.agent.ruby.propagate_yield) if @_patch_yield.nil?
45
- @_patch_yield
87
+ !false?(ruby.propagate_yield)
46
88
  end
47
89
 
48
90
  def interpolation_enabled?
@@ -52,18 +94,14 @@ module Contrast
52
94
  end
53
95
 
54
96
  def omit_body?
55
- @_omit_body = true?(::Contrast::CONFIG.root.agent.omit_body) if @_omit_body.nil?
56
97
  @_omit_body
57
98
  end
58
99
 
59
100
  def exception_control
60
101
  @_exception_control ||= {
61
- enable: true?(::Contrast::CONFIG.root.agent.ruby.exceptions.capture),
62
- status:
63
- ::Contrast::CONFIG.root.agent.ruby.exceptions.override_status || 403,
64
- message:
65
- ::Contrast::CONFIG.root.agent.ruby.exceptions.override_message ||
66
- Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
102
+ enable: true?(ruby.exceptions.capture),
103
+ status: ruby.exceptions.override_status || 403,
104
+ message: ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
67
105
  }
68
106
  end
69
107
 
@@ -87,7 +125,7 @@ module Contrast
87
125
  def retrieve_protect_ruleset
88
126
  return {} unless enabled? && ::Contrast::PROTECT.enabled?
89
127
 
90
- ::Contrast::PROTECT.rules
128
+ ::Contrast::PROTECT.defend_rules
91
129
  end
92
130
  end
93
131
  end
@@ -3,6 +3,9 @@
3
3
 
4
4
  require 'contrast/components/base'
5
5
  require 'contrast/components/config'
6
+ require 'contrast/config/api_proxy_configuration'
7
+ require 'contrast/config/request_audit_configuration'
8
+ require 'contrast/config/certification_configuration'
6
9
 
7
10
  module Contrast
8
11
  module Components
@@ -12,50 +15,86 @@ module Contrast
12
15
  # parent_configuration_spec.yaml.
13
16
  class Interface
14
17
  include Contrast::Components::ComponentBase
18
+ include Contrast::Config::BaseConfiguration
19
+
20
+ # @return [String]
21
+ attr_accessor :api_key
22
+ # @return [String]
23
+ attr_accessor :user_name
24
+ # @return [String]
25
+ attr_accessor :service_key
26
+ attr_writer :url
27
+
28
+ DEFAULT_URL = 'https://app.contrastsecurity.com/Contrast'
29
+
30
+ def initialize hsh = {}
31
+ return unless hsh
32
+
33
+ @api_key = hsh[:api_key]
34
+ @url = hsh[:url]
35
+ @user_name = hsh[:user_name]
36
+ @service_key = hsh[:service_key]
37
+ @_proxy = Contrast::Config::ApiProxyConfiguration.new(hsh[:proxy])
38
+ @_request_audit = Contrast::Config::RequestAuditConfiguration.new(hsh[:request_audit])
39
+ @_certificate = Contrast::Config::CertificationConfiguration.new(hsh[:certificate])
40
+ end
15
41
 
16
- def api_url
17
- @_api_url ||= begin
18
- tmp = ::Contrast::CONFIG.root.api.url
19
- tmp += '/Contrast' unless tmp.end_with?('/Contrast')
20
- tmp
21
- end
42
+ def url
43
+ @url.nil? ? DEFAULT_URL : @url
22
44
  end
23
45
 
24
- def api_key
25
- @_api_key ||= ::Contrast::CONFIG.root.api.api_key
46
+ # @return [Contrast::Config::ApiProxyConfiguration]
47
+ def proxy
48
+ return @_proxy unless @_proxy.nil?
49
+
50
+ @_proxy = Contrast::Config::ApiProxyConfiguration.new
26
51
  end
27
52
 
28
- def service_key
29
- @_service_key ||= ::Contrast::CONFIG.root.api.service_key
53
+ # @return [Contrast::Config::RequestAuditConfiguration]
54
+ def request_audit
55
+ return @_request_audit unless @_request_audit.nil?
56
+
57
+ @_request_audit = Contrast::Config::RequestAuditConfiguration.new
30
58
  end
31
59
 
32
- def username
33
- @_username ||= ::Contrast::CONFIG.root.api.user_name
60
+ # @return [Contrast::Config::CertificationConfiguration]
61
+ def certificate
62
+ return @_certificate unless @_certificate.nil?
63
+
64
+ @_certificate = Contrast::Config::CertificationConfiguration.new
34
65
  end
35
66
 
36
- def proxy_enabled?
37
- return @_proxy_enabled unless @_proxy_enabled.nil?
67
+ def api_url
68
+ @_api_url ||= begin
69
+ tmp = Contrast::CONFIG.root.api.url
70
+ tmp += '/Contrast' unless tmp.end_with?('/Contrast')
71
+ tmp
72
+ end
73
+ end
38
74
 
39
- @_proxy_enabled = true?(::Contrast::CONFIG.root.api.proxy.enable)
75
+ def proxy_enable
76
+ return @_proxy_enable unless @_proxy_enable.nil?
77
+
78
+ @_proxy_enable = true?(::Contrast::CONFIG.root.api.proxy.enable)
40
79
  end
41
80
 
42
81
  def proxy_url
43
- @_proxy_url ||= ::Contrast::CONFIG.root.api.proxy.url
82
+ proxy.url
44
83
  end
45
84
 
46
- def request_audit_enable?
85
+ def request_audit_enable
47
86
  return @_request_audit_enable unless @_request_audit_enable.nil?
48
87
 
49
88
  @_request_audit_enable = true?(::Contrast::CONFIG.root.api.request_audit.enable)
50
89
  end
51
90
 
52
- def request_audit_requests?
91
+ def request_audit_requests
53
92
  return @_request_audit_requests unless @_request_audit_requests.nil?
54
93
 
55
94
  @_request_audit_requests = true?(::Contrast::CONFIG.root.api.request_audit.requests)
56
95
  end
57
96
 
58
- def request_audit_responses?
97
+ def request_audit_responses
59
98
  return @_request_audit_responses unless @_request_audit_responses.nil?
60
99
 
61
100
  @_request_audit_responses = true?(::Contrast::CONFIG.root.api.request_audit.responses)
@@ -65,10 +104,8 @@ module Contrast
65
104
  @_request_audit_path ||= ::Contrast::CONFIG.root.api.request_audit.path.to_s
66
105
  end
67
106
 
68
- def certification_enabled?
69
- return @_certification_enabled unless @_certification_enabled.nil?
70
-
71
- @_certification_enabled = certification_truly_enabled?(::Contrast::CONFIG.root.api.certificate)
107
+ def certification_enable
108
+ @_certification_enable ||= certification_truly_enabled?(::Contrast::CONFIG.root.api.certificate)
72
109
  end
73
110
 
74
111
  def certification_ca_file
@@ -118,6 +118,22 @@ module Contrast
118
118
  ::Contrast::SETTINGS.assess_state.session_id
119
119
  end
120
120
 
121
+ def max_source_events
122
+ ::Contrast::CONFIG.root.assess.max_context_source_events
123
+ end
124
+
125
+ def max_propagation_events
126
+ ::Contrast::CONFIG.root.assess.max_propagation_events
127
+ end
128
+
129
+ def time_limit_threshold
130
+ ::Contrast::CONFIG.root.assess.time_limit_threshold
131
+ end
132
+
133
+ def max_rule_reported
134
+ ::Contrast::CONFIG.root.assess.max_rule_reported
135
+ end
136
+
121
137
  private
122
138
 
123
139
  def forcibly_enabled?
@@ -29,7 +29,7 @@ module Contrast
29
29
 
30
30
  # Requirement says "must be true" but that
31
31
  # should be "must not be false" -- oops.
32
- @_use_bundled_service ||= !false?(::Contrast::CONFIG.root.agent.start_bundled_service) &&
32
+ @_use_bundled_service ||= !false?(::Contrast::CONFIG.root.agent.start_bundled_service?) &&
33
33
  # Either a valid host or a valid socket
34
34
  # Path validity is the service's problem
35
35
  (LOCALHOST.match?(host) || !!socket_path)
@@ -2,11 +2,61 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/base'
5
- require 'contrast/components/heap_dump'
5
+ require 'contrast/config/base_configuration'
6
6
 
7
7
  module Contrast
8
8
  module Components
9
9
  module HeapDump
10
+ # Interface used to build the HeapDump settings and component.
11
+ class Interface
12
+ include Contrast::Config::BaseConfiguration
13
+
14
+ DEFAULT_PATH = 'contrast_heap_dumps' # saved
15
+ DEFAULT_MS = 10_000
16
+ DEFAULT_COUNT = 5
17
+
18
+ def initialize hsh = {}
19
+ return unless hsh
20
+
21
+ @_enable = hsh[:enable]
22
+ @_path = hsh[:path]
23
+ @_delay_ms = hsh[:delay_ms]
24
+ @_window_ms = hsh[:window_ms]
25
+ @_count = hsh[:count]
26
+ @_clean = hsh[:clean]
27
+ end
28
+
29
+ # @return [Boolean, String] should dumps be taken
30
+ def enable
31
+ @_enable.nil? ? Contrast::Utils::ObjectShare::FALSE : @_enable
32
+ end
33
+
34
+ # @return [String, DEFAULT_PATH] dir to which dumps should be
35
+ def path
36
+ @_path ||= DEFAULT_PATH
37
+ end
38
+
39
+ # @return [Integer, DEFAULT_MS] time, in ms, after initialization
40
+ def delay_ms
41
+ @_delay_ms ||= DEFAULT_MS
42
+ end
43
+
44
+ # @return [Integer, DEFAULT_MS] ms between each dump
45
+ def window_ms
46
+ @_window_ms ||= DEFAULT_MS
47
+ end
48
+
49
+ # @return [Integer, DEFAULT_COUNT] number of dumps to take
50
+ def count
51
+ @_count ||= DEFAULT_COUNT
52
+ end
53
+
54
+ # @return [Boolean, String] remove temporary objects or not
55
+ def clean
56
+ @_clean.nil? ? Contrast::Utils::ObjectShare::FALSE : @_clean
57
+ end
58
+ end
59
+
10
60
  # A wrapper build around the Common Agent Configuration project to allow
11
61
  # for access of the values contained in its
12
62
  # parent_configuration_spec.yaml.
@@ -1,29 +1,35 @@
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 Inventory
7
- # A wrapper build around the Common Agent Configuration project to allow
8
- # for access of the values contained in its
9
- # parent_configuration_spec.yaml.
10
- # Specifically, this allows for querying the state of the Inventory
11
- # product.
9
+ # Interface component for Inventory settings used to store the values from
10
+ # settings file and assert state with check methods.
12
11
  class Interface
13
12
  include Contrast::Components::ComponentBase
14
13
 
15
- def enabled?
16
- @_enabled = !false?(::Contrast::CONFIG.root.inventory.enable) if @_enabled.nil?
17
- @_enabled
14
+ # @return [Array, nil] tags
15
+ attr_accessor :tags
16
+
17
+ def initialize hsh = {}
18
+ return unless hsh
19
+
20
+ @enable = !false?(hsh[:enable])
21
+ @analyze_libraries = !false?(hsh[:analyze_libraries])
22
+ @tags = hsh[:tags]
18
23
  end
19
24
 
20
- def analyze_libraries?
21
- @_analyze_libraries = !false?(::Contrast::CONFIG.root.inventory.analyze_libraries) if @_analyze_libraries.nil?
22
- @_analyze_libraries
25
+ # return [Boolean]
26
+ def enable
27
+ @enable.nil? ? true : @enable
23
28
  end
24
29
 
25
- def tags
26
- ::Contrast::CONFIG.root.inventory&.tags
30
+ # return [Boolean]
31
+ def analyze_libraries
32
+ @analyze_libraries.nil? ? true : @analyze_libraries
27
33
  end
28
34
  end
29
35
  end
@@ -28,8 +28,26 @@ module Contrast
28
28
  end
29
29
  end
30
30
 
31
+ # So This class here follows the update for the configuration
32
+ # and from know on ( if it's as we planned it to be) it will hold the
33
+ # instance methods and will initialize new instances for where they're needed
31
34
  class Interface
32
35
  include InstanceMethods
36
+
37
+ # @return [String, nil]
38
+ attr_accessor :path
39
+ # @return [String, nil]
40
+ attr_accessor :level
41
+ # @return [String, nil]
42
+ attr_accessor :progname
43
+
44
+ def initialize hsh = {}
45
+ return unless hsh
46
+
47
+ @path = hsh[:path]
48
+ @level = hsh[:level]
49
+ @progname = hsh[:progname]
50
+ end
33
51
  end
34
52
  end
35
53
  end
@@ -2,6 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/base'
5
+ require 'contrast/config/exception_configuration'
6
+ require 'contrast/config/protect_rule_configuration'
5
7
 
6
8
  module Contrast
7
9
  module Components
@@ -10,6 +12,39 @@ module Contrast
10
12
  # its parent_configuration_spec.yaml. Specifically, this allows for querying the state of the Protect product.
11
13
  class Interface
12
14
  include Contrast::Components::ComponentBase
15
+ include Contrast::Config::BaseConfiguration
16
+
17
+ # @return [Boolean, nil]
18
+ attr_accessor :enable
19
+
20
+ def initialize hsh = {}
21
+ return unless hsh
22
+
23
+ @_exceptions = Contrast::Config::ExceptionConfiguration.new(hsh[:exceptions])
24
+ @_rules = Contrast::Config::ProtectRulesConfiguration.new(hsh[:rules])
25
+ @enable = hsh[:enable]
26
+ end
27
+
28
+ # @return [Contrast::Config::ExceptionConfiguration]
29
+ def exceptions
30
+ @_exceptions ||= Contrast::Config::ExceptionConfiguration.new
31
+ end
32
+
33
+ # Name is kept the same - rules to correspond to config,
34
+ # mapping. - root.protect.rules
35
+ #
36
+ # @return [Contrast::Config::ProtectRulesConfiguration]
37
+ def rules
38
+ @_rules ||= Contrast::Config::ProtectRulesConfiguration.new
39
+ end
40
+
41
+ def rules= new_rules
42
+ @_rules = new_rules
43
+ end
44
+
45
+ def exceptions= new_exceptions
46
+ @_exceptions = new_exceptions
47
+ end
13
48
 
14
49
  def enabled?
15
50
  # config overrides if forcibly set
@@ -23,7 +58,12 @@ module Contrast
23
58
  ::Contrast::CONFIG.root.protect.rules
24
59
  end
25
60
 
26
- def rules
61
+ # Returns Protect array of all initialized
62
+ # protect rules.
63
+ #
64
+ # @return defend_rules[Hash<Contrast::SETTINGS.protect_state.rules>]
65
+ #
66
+ def defend_rules
27
67
  ::Contrast::SETTINGS.protect_state.rules
28
68
  end
29
69
 
@@ -91,6 +91,35 @@ module Contrast
91
91
  include Constants
92
92
  include ClassMethods
93
93
  end
94
+
95
+ class Interface # :nodoc:
96
+ include InstanceMethods
97
+ include Contrast::Config::BaseConfiguration
98
+
99
+ # @return [Integer, nil]
100
+ attr_reader :baseline
101
+ # @return [Integer, nil]
102
+ attr_reader :request_frequency
103
+ # @return [Integer, nil]
104
+ attr_reader :response_frequency
105
+ # @return [Integer, nil]
106
+ attr_reader :window_ms
107
+
108
+ def initialize hsh = {}
109
+ return unless hsh
110
+
111
+ @enable = hsh[:enable]
112
+ @baseline = hsh[:baseline]
113
+ @request_frequency = hsh[:request_frequency]
114
+ @response_frequency = hsh[:response_frequency]
115
+ @window_ms = hsh[:window_ms]
116
+ end
117
+
118
+ # @return [Boolean, false]
119
+ def enable
120
+ !!@enable
121
+ end
122
+ end
94
123
  end
95
124
  end
96
125
  end