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
@@ -41,15 +41,13 @@ module Kernel # :nodoc:
41
41
 
42
42
  def catch *args, &block
43
43
  # Save current scope level
44
- scope_level =
45
- Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_get(:@contrast_scope)
44
+ scope_level = ::Contrast::SCOPE.scope_for_current_ec.instance_variable_get(:@contrast_scope)
46
45
 
47
46
  # Run original catch with block.
48
47
  retval = cs__catch(*args, &block)
49
48
 
50
49
  # Restore scope.
51
- Contrast::Components::Scope::COMPONENT_INTERFACE.scope_for_current_ec.instance_variable_set(:@contrast_scope,
52
- scope_level)
50
+ ::Contrast::SCOPE.scope_for_current_ec.instance_variable_set(:@contrast_scope, scope_level)
53
51
 
54
52
  retval
55
53
  end
@@ -1,8 +1,6 @@
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'
5
-
6
4
  module Contrast
7
5
  module Extension
8
6
  module Protect
@@ -10,9 +8,6 @@ module Contrast
10
8
  # allowing us to track activity as it crosses spawned processes.
11
9
  module Kernel
12
10
  class << self
13
- include Contrast::Components::Interface
14
- access_component :contrast_service
15
-
16
11
  def build_wrapper
17
12
  lambda {
18
13
  proc_start
@@ -1,19 +1,18 @@
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'
4
5
  require 'contrast/framework/platform_version'
5
6
  require 'contrast/framework/rack/support'
6
7
  require 'contrast/framework/rails/support'
7
8
  require 'contrast/framework/sinatra/support'
8
- require 'contrast/components/interface'
9
9
  require 'contrast/utils/class_util'
10
10
 
11
11
  module Contrast
12
12
  module Framework
13
13
  # Allows access to framework specific information
14
14
  class Manager
15
- include Contrast::Components::Interface
16
- access_component :analysis, :logging
15
+ include Contrast::Components::Logger::InstanceMethods
17
16
 
18
17
  # Order here does matter as the first framework listed will be the first one we pull information from
19
18
  # Rack will be a special case that may involve updating some logic to handle only applying Rack if Rails/Sinatra
@@ -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 Framework
@@ -11,9 +12,8 @@ module Contrast
11
12
  # runtime detection of insecure configurations on individual cookies
12
13
  # within the application
13
14
  class SessionCookie
14
- include Contrast::Components::Interface
15
-
16
- access_component :agent, :analysis, :logging, :scope
15
+ extend Contrast::Components::Logger::InstanceMethods
16
+ extend Contrast::Components::Scope::InstanceMethods
17
17
 
18
18
  CS__SECURE_RULE_NAME = 'secure-flag-missing'
19
19
  CS__HTTPONLY_NAME = 'rails-http-only-disabled'
@@ -36,8 +36,8 @@ module Contrast
36
36
  end
37
37
 
38
38
  def analyze options
39
- return unless AGENT.enabled?
40
- return if ASSESS.forcibly_disabled?
39
+ return unless ::Contrast::AGENT.enabled?
40
+ return if ::Contrast::ASSESS.forcibly_disabled?
41
41
 
42
42
  apply_session_timeout(options)
43
43
  apply_httponly(options)
@@ -1,7 +1,6 @@
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'
5
4
  require 'contrast/utils/invalid_configuration_util'
6
5
 
7
6
  module Contrast
@@ -10,9 +9,8 @@ module Contrast
10
9
  module Patch
11
10
  # This module is used to analyze rails session storage configuration for assess vulnerabilities
12
11
  module AssessConfiguration
13
- include Contrast::Components::Interface
12
+ include Contrast::Components::Logger::InstanceMethods
14
13
 
15
- access_component :agent, :analysis, :logging
16
14
 
17
15
  CS__SESSION_TIMEOUT_NAME = 'session-timeout'
18
16
  SAFE_SESSION_TIMEOUT = (30 * 60 * 1000)
@@ -23,7 +21,7 @@ module Contrast
23
21
  include Contrast::Utils::InvalidConfigurationUtil
24
22
 
25
23
  def analyze_session_store *args
26
- return if ASSESS.forcibly_disabled?
24
+ return if ::Contrast::ASSESS.forcibly_disabled?
27
25
 
28
26
  apply_httponly_disabled(*args)
29
27
  apply_secure_cookie_disabled(*args)
@@ -52,7 +50,7 @@ module Contrast
52
50
  end
53
51
 
54
52
  def apply_session_timeout *args
55
- return if ASSESS.rule_disabled? CS__SESSION_TIMEOUT_NAME
53
+ return if ::Contrast::ASSESS.rule_disabled? CS__SESSION_TIMEOUT_NAME
56
54
  return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args,
57
55
  comparison_type: :greater_than, safe_default: false)
