contrast-agent 3.15.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +22 -10
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +4 -3
- data/lib/contrast/agent.rb +4 -12
- data/lib/contrast/agent/assess/contrast_event.rb +121 -130
- data/lib/contrast/agent/assess/contrast_object.rb +51 -0
- data/lib/contrast/agent/assess/events/source_event.rb +5 -10
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +4 -3
- data/lib/contrast/agent/assess/policy/policy_node.rb +46 -69
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -2
- data/lib/contrast/agent/assess/policy/preshift.rb +3 -3
- data/lib/contrast/agent/assess/policy/propagation_method.rb +13 -19
- data/lib/contrast/agent/assess/policy/propagation_node.rb +12 -24
- data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +2 -3
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -5
- data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +2 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +2 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +77 -122
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +32 -25
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -7
- data/lib/contrast/agent/assess/policy/source_method.rb +2 -14
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +9 -13
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +39 -14
- data/lib/contrast/agent/assess/policy/trigger_node.rb +31 -37
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +5 -18
- data/lib/contrast/agent/assess/property/tagged.rb +28 -16
- data/lib/contrast/agent/assess/property/updated.rb +0 -5
- 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/rule/redos.rb +1 -1
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +16 -18
- data/lib/contrast/agent/at_exit_hook.rb +5 -5
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +7 -0
- 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 +51 -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/method_policy.rb +1 -1
- 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/policy.rb +16 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +47 -1
- 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/policy/rule_applicator.rb +53 -0
- data/lib/contrast/agent/protect/rule/base.rb +63 -14
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -28
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -4
- data/lib/contrast/agent/protect/rule/deserialization.rb +4 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +3 -3
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
- data/lib/contrast/agent/protect/rule/xxe.rb +32 -11
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +10 -6
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- data/lib/contrast/agent/request.rb +34 -34
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +5 -5
- data/lib/contrast/agent/rewriter.rb +3 -3
- data/lib/contrast/agent/scope.rb +81 -55
- data/lib/contrast/agent/static_analysis.rb +15 -9
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- 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 +1 -1
- data/lib/contrast/api/decorators/library.rb +54 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +31 -0
- data/lib/contrast/api/decorators/message.rb +1 -0
- data/lib/contrast/api/decorators/trace_event.rb +31 -41
- data/lib/contrast/api/decorators/trace_event_object.rb +11 -3
- data/lib/contrast/api/decorators/trace_event_signature.rb +27 -5
- data/lib/contrast/api/decorators/user_input.rb +2 -1
- data/lib/contrast/common_agent_configuration.rb +2 -1
- data/lib/contrast/components/agent.rb +6 -5
- data/lib/contrast/components/app_context.rb +39 -30
- data/lib/contrast/components/assess.rb +36 -0
- data/lib/contrast/components/config.rb +29 -37
- data/lib/contrast/components/contrast_service.rb +9 -9
- data/lib/contrast/components/interface.rb +30 -6
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/scope.rb +72 -6
- data/lib/contrast/components/settings.rb +23 -23
- data/lib/contrast/config/assess_configuration.rb +2 -1
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/service_configuration.rb +4 -2
- data/lib/contrast/configuration.rb +1 -1
- data/lib/contrast/extension/assess/array.rb +9 -6
- data/lib/contrast/extension/assess/erb.rb +6 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
- data/lib/contrast/extension/assess/exec_trigger.rb +0 -3
- data/lib/contrast/extension/assess/fiber.rb +5 -6
- data/lib/contrast/extension/assess/hash.rb +7 -5
- data/lib/contrast/extension/assess/kernel.rb +19 -22
- data/lib/contrast/extension/assess/marshal.rb +40 -28
- data/lib/contrast/extension/assess/regexp.rb +6 -11
- data/lib/contrast/extension/assess/string.rb +14 -13
- data/lib/contrast/extension/protect/kernel.rb +3 -3
- data/lib/contrast/framework/base_support.rb +51 -53
- data/lib/contrast/framework/manager.rb +6 -5
- data/lib/contrast/framework/rack/patch/session_cookie.rb +10 -10
- data/lib/contrast/framework/rack/support.rb +2 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -14
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +13 -13
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +13 -13
- data/lib/contrast/framework/rails/support.rb +5 -1
- data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
- data/lib/contrast/framework/sinatra/support.rb +7 -6
- data/lib/contrast/logger/application.rb +1 -4
- data/lib/contrast/logger/log.rb +7 -2
- data/lib/contrast/utils/duck_utils.rb +1 -1
- data/lib/contrast/utils/heap_dump_util.rb +1 -1
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -5
- data/lib/contrast/utils/inventory_util.rb +0 -7
- data/lib/contrast/utils/object_share.rb +3 -3
- data/lib/contrast/utils/preflight_util.rb +1 -1
- data/lib/contrast/utils/prevent_serialization.rb +1 -1
- data/lib/contrast/utils/resource_loader.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -14
- data/lib/contrast/utils/string_utils.rb +1 -1
- data/lib/contrast/utils/tag_util.rb +9 -13
- data/resources/assess/policy.json +31 -12
- data/resources/deadzone/policy.json +156 -0
- data/resources/protect/policy.json +12 -0
- data/ruby-agent.gemspec +11 -6
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +91 -28
- data/lib/contrast/utils/boolean_util.rb +0 -30
- data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -55,23 +55,25 @@ module Contrast
|
|
55
55
|
APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules].cs__freeze
|
56
56
|
|
57
57
|
# Meta-define an accessor for each state attribute.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
|
59
|
+
PROTECT_STATE_ATTRS.each do |attr|
|
60
|
+
# TODO: RUBY-1052
|
61
|
+
define_method(attr) do # rubocop:disable Performance/Kernel/DefineMethod
|
62
|
+
protect_state[attr]
|
63
63
|
end
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
ASSESS_STATE_ATTRS.each do |attr|
|
67
|
+
# TODO: RUBY-1052
|
68
|
+
define_method(attr) do # rubocop:disable Performance/Kernel/DefineMethod
|
69
|
+
assess_state[attr]
|
69
70
|
end
|
71
|
+
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
APPLICATION_STATE_ATTRS.each do |attr|
|
74
|
+
# TODO: RUBY-1052
|
75
|
+
define_method(attr) do # rubocop:disable Performance/Kernel/DefineMethod
|
76
|
+
application_state[attr]
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
@@ -95,18 +97,16 @@ module Contrast
|
|
95
97
|
|
96
98
|
def update_from_server_features server_features
|
97
99
|
# protect
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
100
|
+
|
101
|
+
@_protect_enabled = nil
|
102
|
+
protect_state[:enabled] = server_features.protect_enabled?
|
102
103
|
|
103
104
|
# assess
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
105
|
+
|
106
|
+
@_assess_enabled = nil
|
107
|
+
assess_state[:enabled] = server_features.assess_enabled?
|
108
|
+
assess_state[:sampling_settings] = server_features.assess.sampling
|
109
|
+
Contrast::Utils::Assess::SamplingUtil.instance.update
|
110
110
|
end
|
111
111
|
|
112
112
|
def update_from_application_settings application_settings
|
@@ -11,7 +11,8 @@ module Contrast
|
|
11
11
|
enable: EMPTY_VALUE,
|
12
12
|
enable_scan_response: Contrast::Config::DefaultValue.new('true'),
|
13
13
|
sampling: Contrast::Config::SamplingConfiguration,
|
14
|
-
rules: Contrast::Config::AssessRulesConfiguration
|
14
|
+
rules: Contrast::Config::AssessRulesConfiguration,
|
15
|
+
stacktraces: Contrast::Config::DefaultValue.new('ALL')
|
15
16
|
}.cs__freeze
|
16
17
|
|
17
18
|
def initialize hsh
|
@@ -7,8 +7,8 @@ module Contrast
|
|
7
7
|
# inventory functionality of the Agent.
|
8
8
|
class InventoryConfiguration < BaseConfiguration
|
9
9
|
KEYS = {
|
10
|
-
enable:
|
11
|
-
|
10
|
+
enable: Contrast::Config::DefaultValue.new(true),
|
11
|
+
analyze_libraries: Contrast::Config::DefaultValue.new(true),
|
12
12
|
tags: EMPTY_VALUE
|
13
13
|
}.cs__freeze
|
14
14
|
|
@@ -9,13 +9,15 @@ module Contrast
|
|
9
9
|
# Common Configuration settings. Those in this section pertain to the
|
10
10
|
# communication between the Agent & the Service.
|
11
11
|
class ServiceConfiguration < BaseConfiguration
|
12
|
+
# We don't set these b/c we've been asked to handle the default values of
|
13
|
+
# these settings differently, logging when we have to use them.
|
12
14
|
DEFAULT_HOST = '127.0.0.1'
|
13
15
|
DEFAULT_PORT = '30555'
|
14
16
|
|
15
17
|
KEYS = {
|
16
18
|
enable: EMPTY_VALUE,
|
17
|
-
host:
|
18
|
-
port:
|
19
|
+
host: EMPTY_VALUE,
|
20
|
+
port: EMPTY_VALUE,
|
19
21
|
socket: EMPTY_VALUE,
|
20
22
|
logger: Contrast::Config::LoggerConfiguration
|
21
23
|
}.cs__freeze
|
@@ -238,7 +238,7 @@ module Contrast
|
|
238
238
|
# @return [Hash, Object] the leaf of each
|
239
239
|
# Contrast::Config::BaseConfiguration will be returned in the N > 0 steps
|
240
240
|
# the Hash will be returned at the end of the 0 level
|
241
|
-
def convert_to_hash convert=root, hash={}
|
241
|
+
def convert_to_hash convert = root, hash = {}
|
242
242
|
case convert
|
243
243
|
when Contrast::Config::BaseConfiguration
|
244
244
|
convert.cs__class::KEYS.each_key do |key|
|
@@ -35,19 +35,21 @@ 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 ret 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
|
42
|
+
return ret unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
44
43
|
|
45
44
|
shift = 0
|
46
45
|
separator_length = separator.nil? ? 0 : separator.to_s.length
|
46
|
+
parent_events = []
|
47
47
|
ary.each do |obj|
|
48
48
|
if obj # skip nil here
|
49
49
|
properties.copy_from(obj, ret, shift)
|
50
50
|
shift += obj.to_s.length
|
51
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(obj)&.event
|
52
|
+
parent_events << parent_event if parent_event
|
51
53
|
end
|
52
54
|
shift += separator_length
|
53
55
|
end
|
@@ -60,15 +62,16 @@ module Contrast
|
|
60
62
|
ary,
|
61
63
|
ret,
|
62
64
|
[separator])
|
65
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
63
66
|
ret
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
67
70
|
def instrument_array_track
|
68
71
|
@_instrument_array_track ||= begin
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
require 'cs__assess_array/cs__assess_array'
|
73
|
+
true
|
74
|
+
end
|
72
75
|
rescue StandardError, LoadError => e
|
73
76
|
logger.error('Error loading assess track patch', e)
|
74
77
|
false
|
@@ -6,14 +6,13 @@ module ERBPropagator
|
|
6
6
|
class << self
|
7
7
|
def result_tagger patcher, preshift, ret, _block
|
8
8
|
return unless preshift.args.length >= 1
|
9
|
-
|
10
|
-
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
11
|
-
return unless properties
|
9
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
12
10
|
|
13
11
|
used_binding = preshift.args[0]
|
14
12
|
binding_variable_set = used_binding.local_variables
|
15
13
|
|
16
14
|
erb_pre_result = preshift.object.src
|
15
|
+
parent_events = []
|
17
16
|
binding_variable_set.each do |bound_var_symbol|
|
18
17
|
bound_variable_value = used_binding.local_variable_get(bound_var_symbol)
|
19
18
|
next unless Contrast::Agent::Assess::Tracker.tracked?(bound_variable_value)
|
@@ -23,6 +22,8 @@ module ERBPropagator
|
|
23
22
|
next if start_index.nil?
|
24
23
|
|
25
24
|
properties.copy_from(bound_variable_value, ret, start_index)
|
25
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(bound_variable_value)&.event
|
26
|
+
parent_events << parent_event if parent_event
|
26
27
|
end
|
27
28
|
properties.build_event(
|
28
29
|
patcher,
|
@@ -31,6 +32,8 @@ module ERBPropagator
|
|
31
32
|
ret,
|
32
33
|
preshift.args,
|
33
34
|
1)
|
35
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
36
|
+
|
34
37
|
ret
|
35
38
|
end
|
36
39
|
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
|
@@ -61,8 +61,7 @@ module Contrast
|
|
61
61
|
|
62
62
|
with_contrast_scope do
|
63
63
|
results.each do |result|
|
64
|
-
result_properties = Contrast::Agent::Assess::Tracker.properties(result)
|
65
|
-
next unless result_properties
|
64
|
+
next unless (result_properties = Contrast::Agent::Assess::Tracker.properties!(result))
|
66
65
|
|
67
66
|
result_properties.splat_from(fiber, result)
|
68
67
|
result_properties.build_event(
|
@@ -82,7 +81,7 @@ module Contrast
|
|
82
81
|
return unless underlying.is_a?(String) && !underlying.empty?
|
83
82
|
|
84
83
|
with_contrast_scope do
|
85
|
-
properties = Contrast::Agent::Assess::Tracker.properties(fiber)
|
84
|
+
properties = Contrast::Agent::Assess::Tracker.properties!(fiber)
|
86
85
|
return unless properties
|
87
86
|
|
88
87
|
properties.splat_from(underlying, fiber)
|
@@ -99,9 +98,9 @@ module Contrast
|
|
99
98
|
|
100
99
|
def instrument_fiber_track
|
101
100
|
@_instrument_fiber_variables ||= begin
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
require 'cs__assess_fiber_track/cs__assess_fiber_track' if Funchook.available?
|
102
|
+
true
|
103
|
+
end
|
105
104
|
rescue StandardError, LoadError => e
|
106
105
|
logger.error('Error loading fiber track patch', e)
|
107
106
|
false
|
@@ -17,18 +17,20 @@ module Contrast
|
|
17
17
|
return object unless object.is_a?(String) && !object.cs__frozen?
|
18
18
|
return object unless Contrast::Agent::Assess::Tracker.tracked?(object)
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# Copy the object, then freeze it, so that it looks the same
|
21
|
+
# externally, but will have our finalizer on it.
|
22
|
+
object.dup&.cs__freeze
|
22
23
|
rescue StandardError
|
23
24
|
# we'll rescue this error, but we can't log it here as that will
|
24
25
|
# result in a seg fault
|
26
|
+
object
|
25
27
|
end
|
26
28
|
|
27
29
|
def instrument_hash_track
|
28
30
|
@_instrument_hash_track ||= begin
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
require 'cs__assess_hash/cs__assess_hash'
|
32
|
+
true
|
33
|
+
end
|
32
34
|
rescue StandardError, LoadError => e
|
33
35
|
logger.error('Error loading hash track patch', e)
|
34
36
|
false
|
@@ -39,13 +39,13 @@ 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
|
42
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
44
43
|
|
45
44
|
format_string = preshift.args[0]
|
46
45
|
args = preshift.args[1]
|
47
46
|
|
48
|
-
|
47
|
+
parent_events = []
|
48
|
+
track_sprintf(ret, format_string, args, parent_events)
|
49
49
|
|
50
50
|
properties.build_event(
|
51
51
|
patcher,
|
@@ -54,32 +54,31 @@ module Contrast
|
|
54
54
|
ret,
|
55
55
|
preshift.args,
|
56
56
|
1)
|
57
|
+
|
58
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
57
59
|
ret
|
58
60
|
end
|
59
61
|
|
60
|
-
def track_sprintf result, format_string, args
|
61
|
-
handle_sprintf_value(format_string, result)
|
62
|
+
def track_sprintf result, format_string, args, parent_events
|
63
|
+
handle_sprintf_value(format_string, result, parent_events)
|
62
64
|
case args
|
63
65
|
when String
|
64
|
-
handle_sprintf_value(args, result)
|
66
|
+
handle_sprintf_value(args, result, parent_events)
|
65
67
|
when Hash
|
66
|
-
handle_sprintf_hash(args, result)
|
68
|
+
handle_sprintf_hash(args, result, parent_events)
|
67
69
|
when Array
|
68
|
-
handle_sprintf_array
|
70
|
+
handle_sprintf_array(args, result, parent_events)
|
69
71
|
end
|
70
|
-
|
71
|
-
result
|
72
72
|
rescue StandardError => e
|
73
73
|
logger.error(
|
74
74
|
'Unable to track dataflow through sprintf', e)
|
75
|
-
result
|
76
75
|
end
|
77
76
|
|
78
77
|
def instrument_kernel_track
|
79
78
|
@_instrument_fiber_variables ||= begin
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
require 'cs__assess_kernel/cs__assess_kernel'
|
80
|
+
true
|
81
|
+
end
|
83
82
|
rescue StandardError, LoadError => e
|
84
83
|
logger.error('Error loading kernel track patch', e)
|
85
84
|
false
|
@@ -87,28 +86,26 @@ module Contrast
|
|
87
86
|
|
88
87
|
private
|
89
88
|
|
90
|
-
def handle_sprintf_value value, result
|
89
|
+
def handle_sprintf_value value, result, parent_events
|
91
90
|
properties = Contrast::Agent::Assess::Tracker.properties(result)
|
92
91
|
return unless properties
|
93
92
|
|
94
93
|
value_properties = Contrast::Agent::Assess::Tracker.properties(value)
|
95
94
|
return unless value_properties
|
96
95
|
|
97
|
-
value_properties.
|
98
|
-
properties.events << event
|
99
|
-
end
|
96
|
+
parent_events << value_properties.event if value_properties.event
|
100
97
|
properties.splat_from(value, result)
|
101
98
|
end
|
102
99
|
|
103
|
-
def handle_sprintf_array args, result
|
100
|
+
def handle_sprintf_array args, result, parent_events
|
104
101
|
args.each do |value|
|
105
|
-
handle_sprintf_value(value, result)
|
102
|
+
handle_sprintf_value(value, result, parent_events)
|
106
103
|
end
|
107
104
|
end
|
108
105
|
|
109
|
-
def handle_sprintf_hash args, result
|
106
|
+
def handle_sprintf_hash args, result, parent_events
|
110
107
|
args.each_value do |value|
|
111
|
-
handle_sprintf_value(value, result)
|
108
|
+
handle_sprintf_value(value, result, parent_events)
|
112
109
|
end
|
113
110
|
end
|
114
111
|
end
|
@@ -6,45 +6,57 @@ require 'contrast/components/interface'
|
|
6
6
|
module Contrast
|
7
7
|
module Extension
|
8
8
|
module Assess
|
9
|
-
# This is our patch of the
|
9
|
+
# This is our patch of the Marshal class
|
10
10
|
# Disclaimer: there may be a better way, but we're in a 'get it work' state.
|
11
11
|
# Hopefully, we'll be in a 'get it right' state soon.
|
12
|
-
# This module is used for our Marshal
|
12
|
+
# This module is used for our Marshal.load patches
|
13
13
|
class MarshalPropagator
|
14
14
|
include Contrast::Components::Interface
|
15
15
|
|
16
|
-
access_component :logging
|
16
|
+
access_component :logging, :scope
|
17
17
|
|
18
18
|
class << self
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
19
|
+
def cs__load_protect arg
|
20
|
+
return if in_contrast_scope?
|
21
|
+
|
22
|
+
with_contrast_scope do
|
23
|
+
Contrast::Agent::Protect::Policy::AppliesDeserializationRule.prepended_invoke(arg)
|
24
|
+
end
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def cs__load_assess source, ret
|
29
|
+
with_contrast_scope do
|
30
|
+
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
31
|
+
return unless current_context
|
32
|
+
|
33
|
+
args = [source]
|
34
|
+
# source might not be all the args passed in, but it is the one we care
|
35
|
+
# about. we could pass in all the args in the last param here if it
|
36
|
+
# becomes an issue in rendering on TS
|
37
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
|
38
|
+
current_context,
|
39
|
+
trigger_node('Marshal', :load),
|
40
|
+
source,
|
41
|
+
self,
|
42
|
+
ret,
|
43
|
+
*args)
|
44
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
45
|
+
|
46
|
+
properties.copy_from(source, ret)
|
47
|
+
|
48
|
+
node = Contrast::Agent::Assess::Policy::Policy.instance.find_propagator_node('Marshal', :load, false)
|
49
|
+
properties.build_event(node, ret, self, ret, args)
|
50
|
+
rescue StandardError => e
|
51
|
+
logger.error('Unable to run Assess for Marshal.load', e)
|
52
|
+
end
|
41
53
|
end
|
42
54
|
|
43
55
|
def instrument_marshal_load
|
44
56
|
@_instrument_marshal_load ||= begin
|
45
|
-
|
46
|
-
|
47
|
-
|
57
|
+
require 'cs__assess_marshal_module/cs__assess_marshal_module'
|
58
|
+
true
|
59
|
+
end
|
48
60
|
rescue StandardError, LoadError => e
|
49
61
|
logger.error('Error loading marshal load patch', e)
|
50
62
|
false
|