contrast-agent 3.15.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +22 -10
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +4 -3
- data/lib/contrast/agent.rb +4 -12
- data/lib/contrast/agent/assess/contrast_event.rb +121 -130
- data/lib/contrast/agent/assess/contrast_object.rb +51 -0
- data/lib/contrast/agent/assess/events/source_event.rb +5 -10
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +4 -3
- data/lib/contrast/agent/assess/policy/policy_node.rb +46 -69
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -2
- data/lib/contrast/agent/assess/policy/preshift.rb +3 -3
- data/lib/contrast/agent/assess/policy/propagation_method.rb +13 -19
- data/lib/contrast/agent/assess/policy/propagation_node.rb +12 -24
- data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +2 -3
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -5
- data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +2 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +2 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +77 -122
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +32 -25
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -7
- data/lib/contrast/agent/assess/policy/source_method.rb +2 -14
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +9 -13
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +39 -14
- data/lib/contrast/agent/assess/policy/trigger_node.rb +31 -37
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +5 -18
- data/lib/contrast/agent/assess/property/tagged.rb +28 -16
- data/lib/contrast/agent/assess/property/updated.rb +0 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
- data/lib/contrast/agent/assess/rule/redos.rb +1 -1
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +16 -18
- data/lib/contrast/agent/at_exit_hook.rb +5 -5
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +7 -0
- data/lib/contrast/agent/inventory.rb +15 -0
- data/lib/contrast/agent/inventory/dependencies.rb +50 -0
- data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
- data/lib/contrast/agent/middleware.rb +51 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
- data/lib/contrast/agent/patching/policy/method_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
- data/lib/contrast/agent/patching/policy/patch.rb +6 -0
- data/lib/contrast/agent/patching/policy/policy.rb +16 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +47 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +53 -0
- data/lib/contrast/agent/protect/rule/base.rb +63 -14
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -28
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -4
- data/lib/contrast/agent/protect/rule/deserialization.rb +4 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +3 -3
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
- data/lib/contrast/agent/protect/rule/xxe.rb +32 -11
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +10 -6
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- data/lib/contrast/agent/request.rb +34 -34
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +5 -5
- data/lib/contrast/agent/rewriter.rb +3 -3
- data/lib/contrast/agent/scope.rb +81 -55
- data/lib/contrast/agent/static_analysis.rb +15 -9
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +36 -1
- data/lib/contrast/api/decorators.rb +3 -0
- data/lib/contrast/api/decorators/address.rb +13 -14
- data/lib/contrast/api/decorators/application_update.rb +1 -1
- data/lib/contrast/api/decorators/library.rb +54 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +31 -0
- data/lib/contrast/api/decorators/message.rb +1 -0
- data/lib/contrast/api/decorators/trace_event.rb +31 -41
- data/lib/contrast/api/decorators/trace_event_object.rb +11 -3
- data/lib/contrast/api/decorators/trace_event_signature.rb +27 -5
- data/lib/contrast/api/decorators/user_input.rb +2 -1
- data/lib/contrast/common_agent_configuration.rb +2 -1
- data/lib/contrast/components/agent.rb +6 -5
- data/lib/contrast/components/app_context.rb +39 -30
- data/lib/contrast/components/assess.rb +36 -0
- data/lib/contrast/components/config.rb +29 -37
- data/lib/contrast/components/contrast_service.rb +9 -9
- data/lib/contrast/components/interface.rb +30 -6
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/scope.rb +72 -6
- data/lib/contrast/components/settings.rb +23 -23
- data/lib/contrast/config/assess_configuration.rb +2 -1
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/service_configuration.rb +4 -2
- data/lib/contrast/configuration.rb +1 -1
- data/lib/contrast/extension/assess/array.rb +9 -6
- data/lib/contrast/extension/assess/erb.rb +6 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
- data/lib/contrast/extension/assess/exec_trigger.rb +0 -3
- data/lib/contrast/extension/assess/fiber.rb +5 -6
- data/lib/contrast/extension/assess/hash.rb +7 -5
- data/lib/contrast/extension/assess/kernel.rb +19 -22
- data/lib/contrast/extension/assess/marshal.rb +40 -28
- data/lib/contrast/extension/assess/regexp.rb +6 -11
- data/lib/contrast/extension/assess/string.rb +14 -13
- data/lib/contrast/extension/protect/kernel.rb +3 -3
- data/lib/contrast/framework/base_support.rb +51 -53
- data/lib/contrast/framework/manager.rb +6 -5
- data/lib/contrast/framework/rack/patch/session_cookie.rb +10 -10
- data/lib/contrast/framework/rack/support.rb +2 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -14
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +13 -13
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +13 -13
- data/lib/contrast/framework/rails/support.rb +5 -1
- data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
- data/lib/contrast/framework/sinatra/support.rb +7 -6
- data/lib/contrast/logger/application.rb +1 -4
- data/lib/contrast/logger/log.rb +7 -2
- data/lib/contrast/utils/duck_utils.rb +1 -1
- data/lib/contrast/utils/heap_dump_util.rb +1 -1
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -5
- data/lib/contrast/utils/inventory_util.rb +0 -7
- data/lib/contrast/utils/object_share.rb +3 -3
- data/lib/contrast/utils/preflight_util.rb +1 -1
- data/lib/contrast/utils/prevent_serialization.rb +1 -1
- data/lib/contrast/utils/resource_loader.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -14
- data/lib/contrast/utils/string_utils.rb +1 -1
- data/lib/contrast/utils/tag_util.rb +9 -13
- data/resources/assess/policy.json +31 -12
- data/resources/deadzone/policy.json +156 -0
- data/resources/protect/policy.json +12 -0
- data/ruby-agent.gemspec +11 -6
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +91 -28
- data/lib/contrast/utils/boolean_util.rb +0 -30
- data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/components/interface'
|
5
|
-
require 'contrast/
|
5
|
+
require 'contrast/agent/inventory'
|
6
6
|
require 'contrast/api/decorators/application_update'
|
7
7
|
|
8
8
|
module Contrast
|
@@ -17,14 +17,9 @@ module Contrast
|
|
17
17
|
# report the already-loaded gems.
|
18
18
|
def catchup
|
19
19
|
@_catchup ||= begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
rescue StandardError => e
|
27
|
-
logger.warn('Unable to run post-initialization static analysis', e)
|
20
|
+
threaded_analysis!
|
21
|
+
true
|
22
|
+
end
|
28
23
|
end
|
29
24
|
|
30
25
|
def send_inventory_message
|
@@ -35,6 +30,17 @@ module Contrast
|
|
35
30
|
Contrast::Utils::InventoryUtil.append_db_config(app_update_msg)
|
36
31
|
Contrast::Agent.messaging_queue.send_event_eventually(app_update_msg)
|
37
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def threaded_analysis!
|
37
|
+
Contrast::Agent::Thread.new do
|
38
|
+
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.catchup
|
39
|
+
send_inventory_message
|
40
|
+
rescue StandardError => e
|
41
|
+
logger.warn('Unable to run post-initialization static analysis', e)
|
42
|
+
end
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
@@ -35,7 +35,7 @@ module Contrast
|
|
35
35
|
path = tracepoint_event.path
|
36
36
|
return if path&.include?('contrast')
|
37
37
|
|
38
|
-
Contrast::
|
38
|
+
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.associate_file(path) if path
|
39
39
|
Contrast::Agent::Patching::Policy::Patcher.patch_specific_module(loaded_module)
|
40
40
|
Contrast::Agent::Assess::Policy::RewriterPatch.rewrite_interpolation(loaded_module)
|
41
41
|
Contrast::Agent::Assess::Policy::PolicyScanner.scan(tracepoint_event)
|
@@ -15,7 +15,7 @@ module Contrast
|
|
15
15
|
# service proxy and tracks the state of that proxy.
|
16
16
|
class SocketClient
|
17
17
|
include Contrast::Components::Interface
|
18
|
-
access_component :contrast_service, :logging
|
18
|
+
access_component :config, :contrast_service, :logging
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
@socket = init_connection
|
@@ -34,6 +34,7 @@ module Contrast
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def init_connection
|
37
|
+
log_connection
|
37
38
|
if CONTRAST_SERVICE.use_tcp?
|
38
39
|
Contrast::Api::Communication::TcpSocket.new(CONTRAST_SERVICE.host, CONTRAST_SERVICE.port)
|
39
40
|
else
|
@@ -41,6 +42,40 @@ module Contrast
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
45
|
+
def log_connection
|
46
|
+
# The socket is set,
|
47
|
+
if CONFIG.root.agent.service.socket
|
48
|
+
logger.info('Connecting to the Contrast Service using a UnixSocket socket',
|
49
|
+
socket: CONTRAST_SERVICE.socket_path)
|
50
|
+
return
|
51
|
+
end
|
52
|
+
# The host & port are set,
|
53
|
+
if CONFIG.root.agent.service.host && CONFIG.root.agent.service.port
|
54
|
+
logger.info('Connecting to the Contrast Service using a TCP socket',
|
55
|
+
host: CONTRAST_SERVICE.host,
|
56
|
+
port: CONTRAST_SERVICE.port)
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
# Or something is not set.
|
61
|
+
msg = if CONFIG.root.agent.service.host
|
62
|
+
'Missing a required connection value to the Contrast Service. ' \
|
63
|
+
'`agent.service.port` is not set. ' \
|
64
|
+
'Falling back to default TCP socket port.'
|
65
|
+
elsif CONFIG.root.agent.service.port
|
66
|
+
'Missing a required connection value to the Contrast Service. ' \
|
67
|
+
'`agent.service.host` is not set. ' \
|
68
|
+
'Falling back to default TCP socket host.'
|
69
|
+
else
|
70
|
+
'Missing a required connection value to the Contrast Service. ' \
|
71
|
+
'Neither `agent.service.socket` nor the pair of `agent.service.host` and `agent.service.port` are set. '\
|
72
|
+
'Falling back to default TCP socket.'
|
73
|
+
end
|
74
|
+
logger.warn(msg,
|
75
|
+
host: CONTRAST_SERVICE.host,
|
76
|
+
port: CONTRAST_SERVICE.port)
|
77
|
+
end
|
78
|
+
|
44
79
|
def send_message msg
|
45
80
|
return unless msg
|
46
81
|
|
@@ -8,11 +8,14 @@ module Contrast
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
11
12
|
require 'contrast/api/decorators/message'
|
12
13
|
require 'contrast/api/decorators/application_update'
|
13
14
|
require 'contrast/api/decorators/input_analysis'
|
14
15
|
require 'contrast/api/decorators/application_settings'
|
15
16
|
require 'contrast/api/decorators/server_features'
|
17
|
+
require 'contrast/api/decorators/library'
|
18
|
+
require 'contrast/api/decorators/library_usage_update'
|
16
19
|
require 'contrast/api/decorators/route_coverage'
|
17
20
|
require 'contrast/api/decorators/trace_event_object'
|
18
21
|
require 'contrast/api/decorators/trace_event_signature'
|
@@ -21,26 +21,25 @@ module Contrast
|
|
21
21
|
module ClassMethods
|
22
22
|
include Contrast::Components::Interface
|
23
23
|
access_component :logging
|
24
|
-
|
25
24
|
# receiver is memoized because it is the address/host/port of the server, once we
|
26
25
|
# resolve this for the first time, it shouldn't change
|
27
26
|
#
|
28
27
|
# @return [Contrast::Api::Dtm::Address] the address of this server
|
29
28
|
def build_receiver
|
30
29
|
@_build_receiver ||= begin
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
30
|
+
address = new
|
31
|
+
address.host = 'localhost'
|
32
|
+
address.ip = '127.0.0.1'
|
33
|
+
begin
|
34
|
+
Timeout.timeout(1) do
|
35
|
+
address.host = Contrast::Utils::StringUtils.force_utf8(Socket.gethostname)
|
36
|
+
address.ip = Contrast::Utils::StringUtils.force_utf8(Resolv.getaddress(address.host))
|
37
|
+
end
|
38
|
+
rescue StandardError => e
|
39
|
+
logger.warn('Unable to resolve host or ip', e, address: address)
|
40
|
+
end
|
41
|
+
address
|
42
|
+
end
|
44
43
|
end
|
45
44
|
|
46
45
|
# Parse out the sender of the Request and return it as an Address
|
@@ -44,7 +44,7 @@ module Contrast
|
|
44
44
|
msg = new
|
45
45
|
msg.append_route_coverage_data(Contrast::Agent.framework_manager.find_route_discovery_data)
|
46
46
|
msg.append_platform_version(Contrast::Agent.framework_manager.platform_version)
|
47
|
-
msg.append_library_update(Contrast::
|
47
|
+
msg.append_library_update(Contrast::Agent::Inventory::DependencyAnalysis.instance.library_pb_list)
|
48
48
|
msg
|
49
49
|
end
|
50
50
|
end
|
@@ -0,0 +1,54 @@
|
|
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/utils/string_utils'
|
5
|
+
require 'contrast/utils/sha256_builder'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Api
|
10
|
+
module Decorators
|
11
|
+
# Used to decorate the Library protobuf model to handle Gem::Specification translation
|
12
|
+
module Library
|
13
|
+
def self.included klass
|
14
|
+
klass.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Used to add class methods to the Library class on inclusion of the decorator
|
18
|
+
module ClassMethods
|
19
|
+
def build digest, gem_specification
|
20
|
+
msg = new
|
21
|
+
msg.file_path = Contrast::Utils::StringUtils.force_utf8(gem_specification.name)
|
22
|
+
msg.hash_code = Contrast::Utils::StringUtils.force_utf8(digest)
|
23
|
+
msg.version = Contrast::Utils::StringUtils.force_utf8(gem_specification.version)
|
24
|
+
msg.manifest = Contrast::Utils::StringUtils.force_utf8(build_manifest(gem_specification))
|
25
|
+
msg.external_ms = date_to_ms(gem_specification.date)
|
26
|
+
msg.internal_ms = msg.external_ms
|
27
|
+
msg.url = Contrast::Utils::StringUtils.force_utf8(gem_specification.homepage)
|
28
|
+
msg.class_count = file_count(gem_specification.full_gem_path.to_s)
|
29
|
+
msg.used_class_count = 0
|
30
|
+
msg
|
31
|
+
end
|
32
|
+
|
33
|
+
# These are all the code files that are located in the Gem directory loaded
|
34
|
+
# by the current environment; this includes more than Ruby files
|
35
|
+
def file_count path
|
36
|
+
Contrast::Utils::Sha256Builder.instance.files(path).length
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_manifest spec
|
40
|
+
Contrast::Utils::StringUtils.force_utf8(spec.to_yaml.to_s)
|
41
|
+
rescue StandardError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def date_to_ms date
|
46
|
+
(date.to_f * 1000.0).to_i
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Contrast::Api::Dtm::Library.include(Contrast::Api::Decorators::Library)
|
@@ -0,0 +1,31 @@
|
|
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/utils/string_utils'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Api
|
8
|
+
module Decorators
|
9
|
+
# Used to decorate the LibraryUsageUpdate protobuf
|
10
|
+
module LibraryUsageUpdate
|
11
|
+
def self.included klass
|
12
|
+
klass.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Used to add class methods to the LibraryUsageUpdate class on inclusion of the decorator
|
16
|
+
module ClassMethods
|
17
|
+
def build digest, files
|
18
|
+
msg = new
|
19
|
+
msg.hash_code = Contrast::Utils::StringUtils.force_utf8(digest)
|
20
|
+
files.each do |required_file|
|
21
|
+
msg.class_names[required_file] = true
|
22
|
+
end
|
23
|
+
msg
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Contrast::Api::Dtm::LibraryUsageUpdate.include(Contrast::Api::Decorators::LibraryUsageUpdate)
|
@@ -15,42 +15,45 @@ module Contrast
|
|
15
15
|
|
16
16
|
# Wrapper around build_event_object for the args array. Handles
|
17
17
|
# tainting the correct argument.
|
18
|
-
def build_event_args contrast_event, taint_target
|
18
|
+
def build_event_args! contrast_event, taint_target
|
19
19
|
contrast_event.args.each_index do |idx|
|
20
20
|
truncate_arg = taint_target != idx
|
21
21
|
event_arg = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.args[idx], truncate_arg)
|
22
22
|
args << event_arg
|
23
23
|
end
|
24
|
+
self
|
24
25
|
end
|
25
26
|
|
26
|
-
# TeamServer only supports one object's taint ranges at a time.
|
27
|
-
#
|
28
|
-
|
27
|
+
# TeamServer only supports one object's taint ranges at a time. We keep
|
28
|
+
# those tags on the event directly, so we just need to convert them to
|
29
|
+
# their DTM form in order to report this.
|
30
|
+
#
|
31
|
+
# @param contrast_event [Contrast::Agent::AssessContrastEvent]
|
32
|
+
def build_taint_ranges! contrast_event
|
29
33
|
# If there's no taint_target, this isn't a dataflow trace, but a
|
30
34
|
# trigger one
|
31
|
-
return
|
35
|
+
return self unless contrast_event&.tags
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if target.is_a?(Hash)
|
41
|
-
if contrast_event.policy_node&.targets&.any?
|
42
|
-
Contrast::Agent::Assess::Tracker.properties(target[contrast_event.policy_node.targets[0]])
|
43
|
-
else
|
44
|
-
Contrast::Agent::Assess::Tracker.properties(target[contrast_event.policy_node.sources[0]])
|
45
|
-
end
|
46
|
-
else
|
47
|
-
Contrast::Agent::Assess::Tracker.properties(target)
|
48
|
-
end
|
49
|
-
end
|
37
|
+
self.taint_ranges += Contrast::Api::Dtm::TraceTaintRange.build_for_event(contrast_event.tags)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_parent_ids! contrast_event
|
42
|
+
contrast_event&.parent_events&.each do |event|
|
43
|
+
next unless event
|
50
44
|
|
51
|
-
|
45
|
+
parent = Contrast::Api::Dtm::ParentObjectId.new
|
46
|
+
parent.id = event.event_id.to_i
|
47
|
+
parent_object_ids << parent
|
48
|
+
end
|
49
|
+
self
|
50
|
+
end
|
52
51
|
|
53
|
-
|
52
|
+
def build_stack! contrast_event
|
53
|
+
# We delayed doing this as long as possible b/c it's expensive
|
54
|
+
stack_dtms = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
|
55
|
+
self.stack += stack_dtms
|
56
|
+
self
|
54
57
|
end
|
55
58
|
|
56
59
|
# Class methods for TraceEvent
|
@@ -70,24 +73,11 @@ module Contrast
|
|
70
73
|
event_dtm.object = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.object, truncate_obj)
|
71
74
|
truncate_ret = Contrast::Utils::ObjectShare::RETURN_KEY != taint_target
|
72
75
|
event_dtm.ret = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.ret, truncate_ret)
|
73
|
-
event_dtm.build_event_args(contrast_event, taint_target)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
event_dtm.taint_ranges << range
|
78
|
-
end
|
79
|
-
|
80
|
-
# We delayed doing this as long as possible b/c it's expensive
|
81
|
-
stack = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
|
82
|
-
event_dtm.stack += stack
|
83
|
-
|
76
|
+
event_dtm.build_event_args!(contrast_event, taint_target)
|
77
|
+
event_dtm.build_parent_ids!(contrast_event)
|
78
|
+
event_dtm.build_taint_ranges!(contrast_event)
|
79
|
+
event_dtm.build_stack!(contrast_event)
|
84
80
|
event_dtm.object_id = contrast_event.event_id.to_i
|
85
|
-
contrast_event.parent_ids&.each do |id|
|
86
|
-
parent = Contrast::Api::Dtm::ParentObjectId.new
|
87
|
-
parent.id = id.to_i
|
88
|
-
event_dtm.parent_object_ids << parent
|
89
|
-
end
|
90
|
-
|
91
81
|
event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret, contrast_event.policy_node, contrast_event.args)
|
92
82
|
event_dtm
|
93
83
|
end
|
@@ -29,13 +29,21 @@ module Contrast
|
|
29
29
|
ELLIPSIS = '...'
|
30
30
|
UNTRUNCATED_PORTION_LENGTH = 25
|
31
31
|
TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + ELLIPSIS.length
|
32
|
-
|
32
|
+
|
33
|
+
# Convert the given Object into a Contrast::Api::Dtm::TraceEventObject
|
34
|
+
#
|
35
|
+
# @param contrast_object [Contrast::Agent::Assess::ContrastObject, nil]
|
36
|
+
# the thing to convert, if any
|
37
|
+
# @param truncate [Boolean] if the converted object can/should be
|
38
|
+
# truncated.
|
39
|
+
# @return [Contrast::Api::Dtm::TraceEventObject]
|
40
|
+
def build contrast_object, truncate
|
33
41
|
event_object = new
|
34
42
|
with_contrast_scope do
|
35
|
-
obj_string = Contrast::Utils::StringUtils.force_utf8(object)
|
43
|
+
obj_string = Contrast::Utils::StringUtils.force_utf8(contrast_object&.object)
|
36
44
|
obj_string = truncate(obj_string) if truncate && obj_string.length > TRUNCATION_LENGTH
|
37
45
|
event_object.value = Base64.encode64(obj_string)
|
38
|
-
event_object.tracked =
|
46
|
+
event_object.tracked = contrast_object&.tracked?
|
39
47
|
end
|
40
48
|
event_object
|
41
49
|
end
|
@@ -17,27 +17,49 @@ module Contrast
|
|
17
17
|
|
18
18
|
# Class methods for TraceEventSignature
|
19
19
|
module ClassMethods
|
20
|
+
# Convert the given composites into components that TeamServer can
|
21
|
+
# understand in order to build a representation of the method
|
22
|
+
# invoked.
|
23
|
+
#
|
24
|
+
# @param ret_obj [Contrast::Agent::Assess::ContrastObject, nil] the
|
25
|
+
# return value of the method call.
|
26
|
+
# @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode]
|
27
|
+
# the policy which pertains to the method invoked.
|
28
|
+
# @param args [Array<Contrast::Agent::Assess::ContrastObject>, nil]
|
29
|
+
# @return [Contrast::Api::Dtm::TraceEventSignature]
|
20
30
|
def build ret_obj, policy_node, args
|
21
31
|
signature = new
|
22
|
-
return_type =
|
23
|
-
signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
|
32
|
+
signature.return_type = Contrast::Utils::StringUtils.force_utf8(type_name(ret_obj))
|
24
33
|
signature.class_name = Contrast::Utils::StringUtils.force_utf8(policy_node.class_name)
|
25
34
|
signature.method_name = Contrast::Utils::StringUtils.force_utf8(policy_node.method_name)
|
26
35
|
if args
|
27
36
|
args&.each do |arg|
|
28
|
-
|
29
|
-
signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
|
37
|
+
signature.arg_types << Contrast::Utils::StringUtils.force_utf8(type_name(arg))
|
30
38
|
end
|
31
39
|
end
|
32
40
|
signature.constructor = policy_node.method_name == :new
|
33
41
|
# if there's a ret, then this method isn't nil. not 100% full proof since you can
|
34
42
|
# return nil, but this is the best we've got currently.
|
35
|
-
signature.void_method = ret_obj.nil?
|
43
|
+
signature.void_method = ret_obj.nil? || ret_obj.object.nil?
|
36
44
|
# 8 is STATIC in Java... we have to placate them for now
|
37
45
|
# it has been requested that flags be removed since it isn't used
|
38
46
|
signature.flags = 8 unless policy_node.instance_method?
|
39
47
|
signature
|
40
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# While Ruby signatures do not require neither a return type and can
|
53
|
+
# return anything depending on inputs, code paths, etc, nor constant
|
54
|
+
# parameter types, TeamServer was designed with strongly typed
|
55
|
+
# languages (Java) in mind, so we need types in our signatures.
|
56
|
+
#
|
57
|
+
# @param contrast_object [Contrast::Agent::Assess::ContrastObject, nil]
|
58
|
+
# the object to find the type of
|
59
|
+
# @return [String] the name of the module of the ret_obj, or `nil`
|
60
|
+
def type_name contrast_object
|
61
|
+
contrast_object ? contrast_object.object_type : Contrast::Utils::ObjectShare::NIL_STRING
|
62
|
+
end
|
41
63
|
end
|
42
64
|
end
|
43
65
|
end
|