58
56
 
@@ -67,7 +65,7 @@ module Contrast
67
65
  end
68
66
 
69
67
  def apply_secure_cookie_disabled *args
70
- return if ASSESS.rule_disabled? CS__SECURE_RULE_NAME
68
+ return if ::Contrast::ASSESS.rule_disabled? CS__SECURE_RULE_NAME
71
69
  return unless vulnerable_setting?(:secure, true, args)
72
70
 
73
71
  rails_session_settings = args[1]
@@ -81,7 +79,7 @@ module Contrast
81
79
  end
82
80
 
83
81
  def apply_httponly_disabled *args
84
- return if ASSESS.rule_disabled? CS__HTTPONLY_RULE_NAME
82
+ return if ::Contrast::ASSESS.rule_disabled? CS__HTTPONLY_RULE_NAME
85
83
  return unless vulnerable_setting?(:httponly, true, args)
86
84
 
87
85
  rails_session_settings = args[1]
@@ -25,42 +25,46 @@ module Contrast
25
25
 
26
26
  # (See BaseSupport#after_load_patches)
27
27
  def after_load_patches
28
- Set.new([
29
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
30
- 'ActionController::Live::Buffer',
31
- 'contrast/framework/rails/patch/action_controller_live_buffer',
32
- instrumenting_module: 'Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer'),
33
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
34
- 'Rails::Application::Configuration',
35
- 'contrast/framework/rails/patch/rails_application_configuration',
36
- method_to_instrument: :session_store,
37
- instrumenting_module: 'Contrast::Framework::Rails::Patch::RailsApplicationConfiguration'),
38
-
39
- # TODO: RUBY-714 remove w/ EOL of 2.5
40
- #
41
- # @deprecated Everything past here is used for Rewriting and can
42
- # be removed once we no longer support 2.5.
43
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
44
- 'ActionController::Railties::Helper::ClassMethods',
45
- 'contrast/framework/rails/rewrite/action_controller_railties_helper_inherited',
46
- method_to_instrument: :inherited,
47
- instrumenting_module:
48
- 'Contrast::Framework::Rails::Rewrite::ActionControllerRailtiesHelperInherited'),
49
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
50
- 'ActiveRecord::AttributeMethods::Read::ClassMethods',
51
- 'contrast/framework/rails/rewrite/active_record_attribute_methods_read',
52
- instrumenting_module:
53
- 'Contrast::Framework::Rails::Rewrite::ActiveRecordAttributeMethodsRead'),
54
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
55
- 'ActiveRecord::Scoping::Named::ClassMethods',
56
- 'contrast/framework/rails/rewrite/active_record_named',
57
- instrumenting_module: 'Contrast::Framework::Rails::Rewrite::ActiveRecordNamed'),
58
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
59
- 'ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods',
60
- 'contrast/framework/rails/rewrite/active_record_time_zone_inherited',
61
- method_to_instrument: :inherited,
62
- instrumenting_module: 'Contrast::Framework::Rails::Rewrite::ActiveRecordTimeZoneInherited')
63
- ])
28
+ patches = Set.new([
29
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
30
+ 'ActionController::Live::Buffer',
31
+ 'contrast/framework/rails/patch/action_controller_live_buffer',
32
+ instrumenting_module: 'Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer'),
33
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
34
+ 'Rails::Application::Configuration',
35
+ 'contrast/framework/rails/patch/rails_application_configuration',
36
+ method_to_instrument: :session_store,
37
+ instrumenting_module: 'Contrast::Framework::Rails::Patch::RailsApplicationConfiguration')
38
+ ])
39
+ if RUBY_VERSION < '2.6.0'
40
+ patches.merge([
41
+ # TODO: RUBY-714 remove w/ EOL of 2.5
42
+ #
43
+ # @deprecated Everything past here is used for Rewriting and can
44
+ # be removed once we no longer support 2.5.
45
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
46
+ 'ActionController::Railties::Helper::ClassMethods',
47
+ 'contrast/framework/rails/rewrite/action_controller_railties_helper_inherited',
48
+ method_to_instrument: :inherited,
49
+ instrumenting_module:
50
+ 'Contrast::Framework::Rails::Rewrite::ActionControllerRailtiesHelperInherited'),
51
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
52
+ 'ActiveRecord::AttributeMethods::Read::ClassMethods',
53
+ 'contrast/framework/rails/rewrite/active_record_attribute_methods_read',
54
+ instrumenting_module:
55
+ 'Contrast::Framework::Rails::Rewrite::ActiveRecordAttributeMethodsRead'),
56
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
57
+ 'ActiveRecord::Scoping::Named::ClassMethods',
58
+ 'contrast/framework/rails/rewrite/active_record_named',
59
+ instrumenting_module: 'Contrast::Framework::Rails::Rewrite::ActiveRecordNamed'),
60
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
61
+ 'ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods',
62
+ 'contrast/framework/rails/rewrite/active_record_time_zone_inherited',
63
+ method_to_instrument: :inherited,
64
+ instrumenting_module: 'Contrast::Framework::Rails::Rewrite::ActiveRecordTimeZoneInherited')
65
+ ])
66
+ end
67
+ patches
64
68
  end
