contrast-agent 3.13.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/contrast_service +1 -7
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
- data/ext/cs__assess_array/cs__assess_array.c +6 -5
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_module/cs__assess_module.c +6 -6
- data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
- data/ext/cs__assess_string/cs__assess_string.c +31 -16
- data/ext/cs__assess_string/cs__assess_string.h +6 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
- data/ext/cs__common/cs__common.c +48 -39
- data/ext/cs__common/cs__common.h +16 -21
- data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
- data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
- data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +13 -23
- data/lib/contrast/agent.rb +39 -47
- data/lib/contrast/agent/assess.rb +12 -12
- data/lib/contrast/agent/assess/contrast_event.rb +151 -85
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +3 -3
- data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
- data/lib/contrast/agent/assess/policy/policy.rb +9 -11
- data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +21 -5
- data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- 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/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
- 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 +7 -9
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -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 +27 -22
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
- data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
- data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +15 -5
- data/lib/contrast/agent/assess/property/evented.rb +7 -20
- data/lib/contrast/agent/assess/property/tagged.rb +13 -7
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- data/lib/contrast/agent/assess/rule.rb +2 -2
- data/lib/contrast/agent/assess/rule/base.rb +3 -4
- data/lib/contrast/agent/assess/rule/provider.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +85 -16
- 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 +6 -6
- data/lib/contrast/agent/class_reopener.rb +14 -11
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +1 -1
- data/lib/contrast/agent/exclusion_matcher.rb +1 -1
- 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/inventory/policy/datastores.rb +2 -2
- data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +33 -34
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
- data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
- data/lib/contrast/agent/patching/policy/patch.rb +15 -15
- data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
- data/lib/contrast/agent/patching/policy/policy.rb +23 -12
- data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +7 -6
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +18 -18
- data/lib/contrast/agent/protect/rule/base.rb +4 -3
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
- data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
- data/lib/contrast/agent/railtie.rb +1 -1
- data/lib/contrast/agent/reaction_processor.rb +2 -2
- data/lib/contrast/agent/request.rb +45 -43
- data/lib/contrast/agent/request_context.rb +10 -6
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +23 -12
- data/lib/contrast/agent/rewriter.rb +6 -9
- data/lib/contrast/agent/service_heartbeat.rb +2 -2
- data/lib/contrast/agent/static_analysis.rb +9 -9
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +2 -2
- data/lib/contrast/agent/tracepoint_hook.rb +2 -2
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +4 -4
- data/lib/contrast/api/communication.rb +9 -9
- data/lib/contrast/api/communication/messaging_queue.rb +3 -6
- data/lib/contrast/api/communication/response_processor.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +41 -6
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/communication/tcp_socket.rb +1 -1
- data/lib/contrast/api/communication/unix_socket.rb +1 -1
- data/lib/contrast/api/decorators.rb +17 -14
- data/lib/contrast/api/decorators/address.rb +20 -20
- data/lib/contrast/api/decorators/application_settings.rb +3 -2
- data/lib/contrast/api/decorators/application_update.rb +7 -8
- data/lib/contrast/api/decorators/http_request.rb +13 -12
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- 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 +4 -2
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
- data/lib/contrast/api/decorators/route_coverage.rb +3 -2
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +28 -25
- data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
- data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
- data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
- data/lib/contrast/api/decorators/user_input.rb +4 -4
- data/lib/contrast/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +8 -7
- data/lib/contrast/components/app_context.rb +50 -39
- data/lib/contrast/components/config.rb +32 -50
- data/lib/contrast/components/contrast_service.rb +10 -10
- data/lib/contrast/components/interface.rb +39 -17
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/components/settings.rb +20 -23
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +93 -52
- data/lib/contrast/extension/assess.rb +21 -22
- data/lib/contrast/extension/assess/array.rb +18 -11
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
- data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
- data/lib/contrast/extension/assess/fiber.rb +14 -14
- data/lib/contrast/extension/assess/hash.rb +7 -6
- data/lib/contrast/extension/assess/kernel.rb +34 -28
- data/lib/contrast/extension/assess/marshal.rb +67 -0
- data/lib/contrast/extension/assess/regexp.rb +10 -9
- data/lib/contrast/extension/assess/string.rb +23 -23
- data/lib/contrast/extension/inventory.rb +4 -4
- data/lib/contrast/extension/kernel.rb +1 -1
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +3 -3
- data/lib/contrast/extension/protect/kernel.rb +4 -4
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +10 -11
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- data/lib/contrast/framework/rack/patch/support.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +2 -2
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
- data/lib/contrast/framework/rails/patch/support.rb +4 -4
- 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 +4 -4
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +67 -14
- data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +6 -6
- data/lib/contrast/funchook/funchook.rb +1 -1
- data/lib/contrast/logger/application.rb +13 -5
- data/lib/contrast/logger/format.rb +22 -9
- data/lib/contrast/logger/log.rb +17 -10
- data/lib/contrast/logger/request.rb +30 -0
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/sampling_util.rb +2 -2
- data/lib/contrast/utils/assess/tracking_util.rb +49 -4
- data/lib/contrast/utils/class_util.rb +2 -2
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/hash_digest.rb +2 -1
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
- data/lib/contrast/utils/inventory_util.rb +3 -10
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/os.rb +1 -1
- data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -14
- data/lib/contrast/utils/stack_trace_utils.rb +2 -2
- data/lib/contrast/utils/string_utils.rb +11 -6
- data/resources/assess/policy.json +31 -22
- data/resources/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +21 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +73 -30
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/extension/assess/assess_extension.rb +0 -147
- 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
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/agent/at_exit_hook'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Extension
|
@@ -27,7 +27,7 @@ module Contrast
|
|
27
27
|
source,
|
28
28
|
Kernel,
|
29
29
|
nil,
|
30
|
-
source)
|
30
|
+
[source])
|
31
31
|
# Exec replaces the current process, if we occur in a forked process
|
32
32
|
# our appendage of this finding will not make it to TS
|
33
33
|
Contrast::Agent::AtExitHook.on_exit
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
require 'contrast/components/interface'
|
6
6
|
|
7
7
|
# In order to instrument some difficult methods like String#gsub, as it
|
8
8
|
# returns an enumerator, we need to instrument methods on Fiber.
|
@@ -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
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Extension
|
@@ -15,9 +15,10 @@ 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
|
-
object
|
20
|
+
ret = Contrast::Agent::Assess::Tracker.duplicate(object)
|
21
|
+
ret.cs__freeze
|
21
22
|
rescue StandardError
|
22
23
|
# we'll rescue this error, but we can't log it here as that will
|
23
24
|
# result in a seg fault
|
@@ -25,9 +26,9 @@ module Contrast
|
|
25
26
|
|
26
27
|
def instrument_hash_track
|
27
28
|
@_instrument_hash_track ||= begin
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
require 'cs__assess_hash/cs__assess_hash'
|
30
|
+
true
|
31
|
+
end
|
31
32
|
rescue StandardError, LoadError => e
|
32
33
|
logger.error('Error loading hash track patch', e)
|
33
34
|
false
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
|
+
require 'contrast/extension/assess/exec_trigger'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Extension
|
@@ -39,43 +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)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def track_sprintf result, format_string, args, parent_events
|
64
|
+
handle_sprintf_value(format_string, result, parent_events)
|
65
|
+
case args
|
66
|
+
when String
|
67
|
+
handle_sprintf_value(args, result, parent_events)
|
68
|
+
when Hash
|
69
|
+
handle_sprintf_hash(args, result, parent_events)
|
70
|
+
when Array
|
71
|
+
handle_sprintf_array(args, result, parent_events)
|
65
72
|
end
|
66
|
-
|
67
|
-
result
|
68
73
|
rescue StandardError => e
|
69
74
|
logger.error(
|
70
75
|
'Unable to track dataflow through sprintf', e)
|
71
|
-
result
|
72
76
|
end
|
73
77
|
|
74
78
|
def instrument_kernel_track
|
75
79
|
@_instrument_fiber_variables ||= begin
|
76
|
-
|
77
|
-
|
78
|
-
|
80
|
+
require 'cs__assess_kernel/cs__assess_kernel'
|
81
|
+
true
|
82
|
+
end
|
79
83
|
rescue StandardError, LoadError => e
|
80
84
|
logger.error('Error loading kernel track patch', e)
|
81
85
|
false
|
@@ -83,24 +87,26 @@ module Contrast
|
|
83
87
|
|
84
88
|
private
|
85
89
|
|
86
|
-
def handle_sprintf_value value, result
|
87
|
-
|
90
|
+
def handle_sprintf_value value, result, parent_events
|
91
|
+
properties = Contrast::Agent::Assess::Tracker.properties(result)
|
92
|
+
return unless properties
|
88
93
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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)
|
93
99
|
end
|
94
100
|
|
95
|
-
def handle_sprintf_array args, result
|
101
|
+
def handle_sprintf_array args, result, parent_events
|
96
102
|
args.each do |value|
|
97
|
-
handle_sprintf_value(value, result)
|
103
|
+
handle_sprintf_value(value, result, parent_events)
|
98
104
|
end
|
99
105
|
end
|
100
106
|
|
101
|
-
def handle_sprintf_hash args, result
|
107
|
+
def handle_sprintf_hash args, result, parent_events
|
102
108
|
args.each_value do |value|
|
103
|
-
handle_sprintf_value(value, result)
|
109
|
+
handle_sprintf_value(value, result, parent_events)
|
104
110
|
end
|
105
111
|
end
|
106
112
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/components/interface'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Extension
|
8
|
+
module Assess
|
9
|
+
# This is our patch of the Array class required to handle propagation
|
10
|
+
# Disclaimer: there may be a better way, but we're in a 'get it work' state.
|
11
|
+
# Hopefully, we'll be in a 'get it right' state soon.
|
12
|
+
# This module is used for our Marshal#load patches
|
13
|
+
class MarshalPropagator
|
14
|
+
include Contrast::Components::Interface
|
15
|
+
|
16
|
+
access_component :logging
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def cs__load_trigger_check source, ret
|
20
|
+
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
21
|
+
return unless current_context
|
22
|
+
|
23
|
+
# Since we know this is the source of the trigger, we can do some
|
24
|
+
# optimization here and return when it is not tracked
|
25
|
+
return unless Contrast::Agent::Assess::Tracker.tracked?(source)
|
26
|
+
|
27
|
+
args = [source]
|
28
|
+
# source might not be all the args passed in, but it is the one we care
|
29
|
+
# about. we could pass in all the args in the last param here if it
|
30
|
+
# becomes an issue in rendering on TS
|
31
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
|
32
|
+
current_context,
|
33
|
+
trigger_node('Marshal', :load),
|
34
|
+
source,
|
35
|
+
self,
|
36
|
+
ret,
|
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)
|
43
|
+
rescue StandardError => e
|
44
|
+
logger.error('Unable to determine if a trigger occurred in Marshal.load', e)
|
45
|
+
end
|
46
|
+
|
47
|
+
def instrument_marshal_load
|
48
|
+
@_instrument_marshal_load ||= begin
|
49
|
+
require 'cs__assess_marshal_module/cs__assess_marshal_module'
|
50
|
+
true
|
51
|
+
end
|
52
|
+
rescue StandardError, LoadError => e
|
53
|
+
logger.error('Error loading marshal load patch', e)
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
def trigger_node clazz, method
|
58
|
+
triggers = Contrast::Agent::Assess::Policy::Policy.instance.triggers
|
59
|
+
return unless triggers
|
60
|
+
|
61
|
+
triggers.find { |node| node.class_name == clazz && node.method_name == method }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
require 'contrast/components/interface'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Extension
|
@@ -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
|
@@ -1,15 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
cs__scoped_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
|
4
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
require 'contrast/components/interface'
|
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
|
@@ -11,11 +11,11 @@ module Contrast
|
|
11
11
|
# relevant given the move to C based patching and the lessons learned
|
12
12
|
# therein.
|
13
13
|
module Inventory
|
14
|
-
|
14
|
+
require 'contrast/security_exception'
|
15
15
|
# patching
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
require 'contrast/agent/inventory/policy/trigger_node'
|
17
|
+
require 'contrast/agent/inventory/policy/policy'
|
18
|
+
require 'contrast/agent/patching/policy/patcher'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/components/scope'
|
5
5
|
|
6
6
|
# This is a reasonable place for the Kernel#catch hook to live.
|
7
7
|
# No current plans for component re-design, but if we had some kind of
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/utils/object_share'
|
5
5
|
|
6
6
|
# Some developers override various methods on Module, which can often involve
|
7
7
|
# changing expected method parity/behavior which in turn prevents us from being
|