contrast-agent 4.8.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.simplecov +1 -0
  4. data/lib/contrast.rb +24 -14
  5. data/lib/contrast/agent/assess/contrast_event.rb +1 -4
  6. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -4
  7. data/lib/contrast/agent/assess/policy/patcher.rb +6 -4
  8. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  9. data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -5
  10. data/lib/contrast/agent/assess/policy/preshift.rb +4 -4
  11. data/lib/contrast/agent/assess/policy/propagation_method.rb +4 -4
  12. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +3 -6
  13. data/lib/contrast/agent/assess/policy/propagator/split.rb +9 -6
  14. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -3
  15. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +7 -7
  16. data/lib/contrast/agent/assess/policy/source_method.rb +6 -6
  17. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -3
  18. data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -3
  19. data/lib/contrast/agent/assess/policy/trigger_node.rb +1 -1
  20. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -4
  21. data/lib/contrast/agent/at_exit_hook.rb +3 -3
  22. data/lib/contrast/agent/class_reopener.rb +6 -5
  23. data/lib/contrast/agent/disable_reaction.rb +3 -4
  24. data/lib/contrast/agent/exclusion_matcher.rb +2 -3
  25. data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
  26. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -5
  27. data/lib/contrast/agent/inventory/policy/datastores.rb +3 -4
  28. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  29. data/lib/contrast/agent/middleware.rb +14 -13
  30. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
  31. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +3 -4
  32. data/lib/contrast/agent/patching/policy/patch.rb +8 -8
  33. data/lib/contrast/agent/patching/policy/patcher.rb +6 -6
  34. data/lib/contrast/agent/patching/policy/policy.rb +2 -4
  35. data/lib/contrast/agent/patching/policy/policy_node.rb +2 -3
  36. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  37. data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -5
  38. data/lib/contrast/agent/protect/rule/base.rb +10 -10
  39. data/lib/contrast/agent/protect/rule/cmd_injection.rb +4 -5
  40. data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -5
  41. data/lib/contrast/agent/reaction_processor.rb +2 -3
  42. data/lib/contrast/agent/request.rb +4 -3
  43. data/lib/contrast/agent/request_context.rb +9 -9
  44. data/lib/contrast/agent/request_handler.rb +5 -3
  45. data/lib/contrast/agent/response.rb +2 -3
  46. data/lib/contrast/agent/rewriter.rb +4 -3
  47. data/lib/contrast/agent/rule_set.rb +5 -4
  48. data/lib/contrast/agent/service_heartbeat.rb +2 -3
  49. data/lib/contrast/agent/static_analysis.rb +6 -5
  50. data/lib/contrast/agent/thread.rb +2 -4
  51. data/lib/contrast/agent/thread_watcher.rb +3 -4
  52. data/lib/contrast/agent/tracepoint_hook.rb +4 -4
  53. data/lib/contrast/agent/version.rb +1 -1
  54. data/lib/contrast/api/communication/messaging_queue.rb +4 -5
  55. data/lib/contrast/api/communication/response_processor.rb +11 -11
  56. data/lib/contrast/api/communication/service_lifecycle.rb +5 -4
  57. data/lib/contrast/api/communication/socket_client.rb +18 -14
  58. data/lib/contrast/api/communication/speedracer.rb +5 -6
  59. data/lib/contrast/api/decorators/address.rb +2 -3
  60. data/lib/contrast/api/decorators/agent_startup.rb +7 -9
  61. data/lib/contrast/api/decorators/application_startup.rb +8 -10
  62. data/lib/contrast/api/decorators/application_update.rb +0 -4
  63. data/lib/contrast/api/decorators/http_request.rb +3 -7
  64. data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
  65. data/lib/contrast/api/decorators/message.rb +7 -7
  66. data/lib/contrast/api/decorators/trace_event_object.rb +2 -3
  67. data/lib/contrast/components/agent.rb +10 -15
  68. data/lib/contrast/components/app_context.rb +7 -11
  69. data/lib/contrast/components/assess.rb +16 -16
  70. data/lib/contrast/components/base.rb +40 -0
  71. data/lib/contrast/components/config.rb +0 -2
  72. data/lib/contrast/components/contrast_service.rb +6 -11
  73. data/lib/contrast/components/heap_dump.rb +5 -4
  74. data/lib/contrast/components/inventory.rb +2 -7
  75. data/lib/contrast/components/logger.rb +1 -2
  76. data/lib/contrast/components/protect.rb +10 -13
  77. data/lib/contrast/components/sampling.rb +5 -5
  78. data/lib/contrast/components/scope.rb +0 -4
  79. data/lib/contrast/components/settings.rb +1 -5
  80. data/lib/contrast/configuration.rb +3 -4
  81. data/lib/contrast/extension/assess/array.rb +2 -4
  82. data/lib/contrast/extension/assess/eval_trigger.rb +2 -3
  83. data/lib/contrast/extension/assess/fiber.rb +6 -5
  84. data/lib/contrast/extension/assess/hash.rb +3 -3
  85. data/lib/contrast/extension/assess/kernel.rb +2 -4
  86. data/lib/contrast/extension/assess/marshal.rb +4 -4
  87. data/lib/contrast/extension/assess/regexp.rb +5 -4
  88. data/lib/contrast/extension/assess/string.rb +6 -6
  89. data/lib/contrast/extension/kernel.rb +2 -4
  90. data/lib/contrast/extension/protect/kernel.rb +0 -5
  91. data/lib/contrast/framework/manager.rb +2 -3
  92. data/lib/contrast/framework/rack/patch/session_cookie.rb +6 -6
  93. data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -7
  94. data/lib/contrast/framework/rails/patch/support.rb +40 -36
  95. data/lib/contrast/framework/rails/railtie.rb +8 -6
  96. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -4
  97. data/lib/contrast/funchook/funchook.rb +4 -3
  98. data/lib/contrast/logger/application.rb +1 -6
  99. data/lib/contrast/logger/log.rb +22 -6
  100. data/lib/contrast/logger/request.rb +0 -4
  101. data/lib/contrast/tasks/service.rb +1 -6
  102. data/lib/contrast/utils/assess/sampling_util.rb +2 -3
  103. data/lib/contrast/utils/assess/tracking_util.rb +2 -4
  104. data/lib/contrast/utils/heap_dump_util.rb +5 -3
  105. data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
  106. data/lib/contrast/utils/inventory_util.rb +2 -3
  107. data/lib/contrast/utils/io_util.rb +2 -4
  108. data/lib/contrast/utils/job_servers_running.rb +4 -3
  109. data/lib/contrast/utils/os.rb +2 -3
  110. data/lib/contrast/utils/string_utils.rb +2 -3
  111. data/lib/contrast/utils/tag_util.rb +25 -19
  112. data/ruby-agent.gemspec +4 -2
  113. data/service_executables/VERSION +1 -1
  114. data/service_executables/linux/contrast-service +0 -0
  115. data/service_executables/mac/contrast-service +0 -0
  116. metadata +28 -15
  117. data/lib/contrast/components/interface.rb +0 -196
  118. data/lib/contrast/delegators/input_analysis.rb +0 -12