65
69
  end
66
70
  end
@@ -2,22 +2,24 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/utils/job_servers_running'
5
+ require 'contrast/components/logger'
5
6
 
6
7
  module Contrast
7
8
  module Framework
8
9
  module Rails
9
10
  # A Railtie to allow for the automatic hooking of the Agent into a Rails application.
10
11
  class Railtie < ::Rails::Railtie
11
- include Contrast::Components::Interface
12
- access_component :agent, :app_context, :logging
12
+ include Contrast::Components::Logger::InstanceMethods
13
13
 
14
14
  initializer 'Contrast Ruby Agent Initializer' do |app|
15
- Rails.logger.debug("In railtie ::#{ app.middleware.inspect }") if defined?(Rails) && defined?(Rails.logger)
15
+ log_rails = defined?(Rails) && defined?(Rails.logger)
16
16
 
17
- if APP_CONTEXT.instrument_middleware_stack?
18
- AGENT.insert_middleware(app)
17
+ Rails.logger.debug("In railtie ::#{ app.middleware.inspect }") if log_rails
18
+
19
+ if ::Contrast::APP_CONTEXT.instrument_middleware_stack?
20
+ ::Contrast::AGENT.insert_middleware(app)
19
21
  else
20
- Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.')
22
+ Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.') if log_rails
21
23
  logger.debug('Disabling Contrast for process', p_id: Process.pid)
22
24
  end
23
25
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  return unless RUBY_VERSION < '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5
5
5
 
6
- require 'contrast/components/interface'
6
+ require 'contrast/components/logger'
7
7
 
8
8
  module Contrast
9
9
  module Framework
@@ -17,12 +17,11 @@ module Contrast
17
17
  # @deprecated Changes to this class are discouraged as this approach is
18
18
  # being phased out with support for those language versions.
19
19
  class ActiveRecordNamed
20
- include Contrast::Components::Interface
21
- access_component :agent, :logging
20
+ include Contrast::Components::Logger::InstanceMethods
22
21
 
23
22
  class << self
24
23
  def rewrite mod, method_name, body
25
- return body unless AGENT.rewrite_interpolation?
24
+ return body unless ::Contrast::AGENT.rewrite_interpolation?
26
25
  return body unless body.is_a?(Proc)
27
26
 
28
27
  location = body.source_location
@@ -1,11 +1,12 @@
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
  # This module is used to find funchook library and determine availability
6
7
  module Funchook
7
- include Contrast::Components::Interface
8
- access_component :logging
8
+ extend Contrast::Components::Logger::InstanceMethods
9
+
9
10
  attr_accessor :path
10
11
 
11
12
  # Possible platform library files
@@ -1,16 +1,11 @@
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'
5
-
6
4
  module Contrast
7
5
  module Logger
8
6
  # Our decorator for the Ougai logger allowing for the logging of the
9
7
  # application environment, used to provide context during troubleshooting.
10
8
  module Application
11
- include Contrast::Components::Interface
12
- access_component :config
13
-
14
9
  ENV_KEYS = %w[HOME PWD RACK_ENV RAILS_ENV RUBY_VERSION GEM_HOME GEM_PATH].cs__freeze
15
10
  # Utility method to log some current ruby and rails information from environment
16
11
  def application_environment
@@ -31,7 +26,7 @@ module Contrast
31
26
  def application_configuration
32
27
  return unless info?
33
28
 
34
- loggable = CONFIG.loggable
29
+ loggable = ::Contrast::CONFIG.loggable
35
30
  info('Current configuration', configuration: loggable)
