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
@@ -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
|
|
6
5
|
module Contrast
|
7
6
|
module Agent
|
@@ -16,8 +15,6 @@ module Contrast
|
|
16
15
|
# these objects to see if we were tracking on any of them and report
|
17
16
|
# a finding if so.
|
18
17
|
class Xpath
|
19
|
-
include Contrast::Components::Interface
|
20
|
-
|
21
18
|
class << self
|
22
19
|
def xpath_expression_trigger trigger_node, _source, object, ret, *args
|
23
20
|
return ret unless args
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'contrast/agent/assess/events/event_factory'
|
5
5
|
require 'contrast/agent/assess/policy/trigger_validation/trigger_validation'
|
6
|
-
require 'contrast/components/
|
6
|
+
require 'contrast/components/logger'
|
7
7
|
require 'contrast/utils/object_share'
|
8
8
|
require 'contrast/utils/sha256_builder'
|
9
9
|
|
@@ -17,8 +17,7 @@ module Contrast
|
|
17
17
|
# order to determine if the call was done safely. In those cases where
|
18
18
|
# it was not, a Finding report is issued to the Service
|
19
19
|
module TriggerMethod
|
20
|
-
|
21
|
-
access_component :analysis, :logging
|
20
|
+
extend Contrast::Components::Logger::InstanceMethods
|
22
21
|
|
23
22
|
# The level of TeamServer compliance our traces meet when in the
|
24
23
|
# abnormal condition of being dataflow rules without routes
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/assess/policy/trigger_method'
|
5
|
-
require 'contrast/components/
|
5
|
+
require 'contrast/components/logger'
|
6
6
|
require 'contrast/extension/module'
|
7
7
|
|
8
8
|
module Contrast
|
@@ -18,11 +18,11 @@ module Contrast
|
|
18
18
|
# given value set
|
19
19
|
# 3) redacted_marker : the value to plug in for the obfuscated value
|
20
20
|
module HardcodedValueRule
|
21
|
-
include Contrast::Components::
|
22
|
-
|
21
|
+
include Contrast::Components::Logger::InstanceMethods
|
22
|
+
|
23
23
|
|
24
24
|
def disabled?
|
25
|
-
|
25
|
+
!::Contrast::ASSESS.enabled? || ::Contrast::ASSESS.rule_disabled?(rule_id)
|
26
26
|
end
|
27
27
|
|
28
28
|
# TODO: RUBY-1014 - remove `#analyze`
|
@@ -1,14 +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/
|
4
|
+
require 'contrast/components/logger'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
8
8
|
# This module adds an at_exit hook for us to send messages that may be lost at process exit
|
9
9
|
module AtExitHook
|
10
|
-
|
11
|
-
|
10
|
+
extend Contrast::Components::Logger::InstanceMethods
|
11
|
+
|
12
12
|
def self.exit_hook
|
13
13
|
@_exit_hook ||= begin
|
14
14
|
at_exit do
|
@@ -5,7 +5,8 @@ return unless RUBY_VERSION < '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5
|
|
5
5
|
|
6
6
|
require 'ripper'
|
7
7
|
require 'contrast/extension/module'
|
8
|
-
require 'contrast/components/
|
8
|
+
require 'contrast/components/logger'
|
9
|
+
require 'contrast/components/scope'
|
9
10
|
require 'contrast/logger/log'
|
10
11
|
|
11
12
|
# This method is left purposefully at the top level namespace. Moving it
|
@@ -20,7 +21,7 @@ require 'contrast/logger/log'
|
|
20
21
|
def unbound_eval _class_name, content
|
21
22
|
# Yuck, this is a top-level method that has to break encapsulation
|
22
23
|
# in order to access scoping!
|
23
|
-
Contrast::
|
24
|
+
::Contrast::SCOPE.scope_for_current_ec.enter_contrast_scope!
|
24
25
|
eval(content) # rubocop:disable Security/Eval
|
25
26
|
rescue Exception # rubocop:disable Lint/RescueException
|
26
27
|
# We can't use components here, so we have to access the log directly. I hate
|
@@ -29,7 +30,7 @@ rescue Exception # rubocop:disable Lint/RescueException
|
|
29
30
|
# And we need to return nil here, not the value from the logger.
|
30
31
|
nil
|
31
32
|
ensure
|
32
|
-
Contrast::
|
33
|
+
::Contrast::SCOPE.scope_for_current_ec.exit_contrast_scope!
|
33
34
|
end
|
34
35
|
|
35
36
|
module Contrast
|
@@ -38,8 +39,8 @@ module Contrast
|
|
38
39
|
# @deprecated Changes to this class are discouraged as this approach is
|
39
40
|
# being phased out with support for those language versions.
|
40
41
|
class ClassReopener
|
41
|
-
include Contrast::Components::
|
42
|
-
|
42
|
+
include Contrast::Components::Logger::InstanceMethods
|
43
|
+
include Contrast::Components::Scope::InstanceMethods
|
43
44
|
|
44
45
|
END_NEW_LINE = "end\n"
|
45
46
|
PROTECTED_WITH_NEW_LINE = "protected\n"
|
@@ -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/
|
4
|
+
require 'contrast/components/logger'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -9,12 +9,11 @@ module Contrast
|
|
9
9
|
# typically because some configuration setting did not satisfy requirements
|
10
10
|
# set by the Organization's Administrator
|
11
11
|
class DisableReaction
|
12
|
-
|
13
|
-
access_component :agent, :logging
|
12
|
+
extend Contrast::Components::Logger::InstanceMethods
|
14
13
|
|
15
14
|
def self.run _reaction, level
|
16
15
|
logger.with_level(level, 'Contrast received instructions to disable itself - Disabling now')
|
17
|
-
AGENT.disable!
|
16
|
+
::Contrast::AGENT.disable!
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -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/
|
4
|
+
require 'contrast/components/logger'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -9,8 +9,7 @@ module Contrast
|
|
9
9
|
# the Application. If a request or an event matches one of these, the
|
10
10
|
# functions of the Agent are suppressed for that request or event.
|
11
11
|
class ExclusionMatcher
|
12
|
-
include Contrast::Components::
|
13
|
-
access_component :logging
|
12
|
+
include Contrast::Components::Logger::InstanceMethods
|
14
13
|
|
15
14
|
# Create a matcher around an exclusion sent from TeamServer.
|
16
15
|
#
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/inventory/dependencies'
|
5
|
-
require 'contrast/components/interface'
|
6
5
|
require 'contrast/utils/object_share'
|
7
6
|
|
8
7
|
module Contrast
|
@@ -12,17 +11,14 @@ module Contrast
|
|
12
11
|
class DependencyAnalysis
|
13
12
|
include Singleton
|
14
13
|
include Contrast::Agent::Inventory::Dependencies
|
15
|
-
include Contrast::Components::Interface
|
16
|
-
|
17
|
-
access_component :analysis
|
18
14
|
|
19
15
|
# Report the dependencies of this application
|
20
16
|
#
|
21
17
|
# @return [Array<Contrast::Api::Dtm::Library>] protobuf form of the
|
22
18
|
# Gem::Specification that have been loaded for this application.
|
23
19
|
def library_pb_list
|
24
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless INVENTORY.enabled?
|
25
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless INVENTORY.analyze_libraries?
|
20
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless ::Contrast::INVENTORY.enabled?
|
21
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless ::Contrast::INVENTORY.analyze_libraries?
|
26
22
|
|
27
23
|
loaded_specs.each_with_object([]) do |(_name, spec), reported_lib_list|
|
28
24
|
next unless spec
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/inventory/dependencies'
|
5
|
-
require 'contrast/components/
|
5
|
+
require 'contrast/components/logger'
|
6
6
|
require 'contrast/utils/object_share'
|
7
7
|
require 'set'
|
8
8
|
|
@@ -12,11 +12,9 @@ module Contrast
|
|
12
12
|
# Used to analyze class usage for reporting
|
13
13
|
class DependencyUsageAnalysis
|
14
14
|
include Singleton
|
15
|
-
include Contrast::Components::
|
15
|
+
include Contrast::Components::Logger::InstanceMethods
|
16
16
|
include Contrast::Agent::Inventory::Dependencies
|
17
17
|
|
18
|
-
access_component :analysis, :config, :logging
|
19
|
-
|
20
18
|
def initialize
|
21
19
|
return unless enabled?
|
22
20
|
|
@@ -107,7 +105,7 @@ module Contrast
|
|
107
105
|
|
108
106
|
# We only use this if inventory and library analysis are enabled
|
109
107
|
def enabled?
|
110
|
-
@_enabled = INVENTORY.enabled? && INVENTORY.analyze_libraries? if @_enabled.nil?
|
108
|
+
@_enabled = ::Contrast::INVENTORY.enabled? && ::Contrast::INVENTORY.analyze_libraries? if @_enabled.nil?
|
111
109
|
@_enabled
|
112
110
|
end
|
113
111
|
end
|
@@ -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/
|
4
|
+
require 'contrast/components/logger'
|
5
5
|
require 'contrast/utils/inventory_util'
|
6
6
|
|
7
7
|
module Contrast
|
@@ -14,15 +14,14 @@ module Contrast
|
|
14
14
|
# the given invocation is worth reporting or not.
|
15
15
|
module DataStores
|
16
16
|
class << self
|
17
|
-
|
17
|
+
extend Contrast::Components::Logger::InstanceMethods
|
18
18
|
|
19
|
-
access_component :analysis, :logging
|
20
19
|
# The key used in policy.json to indicate the database type to
|
21
20
|
# report.
|
22
21
|
DATA_STORE_MARKER = 'data_store'
|
23
22
|
|
24
23
|
def report_data_store _method, _exception, properties, object, _args
|
25
|
-
return unless INVENTORY.enabled?
|
24
|
+
return unless ::Contrast::INVENTORY.enabled?
|
26
25
|
|
27
26
|
marker = properties[DATA_STORE_MARKER]
|
28
27
|
return unless marker
|
@@ -7,7 +7,8 @@ require 'rack'
|
|
7
7
|
|
8
8
|
require 'contrast/security_exception'
|
9
9
|
require 'contrast/utils/object_share'
|
10
|
-
require 'contrast/components/
|
10
|
+
require 'contrast/components/logger'
|
11
|
+
require 'contrast/components/scope'
|
11
12
|
require 'contrast/utils/heap_dump_util'
|
12
13
|
require 'contrast/agent/request_handler'
|
13
14
|
require 'contrast/agent/static_analysis'
|
@@ -20,8 +21,8 @@ module Contrast
|
|
20
21
|
# initialize ourselves as a rack middleware inside of #initialize. Afterwards, we process each http request and
|
21
22
|
# response as it goes through the middleware stack inside of #call.
|
22
23
|
class Middleware
|
23
|
-
include Contrast::Components::
|
24
|
-
|
24
|
+
include Contrast::Components::Logger::InstanceMethods
|
25
|
+
include Contrast::Components::Scope::InstanceMethods
|
25
26
|
|
26
27
|
attr_reader :app
|
27
28
|
|
@@ -36,10 +37,10 @@ module Contrast
|
|
36
37
|
def initialize app, _legacy_param = nil
|
37
38
|
@app = app # THIS MUST BE FIRST AND ALWAYS SET!
|
38
39
|
setup_agent # THIS MUST BE SECOND AND ALWAYS CALLED!
|
39
|
-
unless AGENT.enabled?
|
40
|
+
unless ::Contrast::AGENT.enabled?
|
40
41
|
logger.error('The Agent was unable to initialize before the application middleware was initialized. '\
|
41
42
|
'Disabling permanently.')
|
42
|
-
AGENT.disable! # ensure the agent is disabled (probably redundant)
|
43
|
+
::Contrast::AGENT.disable! # ensure the agent is disabled (probably redundant)
|
43
44
|
return
|
44
45
|
end
|
45
46
|
agent_startup_routine
|
@@ -53,7 +54,7 @@ module Contrast
|
|
53
54
|
# @return [Array,Rack::Response] the Response of this and subsequent Middlewares to be passed back to the user up
|
54
55
|
# the Rack framework.
|
55
56
|
def call env
|
56
|
-
return app.call(env) unless AGENT.enabled?
|
57
|
+
return app.call(env) unless ::Contrast::AGENT.enabled?
|
57
58
|
|
58
59
|
Contrast::Agent.heapdump_util.start_thread!
|
59
60
|
handle_first_request
|
@@ -63,17 +64,17 @@ module Contrast
|
|
63
64
|
private
|
64
65
|
|
65
66
|
def setup_agent
|
66
|
-
SETTINGS.reset_state
|
67
|
+
::Contrast::SETTINGS.reset_state
|
67
68
|
|
68
69
|
inform_deprecations
|
69
70
|
|
70
|
-
if CONFIG.invalid?
|
71
|
-
AGENT.disable!
|
71
|
+
if ::Contrast::CONFIG.invalid?
|
72
|
+
::Contrast::AGENT.disable!
|
72
73
|
logger.error('!!! CONFIG FILE IS INVALID - DISABLING CONTRAST AGENT !!!')
|
73
|
-
elsif AGENT.disabled?
|
74
|
+
elsif ::Contrast::AGENT.disabled?
|
74
75
|
logger.warn('Contrast disabled by configuration. Continuing without instrumentation.')
|
75
76
|
else
|
76
|
-
AGENT.enable!
|
77
|
+
::Contrast::AGENT.enable!
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
@@ -92,7 +93,7 @@ module Contrast
|
|
92
93
|
end
|
93
94
|
|
94
95
|
logger.debug_with_time('middleware: enabling tracepoint') do
|
95
|
-
AGENT.enable_tracepoint
|
96
|
+
::Contrast::AGENT.enable_tracepoint
|
96
97
|
end
|
97
98
|
Contrast::Agent::AtExitHook.exit_hook
|
98
99
|
end
|
@@ -191,7 +192,7 @@ module Contrast
|
|
191
192
|
# config.agent.ruby.exceptions.capture? is set
|
192
193
|
def handle_exception exception
|
193
194
|
if security_exception?(exception)
|
194
|
-
exception_control = AGENT.exception_control
|
195
|
+
exception_control = ::Contrast::AGENT.exception_control
|
195
196
|
raise exception unless exception_control[:enable]
|
196
197
|
|
197
198
|
[exception_control[:status], {}, [exception_control[:message]]]
|
@@ -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/
|
4
|
+
require 'contrast/components/scope'
|
5
5
|
require 'contrast/extension/module'
|
6
6
|
require 'contrast/utils/class_util'
|
7
7
|
|
@@ -11,8 +11,8 @@ module Contrast
|
|
11
11
|
module Policy
|
12
12
|
# Used to handle tracking patches that need to apply special instrumentation when a module is loaded
|
13
13
|
class AfterLoadPatch
|
14
|
-
include Contrast::Components::
|
15
|
-
|
14
|
+
include Contrast::Components::Scope::InstanceMethods
|
15
|
+
|
16
16
|
attr_reader :applied, :module_name, :instrumentation_file_path, :method_to_instrument, :instrumenting_module
|
17
17
|
|
18
18
|
def initialize module_name, instrumentation_file_path, method_to_instrument: nil, instrumenting_module: nil
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/patching/policy/after_load_patch'
|
5
|
-
require 'contrast/components/
|
5
|
+
require 'contrast/components/logger'
|
6
6
|
require 'contrast/framework/manager'
|
7
7
|
|
8
8
|
module Contrast
|
@@ -12,8 +12,7 @@ module Contrast
|
|
12
12
|
# Some modules diverge from our generic instrumentation and require custom instrumentation
|
13
13
|
# after they've been loaded
|
14
14
|
module AfterLoadPatcher
|
15
|
-
include Contrast::Components::
|
16
|
-
access_component :agent, :logging
|
15
|
+
include Contrast::Components::Logger::InstanceMethods
|
17
16
|
|
18
17
|
# After initialization run a catchup check to instrument any already loaded modules we care about
|
19
18
|
def catchup_after_load_patches
|
@@ -49,7 +48,7 @@ module Contrast
|
|
49
48
|
def apply_load_patches!
|
50
49
|
after_load_patches.each do |after_load_patch|
|
51
50
|
next unless after_load_patch.target_defined?
|
52
|
-
next if AGENT.skip_instrumentation?(after_load_patch.module_name)
|
51
|
+
next if ::Contrast::AGENT.skip_instrumentation?(after_load_patch.module_name)
|
53
52
|
|
54
53
|
logger.trace('Catching up on already loaded afterload patch - applying instrumentation',
|
55
54
|
module: after_load_patch.module_name)
|
@@ -2,7 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'monitor'
|
5
|
-
require 'contrast/components/
|
5
|
+
require 'contrast/components/logger'
|
6
|
+
require 'contrast/components/scope'
|
6
7
|
|
7
8
|
require 'contrast/agent'
|
8
9
|
require 'contrast/logger/log'
|
@@ -35,9 +36,8 @@ module Contrast
|
|
35
36
|
include Contrast::Agent::Assess::Policy::SourceMethod
|
36
37
|
include Contrast::Agent::Assess::Policy::PropagationMethod
|
37
38
|
include Contrast::Agent::Assess::Policy::TriggerMethod
|
38
|
-
|
39
|
-
include Contrast::Components::
|
40
|
-
access_component :agent, :analysis, :logging, :scope
|
39
|
+
include Contrast::Components::Logger::InstanceMethods
|
40
|
+
include Contrast::Components::Scope::InstanceMethods
|
41
41
|
|
42
42
|
POLICIES = [
|
43
43
|
Contrast::Agent::Assess::Policy::Policy,
|
@@ -127,8 +127,8 @@ module Contrast
|
|
127
127
|
# @param args [Array<Object>] The arguments passed to the method
|
128
128
|
# being invoked.
|
129
129
|
def apply_protect method_policy, method, exception, object, args
|
130
|
-
return unless AGENT.enabled?
|
131
|
-
return unless PROTECT.enabled?
|
130
|
+
return unless ::Contrast::AGENT.enabled?
|
131
|
+
return unless ::Contrast::PROTECT.enabled?
|
132
132
|
|
133
133
|
apply_trigger_only(method_policy&.protect_node, method, exception, object, args)
|
134
134
|
end
|
@@ -145,7 +145,7 @@ module Contrast
|
|
145
145
|
# @param args [Array<Object>] The arguments passed to the method
|
146
146
|
# being invoked.
|
147
147
|
def apply_inventory method_policy, method, exception, object, args
|
148
|
-
return unless INVENTORY.enabled?
|
148
|
+
return unless ::Contrast::INVENTORY.enabled?
|
149
149
|
|
150
150
|
apply_trigger_only(method_policy&.inventory_node, method, exception, object, args)
|
151
151
|
end
|
@@ -167,7 +167,7 @@ module Contrast
|
|
167
167
|
def apply_assess method_policy, preshift, object, ret, args, block
|
168
168
|
source_ret = nil
|
169
169
|
propagated_ret = nil
|
170
|
-
return ret unless method_policy && ASSESS.enabled?
|
170
|
+
return ret unless method_policy && ::Contrast::ASSESS.enabled?
|
171
171
|
|
172
172
|
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
173
173
|
return ret if current_context && !current_context.analyze_request?
|