@@ -7,7 +7,8 @@ require 'monitor'
7
7
  require 'contrast/agent/patching/policy/patch_status'
8
8
  require 'contrast/agent/patching/policy/method_policy'
9
9
  require 'contrast/agent/patching/policy/module_policy'
10
- require 'contrast/components/interface'
10
+ require 'contrast/components/logger'
11
+ require 'contrast/components/scope'
11
12
  require 'contrast/utils/class_util'
12
13
 
13
14
  # assess
@@ -43,9 +44,8 @@ module Contrast
43
44
  # and how.
44
45
  module Patcher
45
46
  extend Contrast::Agent::Patching::Policy::AfterLoadPatcher
46
-
47
- include Contrast::Components::Interface
48
- access_component :agent, :analysis, :logging, :scope
47
+ extend Contrast::Components::Logger::InstanceMethods
48
+ extend Contrast::Components::Scope::InstanceMethods
49
49
 
50
50
  class << self
51
51
  # Hook to install the Contrast changes needed to allow for the
@@ -82,7 +82,7 @@ module Contrast
82
82
  with_contrast_scope do
83
83
  mod_name = mod.cs__name
84
84
  return unless Contrast::Utils::ClassUtil.truly_defined?(mod_name)
85
- return if AGENT.skip_instrumentation?(mod_name)
85
+ return if ::Contrast::AGENT.skip_instrumentation?(mod_name)
86
86
 
87
87
  load_patches_for_module(mod_name)
88
88
 
@@ -156,7 +156,7 @@ module Contrast
156
156
  logger.trace_with_time('Running patching') do