36
31
  env_keys = ENV.keys.select do |env_key|
37
32
  env_key&.to_s&.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER)
@@ -5,21 +5,37 @@ require 'logger'
5
5
  require 'ougai'
6
6
  require 'singleton'
7
7
 
8
- require 'contrast/components/interface'
9
8
  require 'contrast/extension/module'
10
9
  require 'contrast/logger/application'
11
10
  require 'contrast/logger/format'
12
11
  require 'contrast/logger/request'
13
12
  require 'contrast/logger/time'
13
+ require 'contrast/components/config'
14
14
 
15
15
  module Contrast
16
16
  module Logger
17
+ # For development set following env var to raise logged exceptions instead of just logging.
18
+ if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
19
+ Ougai::Logger.class_eval do
20
+ alias_method :cs__error, :error
21
+ alias_method :cs__warn, :warn
22
+
23
+ def error msg, exc, **kwargs
24
+ cs__error(msg, exc, **kwargs)
25
+ raise exc if exc && exc.cs__class < Exception
26
+ end
27
+
28
+ def warn msg, exc, **kwargs
29
+ cs__warn(msg, exc, **kwargs)
30
+ raise exc if exc && exc.cs__class < Exception
31
+ end
32
+ end
33
+ end
34
+
17
35
  # This class functions to serve as a wrapper around our logging, as we need
18
36
  # to be able to dynamically update level based on updates to TeamServer.
19
37
  class Log
20
38
  include Singleton
21
- include Contrast::Components::Interface
22
- access_component :config
23
39
 
24
40
  DEFAULT_NAME = 'contrast.log'
25
41
  DEFAULT_LEVEL = ::Ougai::Logging::Severity::INFO
@@ -107,8 +123,8 @@ module Contrast
107
123
  # TeamServer.
108
124
  # @return [String] the path to which to log or STDOUT / STDERR if one of those values provided.
109
125
  def find_valid_path log_file
110
- config = CONFIG.root.agent.logger
111
- config_path = config.path&.length.to_i.positive? ? config.path : nil
126
+ config = ::Contrast::CONFIG.root.agent.logger
127
+ config_path = config&.path&.length.to_i.positive? ? config.path : nil
112
128
  valid_path(config_path || log_file)
113
129
  end
114
130
 
@@ -141,7 +157,7 @@ module Contrast
141
157
  # TeamServer.
142
158
  # @return [::Ougai::Logging::Severity] the level at which to log
143
159
  def find_valid_level log_level
144
- config = CONFIG.root.agent.logger
160
+ config = ::Contrast::CONFIG.root.agent.logger
145
161
  config_level = config.level&.length&.positive? ? config.level : nil
146
162
  valid_level(config_level || log_level)
147
163
  end
@@ -1,7 +1,6 @@
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'
5
4
  require 'contrast/utils/timer'
6
5
 
7
6
  module Contrast
@@ -9,9 +8,6 @@ module Contrast
9
8
  # Our decorator for the Ougai logger allowing for the logging of the
10
9
  # request lifecycle, used to provide context during troubleshooting.
11
10
  module Request
12
- include Contrast::Components::Interface
13
- access_component :config
14
-
15
11
  # Utility method to log the start of a request
16
12
  def request_start
17
13
  debug('Beginning request analysis')
@@ -1,7 +1,6 @@
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'
5
4
  require 'contrast/utils/os'
6
5
 
7
6
  module Contrast
@@ -10,14 +9,10 @@ module Contrast
10
9
  # forked from the application
11
10
  module Service
12
11
  extend Rake::DSL
13
- include Contrast::Components::Interface
14
-
15
- access_component :contrast_service
16
-
17
12
  # Start the service if it is not already running
18
13
  def self.start_service
19
14
  puts 'Starting Contrast Service'
20
- service_log = CONTRAST_SERVICE.logger_path
15
+ service_log = ::Contrast::CONTRAST_SERVICE.logger_path
21
16
  if File.writable?(service_log)
22
17
  spawn('contrast_service', out: File::NULL, err: service_log)
23
18
  else
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'singleton'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/sampling'
6
6
 
7
7
  module Contrast
8
8
  module Utils
@@ -11,8 +11,7 @@ module Contrast
11
11
  class SamplingUtil
12
12
  include Singleton
13
13
 
14
- include Contrast::Components::Interface
15
- access_component :sampling
14
+ extend Contrast::Components::Sampling::InstanceMethods
16
15
 
17
16
  def initialize
18
17
  @requests = {}