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
data/lib/contrast/agent.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
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 'English'
|
5
5
|
|
6
6
|
# This must precede other Contrast C extensions
|
7
|
-
|
7
|
+
require 'cs__common/cs__common'
|
8
8
|
# This must precede any patching we do as we log patches and we shouldn't cause
|
9
9
|
# requires to happen during that process.
|
10
|
-
|
10
|
+
require 'contrast/components/logger'
|
11
11
|
|
12
12
|
# defining instrumentation, this must precede core extensions
|
13
13
|
# because they need to register their patches
|
14
|
-
|
15
|
-
|
14
|
+
require 'contrast/agent/patching/policy/patcher'
|
15
|
+
require 'contrast/agent/patching/policy/patch'
|
16
16
|
|
17
17
|
# core extensions
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
require 'contrast/extension/assess'
|
19
|
+
require 'contrast/extension/delegator'
|
20
|
+
require 'contrast/extension/inventory'
|
21
|
+
require 'contrast/extension/module'
|
22
|
+
require 'contrast/extension/protect'
|
23
|
+
require 'contrast/extension/protect/kernel'
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
require 'contrast/utils/object_share'
|
26
|
+
require 'contrast/utils/boolean_util'
|
27
|
+
require 'contrast/utils/string_utils'
|
28
|
+
require 'contrast/utils/io_util'
|
29
|
+
require 'contrast/utils/os'
|
30
30
|
|
31
|
-
|
31
|
+
require 'contrast/common_agent_configuration'
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
require 'contrast/utils/hash_digest'
|
34
|
+
require 'contrast/utils/invalid_configuration_util'
|
35
35
|
|
36
36
|
# scoping
|
37
|
-
|
37
|
+
require 'contrast/agent/scope'
|
38
38
|
|
39
|
-
|
39
|
+
require 'contrast/utils/thread_tracker'
|
40
40
|
|
41
41
|
# Framework support
|
42
|
-
|
42
|
+
require 'contrast/framework/manager'
|
43
43
|
|
44
44
|
# Communication to SR
|
45
|
-
|
45
|
+
require 'contrast/api/communication'
|
46
46
|
|
47
|
-
|
47
|
+
require 'contrast/agent/thread_watcher'
|
48
48
|
|
49
49
|
module Contrast
|
50
50
|
# Top namespace of the Agent section. Holds tracking contexts that will be
|
@@ -67,39 +67,32 @@ module Contrast
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
require 'contrast/api'
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
require 'contrast/utils/resource_loader'
|
73
|
+
require 'contrast/utils/duck_utils'
|
74
|
+
require 'contrast/agent/tracepoint_hook'
|
75
|
+
require 'contrast/agent/at_exit_hook'
|
76
76
|
|
77
77
|
# communication with contrast service
|
78
|
-
|
78
|
+
require 'contrast/agent/exclusion_matcher'
|
79
79
|
|
80
80
|
# threads that handle contrast scope
|
81
|
-
|
81
|
+
require 'contrast/agent/thread'
|
82
82
|
|
83
83
|
# keep track of attacks
|
84
|
-
|
84
|
+
require 'contrast/agent/request_context'
|
85
85
|
|
86
|
-
|
86
|
+
require 'contrast/agent/assess'
|
87
87
|
|
88
88
|
# protect rules
|
89
|
-
|
89
|
+
require 'contrast/agent/protect/rule'
|
90
90
|
|
91
91
|
# application libraries
|
92
|
-
|
92
|
+
require 'contrast/utils/gemfile_reader'
|
93
93
|
|
94
94
|
# rack event monitoring
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
|
99
|
-
# Contrast::Framework::Manager.before_load_patches!
|
100
|
-
if defined?(::Rails)
|
101
|
-
cs__scoped_require 'contrast/framework/rails/patch/support'
|
102
|
-
cs__scoped_require 'contrast/framework/rails/patch/rails_application_configuration'
|
103
|
-
Contrast::Framework::Rails::Patch::RailsApplicationConfiguration.instrument
|
104
|
-
cs__scoped_require 'contrast/agent/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
|
105
|
-
end
|
95
|
+
require 'contrast/agent/middleware'
|
96
|
+
|
97
|
+
# Install the patches we need before the application has a chance to initialize
|
98
|
+
Contrast::Agent.framework_manager.before_load_patches!
|
@@ -8,27 +8,27 @@ module Contrast
|
|
8
8
|
# class under this namespace should be required here, providing a single
|
9
9
|
# point of require for this functionality.
|
10
10
|
module Assess
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
require 'contrast/agent/assess/tracker'
|
12
|
+
require 'contrast/agent/module_data'
|
13
|
+
require 'contrast/agent/rewriter'
|
14
|
+
require 'contrast/agent/assess/policy/preshift'
|
14
15
|
|
15
|
-
|
16
|
+
require 'contrast/utils/prevent_serialization'
|
16
17
|
|
17
18
|
# Rules - generic
|
18
|
-
|
19
|
-
|
19
|
+
require 'contrast/agent/assess/rule'
|
20
|
+
require 'contrast/agent/assess/rule/base'
|
20
21
|
|
21
22
|
# Dynamic Sources
|
22
|
-
|
23
|
+
require 'contrast/agent/assess/policy/dynamic_source_factory'
|
23
24
|
|
24
25
|
# Rule: REDOS
|
25
|
-
|
26
|
+
require 'contrast/agent/assess/rule/redos'
|
26
27
|
|
27
28
|
# reporting / tracking
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
cs__scoped_require 'contrast/agent/assess/events/event_factory'
|
29
|
+
require 'contrast/agent/assess/properties'
|
30
|
+
require 'contrast/agent/assess/tag'
|
31
|
+
require 'contrast/agent/assess/events/event_factory'
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -1,14 +1,14 @@
|
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
require 'contrast/utils/assess/tracking_util'
|
5
|
+
require 'contrast/utils/class_util'
|
6
|
+
require 'contrast/utils/duck_utils'
|
7
|
+
require 'contrast/utils/object_share'
|
8
|
+
require 'contrast/utils/prevent_serialization'
|
9
|
+
require 'contrast/utils/stack_trace_utils'
|
10
|
+
require 'contrast/utils/string_utils'
|
11
|
+
require 'contrast/utils/timer'
|
12
12
|
|
13
13
|
module Contrast
|
14
14
|
module Agent
|
@@ -16,10 +16,32 @@ module Contrast
|
|
16
16
|
# This class holds the data about an event in the application
|
17
17
|
# We'll use it to build an event that TeamServer can consume if
|
18
18
|
# the object to which this event belongs ends in a trigger.
|
19
|
+
#
|
20
|
+
# @attr_reader event_id [Integer] the atomic id of this event
|
21
|
+
# @attr_reader policy_node [Contrast::Agent::Assess::Policy::PolicyNode]
|
22
|
+
# the node that governs this event.
|
23
|
+
# @attr_reader stack_trace [Array<String>] the execution stack at the
|
24
|
+
# time the method for this event was invoked
|
25
|
+
# @attr_reader time [Integer] the time, in epoch ms, when this event was
|
26
|
+
# created
|
27
|
+
# @attr_reader thread [Integer] the object id of the thread on which this
|
28
|
+
# event was generated
|
29
|
+
# @attr_reader object [String] the safe representation of the Object on
|
30
|
+
# which the method was invoked
|
31
|
+
# @attr_reader ret [String] the safe representation of the Return of the
|
32
|
+
# invoked method
|
33
|
+
# @attr_reader args [Array<Object>] the safe representation of the
|
34
|
+
# Arguments with which the method was invoked
|
19
35
|
class ContrastEvent
|
20
36
|
include Contrast::Utils::PreventSerialization
|
21
37
|
|
22
38
|
class << self
|
39
|
+
# Given an array of arguments, copy them into a safe, meaning String,
|
40
|
+
# format that we can use to send to SR and TS for rendering.
|
41
|
+
#
|
42
|
+
# @param args [Array<Object>] the arguments to translate
|
43
|
+
# @return [Array<String>] the String forms of those Objects, as
|
44
|
+
# determined by Contrast::Utils::ClassUtil.to_contrast_string
|
23
45
|
def safe_args_representation args
|
24
46
|
return nil unless args
|
25
47
|
return Contrast::Utils::ObjectShare::EMPTY_ARRAY if args.empty?
|
@@ -36,30 +58,31 @@ module Contrast
|
|
36
58
|
rep
|
37
59
|
end
|
38
60
|
|
39
|
-
def safe_arg_hash_representation hash
|
40
|
-
# since this is the named hash for arguments, only the value is
|
41
|
-
# suspect here
|
42
|
-
hash.transform_values { |v| Contrast::Utils::ClassUtil.to_contrast_string(v) }
|
43
|
-
end
|
44
|
-
|
45
61
|
# if given an object that can be duped, duplicate it. otherwise just
|
46
62
|
# return the original object. swallow all exceptions from
|
47
63
|
# non-duplicable things.
|
48
64
|
#
|
49
65
|
# we can't just check respond_to? though b/c dup exists on the
|
50
66
|
# base Object class
|
67
|
+
#
|
68
|
+
# @param original [Object, nil] the thing to duplicate
|
69
|
+
# @return [Object, nil] a copy of that thing
|
51
70
|
def safe_dup original
|
52
71
|
return nil unless original
|
53
72
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
73
|
+
Contrast::Agent::Assess::Tracker.duplicate(original)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def safe_arg_hash_representation hash
|
79
|
+
# since this is the named hash for arguments, only the value is
|
80
|
+
# suspect here
|
81
|
+
hash.transform_values { |v| Contrast::Utils::ClassUtil.to_contrast_string(v) }
|
59
82
|
end
|
60
83
|
end
|
61
84
|
|
62
|
-
attr_reader :event_id, :
|
85
|
+
attr_reader :event_id, :policy_node, :stack_trace, :time, :thread, :object, :ret, :args
|
63
86
|
|
64
87
|
# We need this to track the parent id's of events to build up a flow
|
65
88
|
# chart of the finding
|
@@ -74,6 +97,13 @@ module Contrast
|
|
74
97
|
end
|
75
98
|
end
|
76
99
|
|
100
|
+
# @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode]
|
101
|
+
# the node that governs this event.
|
102
|
+
# @param tagged [Object] the Target to which this event pertains.
|
103
|
+
# @param object [Object] the Object on which the method was invoked
|
104
|
+
# @param ret [Object] the Return of the invoked method
|
105
|
+
# @param args [Array<Object>] the Arguments with which the method
|
106
|
+
# was invoked
|
77
107
|
def initialize policy_node, tagged, object, ret, args
|
78
108
|
@policy_node = policy_node
|
79
109
|
# so long as this event is built in a factory, we know Contrast Code
|
@@ -84,28 +114,110 @@ module Contrast
|
|
84
114
|
|
85
115
|
# These methods rely on the above being set. Don't move them!
|
86
116
|
@event_id = Contrast::Agent::Assess::ContrastEvent.next_atomic_id
|
87
|
-
|
88
|
-
snapshot(tagged, object, ret, args)
|
117
|
+
find_parent_events!(policy_node, object, ret, args)
|
118
|
+
snapshot!(tagged, object, ret, args)
|
119
|
+
end
|
120
|
+
|
121
|
+
def parent_events
|
122
|
+
@_parent_events ||= []
|
89
123
|
end
|
90
124
|
|
91
|
-
#
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
-
|
125
|
+
# We have to do a little work to figure out what our TS appropriate
|
126
|
+
# target is. To break this down, the logic is as follows:
|
127
|
+
# 1) If my policy_node has a target, work on targets. Else, work on sources.
|
128
|
+
# Per TS law, each policy_node must have at least a source or a target.
|
129
|
+
# The only type of policy_node w/o targets is a Trigger, but that may
|
130
|
+
# change.
|
131
|
+
# 2) If I have a highlight, it means that I have a P target that is
|
132
|
+
# not in integer form (it was a named / keyword type for which I had
|
133
|
+
# to find the index). I need to address this so that TS can process
|
134
|
+
# it.
|
135
|
+
# 3) I'll set the event's source and target to TS values.
|
136
|
+
# 4) Return the highlight or the first source/target as the taint
|
137
|
+
# target.
|
138
|
+
def determine_taint_target event_dtm
|
139
|
+
if @policy_node&.targets&.any?
|
140
|
+
event_dtm.source = @policy_node.source_string if @policy_node.source_string
|
141
|
+
event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
|
142
|
+
@highlight || @policy_node.targets[0]
|
143
|
+
elsif policy_node&.sources&.any?
|
144
|
+
event_dtm.source = @highlight ? "P#{ @highlight }" : @policy_node.source_string
|
145
|
+
event_dtm.target = @policy_node.target_string if @policy_node.target_string
|
146
|
+
@highlight || @policy_node.sources[0]
|
96
147
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
148
|
+
end
|
149
|
+
|
150
|
+
# Convert this event into a DTM that TeamServer can consume
|
151
|
+
def to_dtm_event
|
152
|
+
Contrast::Api::Dtm::TraceEvent.build(self)
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
# Parent events are the events of all the sources of this event which
|
158
|
+
# were tracked prior to this event occurring. Depending on which, if
|
159
|
+
# any of the sources were tracked, there may be more than one parent.
|
160
|
+
#
|
161
|
+
# All events except for [Contrast::Agent::Assess::Events::SourceEvent]
|
162
|
+
# will have at least one parent.
|
163
|
+
#
|
164
|
+
# We set those events to this event's instance variables.
|
165
|
+
#
|
166
|
+
# @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode]
|
167
|
+
# the node that governs this event.
|
168
|
+
# @param object [Object] the Object on which the method was invoked
|
169
|
+
# @param ret [Object] the Return of the invoked method
|
170
|
+
# @param args [Array<Object>] the Arguments with which the method
|
171
|
+
# was invoked
|
172
|
+
def find_parent_events! policy_node, object, ret, args
|
173
|
+
policy_node.sources.each do |source_marker|
|
174
|
+
source = value_of_source(source_marker, object, ret, args)
|
175
|
+
next unless source
|
176
|
+
|
177
|
+
event = Contrast::Agent::Assess::Tracker.properties(source)&.event
|
178
|
+
parent_events << event if event
|
102
179
|
end
|
103
|
-
|
104
|
-
|
180
|
+
end
|
181
|
+
|
182
|
+
# @param source [String] the marker for the source type
|
183
|
+
# @param object [Object] the Object on which the method was invoked
|
184
|
+
# @param ret [Object] the Return of the invoked method
|
185
|
+
# @param args [Array<Object>] the Arguments with which the method
|
186
|
+
# was invoked
|
187
|
+
# @return [Object,nil] the literal value of the source indicated by the
|
188
|
+
# given marker
|
189
|
+
def value_of_source source, object, ret, args
|
190
|
+
case source
|
191
|
+
when Contrast::Utils::ObjectShare::OBJECT_KEY
|
192
|
+
object
|
193
|
+
when Contrast::Utils::ObjectShare::RETURN_KEY
|
194
|
+
ret
|
195
|
+
else
|
196
|
+
if source.is_a?(Integer)
|
197
|
+
args[source]
|
198
|
+
else
|
199
|
+
args.each do |search|
|
200
|
+
next unless search.is_a?(Hash)
|
201
|
+
|
202
|
+
s = search[source]
|
203
|
+
return s if s
|
204
|
+
end
|
205
|
+
end
|
105
206
|
end
|
106
207
|
end
|
107
208
|
|
108
|
-
|
209
|
+
# Everything* is mutable in Ruby. As such, to ensure we can accurately
|
210
|
+
# report the application state at the time of this method's invocation,
|
211
|
+
# we have to snapshot the given values, making safe representations of
|
212
|
+
# them for our later use. We set those safe values to this event's
|
213
|
+
# instance variables.
|
214
|
+
#
|
215
|
+
# @param tagged [Object] the Target to which this event pertains.
|
216
|
+
# @param object [Object] the Object on which the method was invoked
|
217
|
+
# @param ret [Object] the Return of the invoked method
|
218
|
+
# @param args [Array<Object>] the Arguments with which the method
|
219
|
+
# was invoked
|
220
|
+
def snapshot! tagged, object, ret, args
|
109
221
|
target = @policy_node.target
|
110
222
|
case target
|
111
223
|
# If the target is nil, this rule was violated simply by a method
|
@@ -139,6 +251,10 @@ module Contrast
|
|
139
251
|
# I know we're creating an extra string here since we replace the safe
|
140
252
|
# one w/ a dup, but good enough for now. Trying not to make this too
|
141
253
|
# complicated. - HM 8/8/19
|
254
|
+
#
|
255
|
+
# @param target [String,Integer] the marker for the target index
|
256
|
+
# @param tagged [Object] the actual Object that we're acting on which
|
257
|
+
# has tags
|
142
258
|
def save_target_arg target, tagged
|
143
259
|
return if @args.cs__frozen?
|
144
260
|
|
@@ -156,56 +272,6 @@ module Contrast
|
|
156
272
|
break
|
157
273
|
end
|
158
274
|
end
|
159
|
-
|
160
|
-
# We have to do a little work to figure out what our TS appropriate
|
161
|
-
# target is. To break this down, the logic is as follows:
|
162
|
-
# 1) If my policy_node has a target, work on targets. Else, work on sources.
|
163
|
-
# Per TS law, each policy_node must have at least a source or a target.
|
164
|
-
# The only type of policy_node w/o targets is a Trigger, but that may
|
165
|
-
# change.
|
166
|
-
# 2) If I have a highlight, it means that I have a P target that is
|
167
|
-
# not in integer form (it was a named / keyword type for which I had
|
168
|
-
# to find the index). I need to address this so that TS can process
|
169
|
-
# it.
|
170
|
-
# 3) I'll set the event's source and target to TS values.
|
171
|
-
# 4) Return the highlight or the first source/target as the taint
|
172
|
-
# target.
|
173
|
-
def determine_taint_target event_dtm
|
174
|
-
if @policy_node&.targets&.any?
|
175
|
-
event_dtm.source = @policy_node.source_string if @policy_node.source_string
|
176
|
-
event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
|
177
|
-
@highlight || @policy_node.targets[0]
|
178
|
-
elsif policy_node&.sources&.any?
|
179
|
-
event_dtm.source = @highlight ? "P#{ @highlight }" : @policy_node.source_string
|
180
|
-
event_dtm.target = @policy_node.target_string if @policy_node.target_string
|
181
|
-
@highlight || @policy_node.sources[0]
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def value_of_source source, object, ret, args
|
186
|
-
case source
|
187
|
-
when Contrast::Utils::ObjectShare::OBJECT_KEY
|
188
|
-
object
|
189
|
-
when Contrast::Utils::ObjectShare::RETURN_KEY
|
190
|
-
ret
|
191
|
-
else
|
192
|
-
if source.is_a?(Integer)
|
193
|
-
args[source]
|
194
|
-
else
|
195
|
-
args.each do |search|
|
196
|
-
next unless search.is_a?(Hash)
|
197
|
-
|
198
|
-
s = search[source]
|
199
|
-
return s if s
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# Convert this event into a DTM that TeamServer can consume
|
206
|
-
def to_dtm_event
|
207
|
-
Contrast::Api::Dtm::TraceEvent.build(self)
|
208
|
-
end
|
209
275
|
end
|
210
276
|
end
|
211
277
|
end
|