157
157
  patched = []
158
158
  all_module_names.each do |patchable_name|
159
- next if AGENT.skip_instrumentation?(patchable_name)
159
+ next if ::Contrast::AGENT.skip_instrumentation?(patchable_name)
160
160
 
161
161
  patchable_mod = patchable(patchable_name)
162
162
  next unless patchable_mod
@@ -5,7 +5,7 @@ require 'json'
5
5
  require 'singleton'
6
6
 
7
7
  require 'contrast'
8
- require 'contrast/components/interface'
8
+ require 'contrast/components/logger'
9
9
  require 'contrast/agent/patching/policy/module_policy'
10
10
  require 'contrast/agent/patching/policy/method_policy'
11
11
 
@@ -19,7 +19,7 @@ module Contrast
19
19
  # @abstract
20
20
  class Policy
21
21
  include Singleton
22
- include Contrast::Components::Interface
22
+ include Contrast::Components::Logger::InstanceMethods
23
23
 
24
24
  # Indicates the folder in `resources` where this policy lives.
25
25
  def self.policy_folder
@@ -36,8 +36,6 @@ module Contrast
36
36
  raise(NoMethodError, 'specify the concrete node type for this poilcy')
37
37
  end
38
38
 
39
- access_component :analysis, :logging
40
-
41
39
  attr_reader :sources, :propagators, :triggers, :providers
42
40
 
43
41
  SOURCES_KEY = 'sources'
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/components/interface'
4
+ require 'contrast/components/scope'
5
5
 
6
6
  module Contrast
7
7
  module Agent
@@ -12,8 +12,7 @@ module Contrast
12
12
  #
13
13
  # @abstract
14
14
  class PolicyNode
15
- include Contrast::Components::Interface
16
- access_component :analysis, :scope
15
+ include Contrast::Components::Scope::InstanceMethods
17
16
 
18
17
  attr_accessor :class_name, :instance_method, :method_name, :method_visibility
19
18
  attr_reader :properties, :method_scope
@@ -24,7 +24,7 @@ module Contrast
24
24
  end
25
25
 
26
26
  def disabled_globally?
27
- PROTECT.forcibly_disabled?
27
+ ::Contrast::PROTECT.forcibly_disabled?
28
28
  end
29
29
 
30
30
  def node_type
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/components/interface'
4
+ require 'contrast/components/logger'
5
5
 
6
6
  module Contrast
7
7
  module Agent
@@ -11,9 +11,7 @@ module Contrast
11
11
  # form of the Applicator, which will override specific implementations
12
12
  # in order to properly invoke its Rule.
13
13
  module RuleApplicator
14
- include Contrast::Components::Interface
15
-
16
- access_component :analysis, :logging
14
+ include Contrast::Components::Logger::InstanceMethods
17
15
 
18
16
  # Calls the actual invocation for this applicator, if required. Will
19
17
  # attempt to transform the data as required prior to invocation and
@@ -82,7 +80,7 @@ module Contrast
82
80
  #
83
81
  # @return [Contrast::Agent::Protect::Rule::Base]
84
82
  def rule
85
- PROTECT.rule rule_name
83
+ ::Contrast::PROTECT.rule rule_name
86
84
  end
87
85
 
88
86
  # Should we skip analysis for this rule for this method invocation?
@@ -1,7 +1,8 @@
1
1
  # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/components/interface'
4
+ require 'contrast/components/logger'
5
+ require 'contrast/components/scope'
5
6
 
6
7
  module Contrast
7
8
  module Agent
@@ -12,9 +13,8 @@ module Contrast
12
13
  #
13
14
  # @abstract Subclass and override {#prefilter}, {#infilter}, {#find_attacker}, {#postfilter} to implement
14
15
  class Base
15
- include Contrast::Components::Interface
16
-
17
- access_component :agent, :analysis, :logging, :scope, :settings
16
+ include Contrast::Components::Logger::InstanceMethods
17
+ include Contrast::Components::Scope::InstanceMethods
18
18
 
19
19
  UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
20
20
  user_input.input_type = :UNKNOWN
@@ -37,7 +37,7 @@ module Contrast
37
37
  attr_reader :mode
38
38
 
39
39
  def initialize
40
- PROTECT.rules[rule_name] = self
40
+ ::Contrast::PROTECT.rules[rule_name] = self
41
41
  @mode = mode_from_settings
