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.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/.simplecov +1 -0
- data/lib/contrast.rb +24 -14
- data/lib/contrast/agent/assess/contrast_event.rb +1 -4
- data/lib/contrast/agent/assess/finalizers/hash.rb +2 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -4
- data/lib/contrast/agent/assess/policy/policy.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -5
- data/lib/contrast/agent/assess/policy/preshift.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagation_method.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +3 -6
- data/lib/contrast/agent/assess/policy/propagator/split.rb +9 -6
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -3
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +7 -7
- data/lib/contrast/agent/assess/policy/source_method.rb +6 -6
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -3
- data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -3
- data/lib/contrast/agent/assess/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -4
- data/lib/contrast/agent/at_exit_hook.rb +3 -3
- data/lib/contrast/agent/class_reopener.rb +6 -5
- data/lib/contrast/agent/disable_reaction.rb +3 -4
- data/lib/contrast/agent/exclusion_matcher.rb +2 -3
- data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -5
- data/lib/contrast/agent/inventory/policy/datastores.rb +3 -4
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +14 -13
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +3 -4
- data/lib/contrast/agent/patching/policy/patch.rb +8 -8
- data/lib/contrast/agent/patching/policy/patcher.rb +6 -6
- data/lib/contrast/agent/patching/policy/policy.rb +2 -4
- data/lib/contrast/agent/patching/policy/policy_node.rb +2 -3
- data/lib/contrast/agent/protect/policy/policy.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -5
- data/lib/contrast/agent/protect/rule/base.rb +10 -10
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +4 -5
- data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -5
- data/lib/contrast/agent/reaction_processor.rb +2 -3
- data/lib/contrast/agent/request.rb +4 -3
- data/lib/contrast/agent/request_context.rb +9 -9
- data/lib/contrast/agent/request_handler.rb +5 -3
- data/lib/contrast/agent/response.rb +2 -3
- data/lib/contrast/agent/rewriter.rb +4 -3
- data/lib/contrast/agent/rule_set.rb +5 -4
- data/lib/contrast/agent/service_heartbeat.rb +2 -3
- data/lib/contrast/agent/static_analysis.rb +6 -5
- data/lib/contrast/agent/thread.rb +2 -4
- data/lib/contrast/agent/thread_watcher.rb +3 -4
- data/lib/contrast/agent/tracepoint_hook.rb +4 -4
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +4 -5
- data/lib/contrast/api/communication/response_processor.rb +11 -11
- data/lib/contrast/api/communication/service_lifecycle.rb +5 -4
- data/lib/contrast/api/communication/socket_client.rb +18 -14
- data/lib/contrast/api/communication/speedracer.rb +5 -6
- data/lib/contrast/api/decorators/address.rb +2 -3
- data/lib/contrast/api/decorators/agent_startup.rb +7 -9
- data/lib/contrast/api/decorators/application_startup.rb +8 -10
- data/lib/contrast/api/decorators/application_update.rb +0 -4
- data/lib/contrast/api/decorators/http_request.rb +3 -7
- data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
- data/lib/contrast/api/decorators/message.rb +7 -7
- data/lib/contrast/api/decorators/trace_event_object.rb +2 -3
- data/lib/contrast/components/agent.rb +10 -15
- data/lib/contrast/components/app_context.rb +7 -11
- data/lib/contrast/components/assess.rb +16 -16
- data/lib/contrast/components/base.rb +40 -0
- data/lib/contrast/components/config.rb +0 -2
- data/lib/contrast/components/contrast_service.rb +6 -11
- data/lib/contrast/components/heap_dump.rb +5 -4
- data/lib/contrast/components/inventory.rb +2 -7
- data/lib/contrast/components/logger.rb +1 -2
- data/lib/contrast/components/protect.rb +10 -13
- data/lib/contrast/components/sampling.rb +5 -5
- data/lib/contrast/components/scope.rb +0 -4
- data/lib/contrast/components/settings.rb +1 -5
- data/lib/contrast/configuration.rb +3 -4
- data/lib/contrast/extension/assess/array.rb +2 -4
- data/lib/contrast/extension/assess/eval_trigger.rb +2 -3
- data/lib/contrast/extension/assess/fiber.rb +6 -5
- data/lib/contrast/extension/assess/hash.rb +3 -3
- data/lib/contrast/extension/assess/kernel.rb +2 -4
- data/lib/contrast/extension/assess/marshal.rb +4 -4
- data/lib/contrast/extension/assess/regexp.rb +5 -4
- data/lib/contrast/extension/assess/string.rb +6 -6
- data/lib/contrast/extension/kernel.rb +2 -4
- data/lib/contrast/extension/protect/kernel.rb +0 -5
- data/lib/contrast/framework/manager.rb +2 -3
- data/lib/contrast/framework/rack/patch/session_cookie.rb +6 -6
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -7
- data/lib/contrast/framework/rails/patch/support.rb +40 -36
- data/lib/contrast/framework/rails/railtie.rb +8 -6
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -4
- data/lib/contrast/funchook/funchook.rb +4 -3
- data/lib/contrast/logger/application.rb +1 -6
- data/lib/contrast/logger/log.rb +22 -6
- data/lib/contrast/logger/request.rb +0 -4
- data/lib/contrast/tasks/service.rb +1 -6
- data/lib/contrast/utils/assess/sampling_util.rb +2 -3
- data/lib/contrast/utils/assess/tracking_util.rb +2 -4
- data/lib/contrast/utils/heap_dump_util.rb +5 -3
- data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
- data/lib/contrast/utils/inventory_util.rb +2 -3
- data/lib/contrast/utils/io_util.rb +2 -4
- data/lib/contrast/utils/job_servers_running.rb +4 -3
- data/lib/contrast/utils/os.rb +2 -3
- data/lib/contrast/utils/string_utils.rb +2 -3
- data/lib/contrast/utils/tag_util.rb +25 -19
- data/ruby-agent.gemspec +4 -2
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +28 -15
- data/lib/contrast/components/interface.rb +0 -196
- 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::
|
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::
|
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/
|
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
|
-
|
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::
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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::
|
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
|
-
|
15
|
+
log_rails = defined?(Rails) && defined?(Rails.logger)
|
16
16
|
|
17
|
-
if
|
18
|
-
|
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/
|
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::
|
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/
|
4
|
+
require 'contrast/components/logger'
|
5
|
+
|
5
6
|
# This module is used to find funchook library and determine availability
|
6
7
|
module Funchook
|
7
|
-
|
8
|
-
|
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)
|
data/lib/contrast/logger/log.rb
CHANGED
@@ -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
|
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/
|
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
|
-
|
15
|
-
access_component :sampling
|
14
|
+
extend Contrast::Components::Sampling::InstanceMethods
|
16
15
|
|
17
16
|
def initialize
|
18
17
|
@requests = {}
|