contrast-agent 3.14.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -15
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_string/cs__assess_string.c +24 -25
- data/ext/cs__assess_string/cs__assess_string.h +3 -1
- data/ext/cs__common/cs__common.c +4 -2
- data/ext/cs__common/cs__common.h +1 -1
- data/lib/contrast.rb +1 -1
- data/lib/contrast/agent.rb +4 -12
- data/lib/contrast/agent/assess.rb +1 -0
- data/lib/contrast/agent/assess/contrast_event.rb +143 -79
- data/lib/contrast/agent/assess/events/source_event.rb +1 -1
- data/lib/contrast/agent/assess/finalizers/freeze.rb +3 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +45 -1
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy.rb +0 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +15 -10
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +7 -11
- data/lib/contrast/agent/assess/policy/propagation_method.rb +50 -33
- data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +5 -3
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +4 -7
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +24 -19
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +47 -31
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +85 -58
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +76 -28
- data/lib/contrast/agent/assess/policy/trigger_node.rb +38 -43
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/properties.rb +2 -0
- data/lib/contrast/agent/assess/property/evented.rb +5 -18
- data/lib/contrast/agent/assess/property/tagged.rb +9 -3
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +66 -0
- data/lib/contrast/agent/at_exit_hook.rb +5 -5
- data/lib/contrast/agent/class_reopener.rb +7 -5
- data/lib/contrast/agent/inventory.rb +15 -0
- data/lib/contrast/agent/inventory/dependencies.rb +50 -0
- data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
- data/lib/contrast/agent/middleware.rb +1 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
- data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
- data/lib/contrast/agent/patching/policy/patch.rb +6 -0
- data/lib/contrast/agent/patching/policy/patcher.rb +13 -22
- data/lib/contrast/agent/patching/policy/policy.rb +17 -6
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +9 -25
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/request.rb +34 -34
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +17 -6
- data/lib/contrast/agent/rewriter.rb +1 -3
- data/lib/contrast/agent/scope.rb +59 -53
- data/lib/contrast/agent/static_analysis.rb +7 -7
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +1 -4
- data/lib/contrast/api/communication/socket_client.rb +36 -1
- data/lib/contrast/api/decorators.rb +3 -0
- data/lib/contrast/api/decorators/address.rb +13 -14
- data/lib/contrast/api/decorators/application_update.rb +2 -4
- data/lib/contrast/api/decorators/library.rb +53 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
- data/lib/contrast/api/decorators/message.rb +1 -0
- data/lib/contrast/api/decorators/trace_event.rb +25 -23
- data/lib/contrast/common_agent_configuration.rb +2 -1
- data/lib/contrast/components/agent.rb +6 -5
- data/lib/contrast/components/app_context.rb +49 -38
- data/lib/contrast/components/config.rb +30 -48
- data/lib/contrast/components/contrast_service.rb +9 -9
- data/lib/contrast/components/interface.rb +25 -3
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/scope.rb +49 -6
- data/lib/contrast/components/settings.rb +23 -23
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +88 -47
- data/lib/contrast/extension/assess.rb +0 -2
- data/lib/contrast/extension/assess/array.rb +15 -8
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -4
- data/lib/contrast/extension/assess/fiber.rb +12 -12
- data/lib/contrast/extension/assess/hash.rb +5 -6
- data/lib/contrast/extension/assess/kernel.rb +28 -23
- data/lib/contrast/extension/assess/marshal.rb +11 -6
- data/lib/contrast/extension/assess/regexp.rb +8 -7
- data/lib/contrast/extension/assess/string.rb +21 -21
- data/lib/contrast/extension/protect/kernel.rb +3 -3
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +3 -3
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -11
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +10 -10
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +5 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
- data/lib/contrast/framework/sinatra/support.rb +4 -4
- data/lib/contrast/logger/application.rb +11 -3
- data/lib/contrast/logger/log.rb +7 -2
- data/lib/contrast/utils/assess/tracking_util.rb +48 -3
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/invalid_configuration_util.rb +20 -21
- data/lib/contrast/utils/inventory_util.rb +0 -7
- data/lib/contrast/utils/sha256_builder.rb +0 -12
- data/lib/contrast/utils/string_utils.rb +10 -5
- data/resources/assess/policy.json +31 -22
- data/ruby-agent.gemspec +21 -18
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +71 -30
- data/lib/contrast/agent/assess/finalizers/finalize.rb +0 -21
- data/lib/contrast/extension/assess/assess_extension.rb +0 -145
- data/lib/contrast/utils/boolean_util.rb +0 -30
- data/lib/contrast/utils/freeze_util.rb +0 -32
- data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -30,8 +30,6 @@ module Contrast
|
|
30
30
|
require 'contrast/agent/assess/policy/policy'
|
31
31
|
require 'contrast/agent/assess/policy/patcher'
|
32
32
|
|
33
|
-
# classes that don't play nice w/ our standard propagation
|
34
|
-
require 'contrast/extension/assess/assess_extension'
|
35
33
|
# this needs to come first b/c array and others work on strings and
|
36
34
|
# expect them to be trackable
|
37
35
|
require 'contrast/extension/assess/string'
|
@@ -35,37 +35,44 @@ module Contrast
|
|
35
35
|
# operation happens in C, we have to do it here rather than rely on the
|
36
36
|
# patch of our String append or concat methods.
|
37
37
|
def cs__track_join ary, separator, ret
|
38
|
-
return unless ary
|
38
|
+
return ret unless ary&.any? { |element| Contrast::Agent::Assess::Tracker.tracked?(element) }
|
39
39
|
return ret if Contrast::Agent::Patching::Policy::Patch.skip_assess_analysis?
|
40
40
|
|
41
41
|
with_contrast_scope do
|
42
|
+
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
43
|
+
return ret unless properties
|
44
|
+
|
42
45
|
shift = 0
|
43
46
|
separator_length = separator.nil? ? 0 : separator.to_s.length
|
47
|
+
parent_events = []
|
44
48
|
ary.each do |obj|
|
45
49
|
if obj # skip nil here
|
46
|
-
|
50
|
+
properties.copy_from(obj, ret, shift)
|
47
51
|
shift += obj.to_s.length
|
52
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(obj)&.event
|
53
|
+
parent_events << parent_event if parent_event
|
48
54
|
end
|
49
55
|
shift += separator_length
|
50
56
|
end
|
51
|
-
return ret unless
|
57
|
+
return ret unless Contrast::Agent::Assess::Tracker.tracked?(ret)
|
52
58
|
|
53
|
-
|
54
|
-
|
59
|
+
properties.cleanup_tags
|
60
|
+
properties.build_event(
|
55
61
|
ARRAY_JOIN_NODE,
|
56
62
|
ret,
|
57
63
|
ary,
|
58
64
|
ret,
|
59
65
|
[separator])
|
66
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
60
67
|
ret
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
64
71
|
def instrument_array_track
|
65
72
|
@_instrument_array_track ||= begin
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
require 'cs__assess_array/cs__assess_array'
|
74
|
+
true
|
75
|
+
end
|
69
76
|
rescue StandardError, LoadError => e
|
70
77
|
logger.error('Error loading assess track patch', e)
|
71
78
|
false
|
@@ -7,27 +7,35 @@ module ERBPropagator
|
|
7
7
|
def result_tagger patcher, preshift, ret, _block
|
8
8
|
return unless preshift.args.length >= 1
|
9
9
|
|
10
|
+
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
11
|
+
return unless properties
|
12
|
+
|
10
13
|
used_binding = preshift.args[0]
|
11
14
|
binding_variable_set = used_binding.local_variables
|
12
15
|
|
13
16
|
erb_pre_result = preshift.object.src
|
17
|
+
parent_events = []
|
14
18
|
binding_variable_set.each do |bound_var_symbol|
|
15
19
|
bound_variable_value = used_binding.local_variable_get(bound_var_symbol)
|
16
|
-
next unless
|
20
|
+
next unless Contrast::Agent::Assess::Tracker.tracked?(bound_variable_value)
|
17
21
|
next unless erb_pre_result.include?(bound_var_symbol.to_s)
|
18
22
|
|
19
23
|
start_index = ret.index(bound_variable_value)
|
20
24
|
next if start_index.nil?
|
21
25
|
|
22
|
-
|
26
|
+
properties.copy_from(bound_variable_value, ret, start_index)
|
27
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(bound_variable_value)&.event
|
28
|
+
parent_events << parent_event if parent_event
|
23
29
|
end
|
24
|
-
|
30
|
+
properties.build_event(
|
25
31
|
patcher,
|
26
32
|
ret,
|
27
33
|
preshift.object,
|
28
34
|
ret,
|
29
35
|
preshift.args,
|
30
36
|
1)
|
37
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
38
|
+
|
31
39
|
ret
|
32
40
|
end
|
33
41
|
end
|
@@ -45,9 +45,9 @@ module Contrast
|
|
45
45
|
|
46
46
|
def instrument_basic_object_track
|
47
47
|
@_instrument_basic_object_track ||= begin
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
require 'cs__assess_basic_object/cs__assess_basic_object'
|
49
|
+
true
|
50
|
+
end
|
51
51
|
rescue StandardError, LoadError => e
|
52
52
|
logger.error('Error loading basic object track patch', e)
|
53
53
|
false
|
@@ -55,9 +55,9 @@ module Contrast
|
|
55
55
|
|
56
56
|
def instrument_module_track
|
57
57
|
@_instrument_module_track ||= begin
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
require 'cs__assess_module/cs__assess_module'
|
59
|
+
true
|
60
|
+
end
|
61
61
|
rescue StandardError, LoadError => e
|
62
62
|
logger.error('Error loading module track patch', e)
|
63
63
|
false
|
@@ -27,10 +27,7 @@ module Contrast
|
|
27
27
|
source,
|
28
28
|
Kernel,
|
29
29
|
nil,
|
30
|
-
source)
|
31
|
-
# Exec replaces the current process, if we occur in a forked process
|
32
|
-
# our appendage of this finding will not make it to TS
|
33
|
-
Contrast::Agent::AtExitHook.on_exit
|
30
|
+
[source])
|
34
31
|
end
|
35
32
|
|
36
33
|
private
|
@@ -54,7 +54,6 @@ module Contrast
|
|
54
54
|
class << self
|
55
55
|
def track_rb_fiber_yield fiber, _method, results
|
56
56
|
return unless ASSESS.enabled?
|
57
|
-
return unless Contrast::Utils::DuckUtils.trackable?(fiber)
|
58
57
|
|
59
58
|
# results will be nil if StopIteration was raised,
|
60
59
|
# otherwise an Array of the yielded arguments
|
@@ -62,11 +61,11 @@ module Contrast
|
|
62
61
|
|
63
62
|
with_contrast_scope do
|
64
63
|
results.each do |result|
|
65
|
-
|
66
|
-
next
|
64
|
+
result_properties = Contrast::Agent::Assess::Tracker.properties(result)
|
65
|
+
next unless result_properties
|
67
66
|
|
68
|
-
|
69
|
-
|
67
|
+
result_properties.splat_from(fiber, result)
|
68
|
+
result_properties.build_event(
|
70
69
|
FIBER_YIELD_NODE,
|
71
70
|
result,
|
72
71
|
fiber,
|
@@ -80,13 +79,14 @@ module Contrast
|
|
80
79
|
|
81
80
|
def track_rb_fiber_new fiber, _enum, _enum_method, underlying, _underlying_method
|
82
81
|
return unless ASSESS.enabled?
|
83
|
-
return unless Contrast::Utils::DuckUtils.trackable?(fiber)
|
84
|
-
return unless Contrast::Utils::DuckUtils.trackable?(underlying)
|
85
82
|
return unless underlying.is_a?(String) && !underlying.empty?
|
86
83
|
|
87
84
|
with_contrast_scope do
|
88
|
-
|
89
|
-
|
85
|
+
properties = Contrast::Agent::Assess::Tracker.properties(fiber)
|
86
|
+
return unless properties
|
87
|
+
|
88
|
+
properties.splat_from(underlying, fiber)
|
89
|
+
properties.build_event(
|
90
90
|
FIBER_NEW_NODE,
|
91
91
|
fiber,
|
92
92
|
underlying,
|
@@ -99,9 +99,9 @@ module Contrast
|
|
99
99
|
|
100
100
|
def instrument_fiber_track
|
101
101
|
@_instrument_fiber_variables ||= begin
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
require 'cs__assess_fiber_track/cs__assess_fiber_track' if Funchook.available?
|
103
|
+
true
|
104
|
+
end
|
105
105
|
rescue StandardError, LoadError => e
|
106
106
|
logger.error('Error loading fiber track patch', e)
|
107
107
|
false
|
@@ -15,10 +15,9 @@ module Contrast
|
|
15
15
|
class << self
|
16
16
|
def cs__duplicate_and_freeze object
|
17
17
|
return object unless object.is_a?(String) && !object.cs__frozen?
|
18
|
-
return object unless
|
18
|
+
return object unless Contrast::Agent::Assess::Tracker.tracked?(object)
|
19
19
|
|
20
|
-
ret = object
|
21
|
-
object.cs__transfer_properties(ret)
|
20
|
+
ret = Contrast::Agent::Assess::Tracker.duplicate(object)
|
22
21
|
ret.cs__freeze
|
23
22
|
rescue StandardError
|
24
23
|
# we'll rescue this error, but we can't log it here as that will
|
@@ -27,9 +26,9 @@ module Contrast
|
|
27
26
|
|
28
27
|
def instrument_hash_track
|
29
28
|
@_instrument_hash_track ||= begin
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
require 'cs__assess_hash/cs__assess_hash'
|
30
|
+
true
|
31
|
+
end
|
33
32
|
rescue StandardError, LoadError => e
|
34
33
|
logger.error('Error loading hash track patch', e)
|
35
34
|
false
|
@@ -39,44 +39,47 @@ module Contrast
|
|
39
39
|
# oh, and there's also %<name>type and %{name}... b/c of course there is
|
40
40
|
# -HM
|
41
41
|
def sprintf_tagger patcher, preshift, ret, _block
|
42
|
+
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
43
|
+
return unless properties
|
44
|
+
|
42
45
|
format_string = preshift.args[0]
|
43
46
|
args = preshift.args[1]
|
44
47
|
|
45
|
-
|
48
|
+
parent_events = []
|
49
|
+
track_sprintf(ret, format_string, args, parent_events)
|
46
50
|
|
47
|
-
|
51
|
+
properties.build_event(
|
48
52
|
patcher,
|
49
53
|
ret,
|
50
54
|
preshift.object,
|
51
55
|
ret,
|
52
56
|
preshift.args,
|
53
57
|
1)
|
58
|
+
|
59
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
54
60
|
ret
|
55
61
|
end
|
56
62
|
|
57
|
-
def track_sprintf result, format_string, args
|
58
|
-
handle_sprintf_value(format_string, result)
|
63
|
+
def track_sprintf result, format_string, args, parent_events
|
64
|
+
handle_sprintf_value(format_string, result, parent_events)
|
59
65
|
case args
|
60
66
|
when String
|
61
|
-
handle_sprintf_value(args, result)
|
67
|
+
handle_sprintf_value(args, result, parent_events)
|
62
68
|
when Hash
|
63
|
-
handle_sprintf_hash(args, result)
|
69
|
+
handle_sprintf_hash(args, result, parent_events)
|
64
70
|
when Array
|
65
|
-
handle_sprintf_array
|
71
|
+
handle_sprintf_array(args, result, parent_events)
|
66
72
|
end
|
67
|
-
|
68
|
-
result
|
69
73
|
rescue StandardError => e
|
70
74
|
logger.error(
|
71
75
|
'Unable to track dataflow through sprintf', e)
|
72
|
-
result
|
73
76
|
end
|
74
77
|
|
75
78
|
def instrument_kernel_track
|
76
79
|
@_instrument_fiber_variables ||= begin
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
require 'cs__assess_kernel/cs__assess_kernel'
|
81
|
+
true
|
82
|
+
end
|
80
83
|
rescue StandardError, LoadError => e
|
81
84
|
logger.error('Error loading kernel track patch', e)
|
82
85
|
false
|
@@ -84,24 +87,26 @@ module Contrast
|
|
84
87
|
|
85
88
|
private
|
86
89
|
|
87
|
-
def handle_sprintf_value value, result
|
88
|
-
|
90
|
+
def handle_sprintf_value value, result, parent_events
|
91
|
+
properties = Contrast::Agent::Assess::Tracker.properties(result)
|
92
|
+
return unless properties
|
89
93
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
value_properties = Contrast::Agent::Assess::Tracker.properties(value)
|
95
|
+
return unless value_properties
|
96
|
+
|
97
|
+
parent_events << value_properties.event if value_properties.event
|
98
|
+
properties.splat_from(value, result)
|
94
99
|
end
|
95
100
|
|
96
|
-
def handle_sprintf_array args, result
|
101
|
+
def handle_sprintf_array args, result, parent_events
|
97
102
|
args.each do |value|
|
98
|
-
handle_sprintf_value(value, result)
|
103
|
+
handle_sprintf_value(value, result, parent_events)
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
102
|
-
def handle_sprintf_hash args, result
|
107
|
+
def handle_sprintf_hash args, result, parent_events
|
103
108
|
args.each_value do |value|
|
104
|
-
handle_sprintf_value(value, result)
|
109
|
+
handle_sprintf_value(value, result, parent_events)
|
105
110
|
end
|
106
111
|
end
|
107
112
|
end
|
@@ -22,8 +22,9 @@ module Contrast
|
|
22
22
|
|
23
23
|
# Since we know this is the source of the trigger, we can do some
|
24
24
|
# optimization here and return when it is not tracked
|
25
|
-
return unless Contrast::
|
25
|
+
return unless Contrast::Agent::Assess::Tracker.tracked?(source)
|
26
26
|
|
27
|
+
args = [source]
|
27
28
|
# source might not be all the args passed in, but it is the one we care
|
28
29
|
# about. we could pass in all the args in the last param here if it
|
29
30
|
# becomes an issue in rendering on TS
|
@@ -33,17 +34,21 @@ module Contrast
|
|
33
34
|
source,
|
34
35
|
self,
|
35
36
|
ret,
|
36
|
-
|
37
|
-
|
37
|
+
args)
|
38
|
+
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
39
|
+
properties.copy_from(source, ret)
|
40
|
+
|
41
|
+
node = Contrast::Agent::Assess::Policy::Policy.instance.find_propagator_node('Marshal', :load, false)
|
42
|
+
properties.build_event(node, ret, self, ret, args)
|
38
43
|
rescue StandardError => e
|
39
44
|
logger.error('Unable to determine if a trigger occurred in Marshal.load', e)
|
40
45
|
end
|
41
46
|
|
42
47
|
def instrument_marshal_load
|
43
48
|
@_instrument_marshal_load ||= begin
|
44
|
-
|
45
|
-
|
46
|
-
|
49
|
+
require 'cs__assess_marshal_module/cs__assess_marshal_module'
|
50
|
+
true
|
51
|
+
end
|
47
52
|
rescue StandardError, LoadError => e
|
48
53
|
logger.error('Error loading marshal load patch', e)
|
49
54
|
false
|
@@ -47,8 +47,6 @@ module Contrast
|
|
47
47
|
return if scope_for_current_ec.instance_variable_get(:@contrast_scope) > 1
|
48
48
|
|
49
49
|
target = info_hash[:back_ref]
|
50
|
-
return unless Contrast::Utils::DuckUtils.trackable?(target)
|
51
|
-
|
52
50
|
with_contrast_scope do
|
53
51
|
result = info_hash[:result]
|
54
52
|
return unless result
|
@@ -56,8 +54,11 @@ module Contrast
|
|
56
54
|
string = info_hash[:string]
|
57
55
|
return unless string
|
58
56
|
|
59
|
-
|
60
|
-
|
57
|
+
properties = Contrast::Agent::Assess::Tracker.properties(target)
|
58
|
+
return unless properties
|
59
|
+
|
60
|
+
properties.splat_from(string, target)
|
61
|
+
properties.build_event(
|
61
62
|
REGEXP_EQUAL_SQUIGGLE_NODE,
|
62
63
|
target,
|
63
64
|
self,
|
@@ -70,9 +71,9 @@ module Contrast
|
|
70
71
|
|
71
72
|
def instrument_regexp_track
|
72
73
|
@_instrument_regexp_track ||= begin
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
require 'cs__assess_regexp/cs__assess_regexp'
|
75
|
+
true
|
76
|
+
end
|
76
77
|
rescue StandardError, LoadError => e
|
77
78
|
logger.error('Error loading regexp track patch', e)
|
78
79
|
false
|
@@ -3,13 +3,6 @@
|
|
3
3
|
|
4
4
|
require 'contrast/agent/assess/policy/propagation_node'
|
5
5
|
require 'contrast/components/interface'
|
6
|
-
require 'contrast/extension/assess/assess_extension'
|
7
|
-
|
8
|
-
# This patch installs our extension as early as possible. The alternative is to
|
9
|
-
# litter our code with Contrast::Utils::DuckUtils.trackable? checks.
|
10
|
-
class String
|
11
|
-
include Contrast::Extension::Assess::AssessExtension
|
12
|
-
end
|
13
6
|
|
14
7
|
module Contrast
|
15
8
|
module Extension
|
@@ -40,23 +33,32 @@ module Contrast
|
|
40
33
|
def track_interpolation inputs, result
|
41
34
|
return unless AGENT.interpolation_enabled?
|
42
35
|
return if in_contrast_scope?
|
43
|
-
return unless inputs.any?(
|
36
|
+
return unless inputs.any? { |input| Contrast::Agent::Assess::Tracker.tracked?(input) }
|
44
37
|
|
45
38
|
with_contrast_scope do
|
39
|
+
properties = Contrast::Agent::Assess::Tracker.properties(result)
|
40
|
+
return unless properties
|
41
|
+
|
42
|
+
parent_events = []
|
46
43
|
offset = 0
|
47
44
|
inputs.each do |input|
|
48
|
-
|
45
|
+
properties.copy_from(input, result, offset)
|
49
46
|
offset += input.length
|
47
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(input)&.event
|
48
|
+
parent_events << parent_event if parent_event
|
50
49
|
end
|
51
|
-
|
50
|
+
properties.build_event(INTERPOLATION_NODE, result, inputs, result, inputs)
|
51
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
52
52
|
end
|
53
|
+
rescue StandardError => e
|
54
|
+
logger.error('Unable to track interpolation', e)
|
53
55
|
end
|
54
56
|
|
55
57
|
def instrument_string
|
56
58
|
@_instrument_string ||= begin
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
require 'cs__assess_string/cs__assess_string'
|
60
|
+
true
|
61
|
+
end
|
60
62
|
rescue StandardError, LoadError => e
|
61
63
|
logger.error('Error loading hash track patch', e)
|
62
64
|
false
|
@@ -65,14 +67,12 @@ module Contrast
|
|
65
67
|
def instrument_string_interpolation
|
66
68
|
if @_instrument_string_interpolation.nil?
|
67
69
|
@_instrument_string_interpolation = begin
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
false
|
75
|
-
end
|
70
|
+
require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26' if AGENT.patch_interpolation? && Funchook.available?
|
71
|
+
true
|
72
|
+
rescue StandardError, LoadError => e
|
73
|
+
logger.error('Error loading interpolation patch', e)
|
74
|
+
false
|
75
|
+
end
|
76
76
|
end
|
77
77
|
@_instrument_string_interpolation
|
78
78
|
end
|