42
42
  end
43
43
 
@@ -48,11 +48,11 @@ module Contrast
48
48
 
49
49
  def enabled?
50
50
  # 1. it is not enabled because protect is not enabled
51
- return false unless AGENT.enabled?
52
- return false unless PROTECT.enabled?
51
+ return false unless ::Contrast::AGENT.enabled?
52
+ return false unless ::Contrast::PROTECT.enabled?
53
53
 
54
54
  # 2. it is not enabled because it is in the list of disabled protect rules
55
- return false if PROTECT.rule_config&.disabled_rules&.include?(rule_name)
55
+ return false if ::Contrast::PROTECT.rule_config&.disabled_rules&.include?(rule_name)
56
56
 
57
57
  # 3. it is enabled so long as its mode is not NO_ACTION
58
58
  @mode != Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
@@ -176,7 +176,7 @@ module Contrast
176
176
  protected
177
177
 
178
178
  def mode_from_settings
179
- PROTECT.rule_mode(rule_name).tap do |mode|
179
+ ::Contrast::PROTECT.rule_mode(rule_name).tap do |mode|
180
180
  logger.trace('Retrieving rule mode', rule: rule_name, mode: mode)
181
181
  end
182
182
  end
@@ -191,7 +191,7 @@ module Contrast
191
191
  # @return [Boolean] if an exclusion was applicable to this request
192
192
  # for this rule
193
193
  def protect_excluded_by_code?
194
- exclusions = SETTINGS.code_exclusions
194
+ exclusions = ::Contrast::SETTINGS.code_exclusions
195
195
  return false unless exclusions
196
196
 
197
197
  for_rule = exclusions.select { |ex| ex.protection_rule?(rule_name) }
@@ -4,7 +4,7 @@
4
4
  require 'contrast/agent/protect/rule/base_service'
5
5
  require 'contrast/utils/stack_trace_utils'
6
6
  require 'contrast/utils/object_share'
7
- require 'contrast/components/interface'
7
+ require 'contrast/components/logger'
8
8
 
9
9
  module Contrast
10
10
  module Agent
@@ -12,8 +12,7 @@ module Contrast
12
12
  module Rule
13
13
  # The Ruby implementation of the Protect Command Injection rule.
14
14
  class CmdInjection < Contrast::Agent::Protect::Rule::BaseService
15
- include Contrast::Components::Interface
16
- access_component :app_context, :logging
15
+ include Contrast::Components::Logger::InstanceMethods
17
16
 
18
17
  NAME = 'cmd-injection'
19
18
  CHAINED_COMMAND_CHARS = /[;&|<>]/.cs__freeze
@@ -28,7 +27,7 @@ module Contrast
28
27
  ia_results = gather_ia_results(context)
29
28
  return if ia_results.empty?
30
29
 
31
- if APP_CONTEXT.in_new_process?
30
+ if ::Contrast::APP_CONTEXT.in_new_process?
32
31
  logger.trace('Running cmd-injection infilter within new process - creating new context')
33
32
  context = Contrast::Agent::RequestContext.new(context.request.rack_request)
34
33
  Contrast::Agent::REQUEST_TRACKER.update_current_context(context)
@@ -124,7 +123,7 @@ module Contrast
124
123
  # @return [Boolean] if the agent should report all command
125
124
  # executions.
126
125
  def report_any_command_execution?
127
- PROTECT.report_any_command_execution?
126
+ ::Contrast::PROTECT.report_any_command_execution?
128
127
  end
129
128
  end
130
129
  end
@@ -2,7 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/protect/rule/base_service'
5
- require 'contrast/components/interface'
6
5
  require 'contrast/utils/stack_trace_utils'
7
6
 
8
7
  module Contrast
@@ -12,9 +11,6 @@ module Contrast
12
11
  # This class handles our implementation of the Path Traversal
13
12
  # Protect rule.
14
13
  class PathTraversal < Contrast::Agent::Protect::Rule::BaseService
15
- include Contrast::Components::Interface
16
- access_component :agent, :analysis
17
-
18
14
  NAME = 'path-traversal'
