contrast-agent 3.13.0 → 3.16.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 -46
- 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 +9 -4
- 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 +84 -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/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 +32 -32
- 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 +3 -3
- 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/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 +1 -1
- 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 +14 -14
- data/lib/contrast/api/decorators/address.rb +20 -19
- 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/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 +2 -2
- data/lib/contrast/components/app_context.rb +50 -39
- data/lib/contrast/components/config.rb +7 -17
- data/lib/contrast/components/contrast_service.rb +10 -10
- data/lib/contrast/components/interface.rb +15 -15
- 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/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 +64 -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/boolean_util.rb +1 -1
- 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/gemfile_reader.rb +5 -5
- 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 +4 -4
- 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 -2
- 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 +67 -29
- 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/freeze_util.rb +0 -32
@@ -12,37 +12,36 @@ module Contrast
|
|
12
12
|
# therein.
|
13
13
|
# Removing it requires a C refactor to handle the namespace.
|
14
14
|
module Assess
|
15
|
-
|
15
|
+
require 'contrast/agent/patching/policy/patcher'
|
16
16
|
|
17
|
-
|
17
|
+
require 'contrast/utils/tag_util'
|
18
18
|
|
19
19
|
# provider rules - have to come before policy
|
20
|
-
|
20
|
+
require 'contrast/agent/assess/rule/provider'
|
21
21
|
|
22
22
|
# tagging / dataflow
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
require 'contrast/agent/assess/policy/policy_node'
|
24
|
+
require 'contrast/agent/assess/policy/source_node'
|
25
|
+
require 'contrast/agent/assess/policy/source_method'
|
26
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
27
|
+
require 'contrast/agent/assess/policy/propagation_method'
|
28
|
+
require 'contrast/agent/assess/policy/trigger_node'
|
29
|
+
require 'contrast/agent/assess/policy/trigger_method'
|
30
|
+
require 'contrast/agent/assess/policy/policy'
|
31
|
+
require 'contrast/agent/assess/policy/patcher'
|
32
32
|
|
33
|
-
# classes that don't play nice w/ our standard propagation
|
34
|
-
cs__scoped_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'
|
38
36
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
require 'contrast/extension/assess/array'
|
38
|
+
require 'contrast/extension/assess/erb'
|
39
|
+
require 'contrast/extension/assess/eval_trigger'
|
40
|
+
require 'contrast/extension/assess/fiber'
|
41
|
+
require 'contrast/extension/assess/hash'
|
42
|
+
require 'contrast/extension/assess/kernel'
|
43
|
+
require 'contrast/extension/assess/regexp'
|
44
|
+
require 'contrast/extension/assess/marshal'
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -1,9 +1,9 @@
|
|
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
|
-
|
4
|
+
require 'contrast/agent/patching/policy/patch'
|
5
|
+
require 'contrast/agent/patching/policy/patcher'
|
6
|
+
require 'contrast/components/interface'
|
7
7
|
|
8
8
|
module Contrast
|
9
9
|
module Extension
|
@@ -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
|
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
|
@@ -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
|
@@ -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
|
@@ -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
|