19
15
  SYSTEM_PATHS = %w[
20
16
  /proc/self
@@ -96,7 +92,7 @@ module Contrast
96
92
  end
97
93
 
98
94
  def custom_code_access_sysfile_enabled?
99
- PROTECT.report_custom_code_sysfile_access?
95
+ ::Contrast::PROTECT.report_custom_code_sysfile_access?
100
96
  end
101
97
 
102
98
  def custom_code_accessing_system_file? input
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/disable_reaction'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/logger'
6
6
 
7
7
  module Contrast
8
8
  module Agent
@@ -10,8 +10,7 @@ module Contrast
10
10
  # from the Agent/Service, we must provide a mechanism for the TeamServer to direct the Agent to take a specific
11
11
  # action. This action is referred to as a Reaction. This class is how we handle those Reaction messages.
12
12
  class ReactionProcessor
13
- include Contrast::Components::Interface
14
- access_component :logging
13
+ extend Contrast::Components::Logger::InstanceMethods
15
14
 
16
15
  # Process the given Reactions from the application settings based on what
17
16
  # TeamServer has indicated. Each Reaction will result in a log message
@@ -7,7 +7,8 @@ require 'timeout'
7
7
  require 'contrast/utils/object_share'
8
8
  require 'contrast/utils/string_utils'
9
9
  require 'contrast/utils/hash_digest'
10
- require 'contrast/components/interface'
10
+ require 'contrast/components/logger'
11
+ require 'contrast/components/scope'
11
12
 
12
13
  module Contrast
13
14
  module Agent
@@ -16,8 +17,8 @@ module Contrast
16
17
  # data in a format that the Agent expects, caching those transformations in
17
18
  # order to avoid repeatedly creating Strings & thrashing GC.
18
19
  class Request
19
- include Contrast::Components::Interface
20
- access_component :agent, :logging, :scope
20
+ include Contrast::Components::Logger::InstanceMethods
21
+ include Contrast::Components::Scope::InstanceMethods
21
22
 
22
23
  extend Forwardable
23
24
 
@@ -5,8 +5,8 @@ require 'contrast/utils/timer'
5
5
  require 'contrast/agent/request'
6
6
  require 'contrast/agent/response'
7
7
  require 'contrast/utils/inventory_util'
8
- require 'contrast/components/interface'
9
- require 'contrast/delegators/input_analysis'
8
+ require 'contrast/components/logger'
9
+ require 'contrast/components/scope'
10
10
 
11
11
  module Contrast
12
12
  module Agent
@@ -26,8 +26,8 @@ module Contrast
26
26
  # @attr_reader route [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
27
27
  # @attr_reader observed_route [Contrast::Api::Dtm::ObservedRoute] the route, used for coverage, of this request
28
28
  class RequestContext
29
- include Contrast::Components::Interface
30
- access_component :agent, :analysis, :logging, :scope
29
+ include Contrast::Components::Logger::InstanceMethods
30
+ include Contrast::Components::Scope::InstanceMethods
31
31
 
32
32
  EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
33
33
 
@@ -63,11 +63,11 @@ module Contrast
63
63
 
64
64
  @sample = true
65
65
 
66
- if ASSESS.enabled?
66
+ if ::Contrast::ASSESS.enabled?
67
67
  @sample_request, @sample_response = Contrast::Utils::Assess::SamplingUtil.instance.sample?(@request)
68
68
  end
69
69
 
70
- @sample_response &&= ASSESS.scan_response?
70
+ @sample_response &&= ::Contrast::ASSESS.scan_response?
71
71
 
72
72
  append_route_coverage(Contrast::Agent.framework_manager.get_route_dtm(@request))
73
73
  end
@@ -120,8 +120,8 @@ module Contrast
120
120
  end
121
121
 
122
122
  def service_extract_request
123
- return false unless AGENT.enabled?
124
- return false unless PROTECT.enabled?
123
+ return false unless ::Contrast::AGENT.enabled?
124
+ return false unless ::Contrast::PROTECT.enabled?
125
125
  return false if @do_not_track
126
126
 
127
127
  service_response = Contrast::Agent.messaging_queue.send_event_immediately(@activity.http_request)
@@ -201,7 +201,7 @@ module Contrast
201
201
  attack_results_by_rule = {}
202
202
  agent_settings.input_analysis.results.each do |ia_result|
203
203
  rule_id = ia_result.rule_id
204
- rule = PROTECT.rule(rule_id)
204
+ rule = ::Contrast::PROTECT.rule(rule_id)
205
205
  next unless rule
206
206
 
207
207
  logger.debug('Building attack result from Contrast Service input analysis result', result: ia_result.inspect)
@@ -1,20 +1,22 @@
1
1
  # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'contrast/components/logger'
5
+ require 'contrast/components/scope'
6
+
4
7
  module Contrast
5
8
  module Agent
6
9
  # This class is instantiated when we receive a request and the agent is enabled to process
7
10
  # that request. It holds the ruleset that we perform filtering operations on (currently
8
11
  # prefilter and postfilter).
9
12
  class RequestHandler
10
- include Contrast::Components::Interface
11
- access_component :agent, :logging, :scope
13
+ include Contrast::Components::Logger::InstanceMethods
12
14
 
13
15
  attr_reader :ruleset, :context
14
16
 
15
17
  def initialize context
16
18
  @context = context
17
- @ruleset = AGENT.ruleset
19
+ @ruleset = ::Contrast::AGENT.ruleset
18
20
  end
19
21
 
20
22
  def send_activity_messages
@@ -7,7 +7,7 @@ require 'timeout'
7
7
  require 'contrast/utils/object_share'
8
8
  require 'contrast/utils/string_utils'
9
9
  require 'contrast/utils/hash_digest'
10
- require 'contrast/components/interface'
10
+ require 'contrast/components/logger'
11
11
 
12
12
  module Contrast
13
13
  module Agent
@@ -16,8 +16,7 @@ module Contrast
16
16
  # data in a format that the Agent expects, caching those transformations in
17
17
  # order to avoid repeatedly creating Strings & thrashing GC.
18
18
  class Response
19
- include Contrast::Components::Interface
20
- access_component :logging
19
+ include Contrast::Components::Logger::InstanceMethods
21
20
 
22
21
  extend Forwardable
23
22
 
@@ -7,7 +7,8 @@ return unless RUBY_VERSION < '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5
7
7
 
8
8
  require 'contrast/agent/class_reopener'
9
9
  require 'contrast/agent/patching/policy/patch_status'
10
- require 'contrast/components/interface'
10
+ require 'contrast/components/logger'
11
+ require 'contrast/components/scope'
11
12
  require 'contrast/utils/ruby_ast_rewriter'
12
13
 
13
14
  module Contrast
@@ -19,8 +20,8 @@ module Contrast
19
20
  # @deprecated Changes to this class are discouraged as this approach is
20
21
  # being phased out with support for those language versions.
21
22
  class Rewriter
22
- include Contrast::Components::Interface
23
- access_component :logging, :scope
23
+ extend Contrast::Components::Logger::InstanceMethods
24
+ extend Contrast::Components::Scope::InstanceMethods
24
25
 
25
26
  SELF_DEFINITION = 'def self.'
26
27
  DEFINITION = 'def '
@@ -1,13 +1,14 @@
1
1
  # Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'contrast/components/logger'
5
+
4
6
  module Contrast
5
7
  module Agent
6
8
  # This class is responsible for holding our ruleset and performing filtering operations on all
7
9
  # rules when asked by the middleware.
8
10
  class RuleSet < Set
9
- include Contrast::Components::Interface
10
- access_component :analysis, :logging
11
+ include Contrast::Components::Logger::InstanceMethods
11
12
 
12
13
  # The filtering that needs to happen before the application gets access to the request object.
13
14
  # The main action here is snapshotting the request as provided to the application from the
@@ -16,7 +17,7 @@ module Contrast
16
17
  def prefilter
17
18
  context = Contrast::Agent::REQUEST_TRACKER.current
18
19
  # TODO: RUBY-801 We shouldn't be responsible for knowing what modes are enabled
19
- return unless context&.analyze_request? || PROTECT.enabled?
20
+ return unless context&.analyze_request? || ::Contrast::PROTECT.enabled?
20
21
 
21
22
  logger.trace_with_time('Running prefilter...') do
22
23
  map { |rule| rule.prefilter(context) }
@@ -33,7 +34,7 @@ module Contrast
33
34
  def postfilter
34
35
  context = Contrast::Agent::REQUEST_TRACKER.current
35
36
  # TODO: RUBY-801 We shouldn't be responsible for knowing what modes are enabled
36
- return unless context&.analyze_response? || PROTECT.enabled?
37
+ return unless context&.analyze_response? || ::Contrast::PROTECT.enabled?
37
38
 
38
39
  logger.trace_with_time('Running postfilter...') do
39
40
  map { |rule| rule.postfilter(context) }