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,11 +1,19 @@
|
|
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
|
+
require 'contrast/config/default_value'
|
5
|
+
require 'contrast/config/logger_configuration'
|
6
|
+
|
4
7
|
module Contrast
|
5
8
|
module Config
|
6
9
|
# Common Configuration settings. Those in this section pertain to the
|
7
10
|
# communication between the Agent & the Service.
|
8
11
|
class ServiceConfiguration < BaseConfiguration
|
12
|
+
# We don't set these b/c we've been asked to handle the default values of
|
13
|
+
# these settings differently, logging when we have to use them.
|
14
|
+
DEFAULT_HOST = '127.0.0.1'
|
15
|
+
DEFAULT_PORT = '30555'
|
16
|
+
|
9
17
|
KEYS = {
|
10
18
|
enable: EMPTY_VALUE,
|
11
19
|
host: EMPTY_VALUE,
|
@@ -1,12 +1,12 @@
|
|
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 'yaml'
|
5
|
+
require 'fileutils'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
require 'contrast/config'
|
8
|
+
require 'contrast/utils/object_share'
|
9
|
+
require 'contrast/components/interface'
|
10
10
|
|
11
11
|
module Contrast
|
12
12
|
# This is how we read in the local settings for the Agent, both ENV/ CMD line
|
@@ -24,8 +24,6 @@ module Contrast
|
|
24
24
|
attr_reader :default_name, :root
|
25
25
|
|
26
26
|
DEFAULT_YAML_PATH = 'contrast_security.yaml'
|
27
|
-
DEFAULT_HOST = '127.0.0.1'
|
28
|
-
DEFAULT_PORT = '30555'
|
29
27
|
MILLISECOND_MARKER = '_ms'
|
30
28
|
CONVERSION = {
|
31
29
|
'agent.service.enable' => 'agent.start_bundled_service'
|
@@ -37,9 +35,6 @@ module Contrast
|
|
37
35
|
'/etc/contrast/',
|
38
36
|
'/etc/'
|
39
37
|
].cs__freeze
|
40
|
-
REMOVE_FIELDS = [
|
41
|
-
'contrast'
|
42
|
-
].cs__freeze
|
43
38
|
|
44
39
|
def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH
|
45
40
|
@default_name = default_name
|
@@ -53,7 +48,6 @@ module Contrast
|
|
53
48
|
|
54
49
|
# Some in-flight rewrites to maintain backwards compatibility
|
55
50
|
config_kv = update_prop_keys(config_kv)
|
56
|
-
config_kv = deprecate_fields(config_kv)
|
57
51
|
|
58
52
|
@root = Contrast::Config::RootConfiguration.new(config_kv)
|
59
53
|
end
|
@@ -73,6 +67,13 @@ module Contrast
|
|
73
67
|
root&.cs__respond_to?(method_name) || super
|
74
68
|
end
|
75
69
|
|
70
|
+
# Get a loggable YAML format of this configuration
|
71
|
+
# @return [String] the current active configuration of the Agent,
|
72
|
+
# represented as a YAML string
|
73
|
+
def loggable
|
74
|
+
convert_to_hash.to_yaml
|
75
|
+
end
|
76
|
+
|
76
77
|
protected
|
77
78
|
|
78
79
|
# TODO: RUBY-546 move utility methods to auxiliary classes
|
@@ -80,26 +81,16 @@ module Contrast
|
|
80
81
|
def load_config
|
81
82
|
config = {}
|
82
83
|
configuration_paths.find do |path|
|
83
|
-
|
84
|
-
next unless found
|
84
|
+
next unless File.exist?(path)
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
puts "!!! Contrast - Configuration file at #{ path } is not readable by current user"
|
86
|
+
unless File.readable?(path)
|
87
|
+
log_file_read_error(path)
|
89
88
|
next
|
90
89
|
end
|
91
90
|
config = yaml_to_hash(path) || {}
|
92
91
|
break
|
93
92
|
end
|
94
93
|
|
95
|
-
if config.empty?
|
96
|
-
puts "!!! Contrast - working directory: #{ Dir.pwd }"
|
97
|
-
puts '!!! Contrast - valid configuration file could not be found at any of the search paths'
|
98
|
-
puts 'Valid configuration paths are: '
|
99
|
-
configuration_paths.each do |path|
|
100
|
-
puts(path)
|
101
|
-
end
|
102
|
-
end
|
103
94
|
config
|
104
95
|
end
|
105
96
|
|
@@ -109,9 +100,10 @@ module Contrast
|
|
109
100
|
yaml = IO.read(path)
|
110
101
|
yaml = ERB.new(yaml).result if defined?(ERB)
|
111
102
|
return YAML.safe_load(yaml)
|
103
|
+
rescue Psych::Exception => e
|
104
|
+
log_yaml_parse_error(path, e)
|
112
105
|
rescue RuntimeError => e
|
113
|
-
puts "
|
114
|
-
puts "ERROR: path=#{ path } pwd=#{ Dir.pwd }"
|
106
|
+
puts "WARN: Unable to load configuration. #{ e }; path: #{ path }, pwd: #{ Dir.pwd }"
|
115
107
|
end
|
116
108
|
end
|
117
109
|
|
@@ -122,29 +114,20 @@ module Contrast
|
|
122
114
|
# files to match the new agreed upon standard configuration
|
123
115
|
# names, so that one file works for all agents
|
124
116
|
def update_prop_keys config
|
125
|
-
converted = false
|
126
117
|
CONVERSION.each_pair do |old_method, new_method|
|
127
118
|
# See if the old value was set and needs to be translated
|
128
119
|
deprecated_keys = old_method.split('.')
|
129
|
-
|
130
120
|
old_value = config
|
131
121
|
deprecated_keys.each do |key|
|
132
122
|
old_value = old_value[key]
|
133
123
|
break if old_value.nil?
|
134
124
|
end
|
125
|
+
next if old_value.nil? # have to account for literal false
|
135
126
|
|
136
|
-
|
137
|
-
|
138
|
-
converted = true
|
139
|
-
|
140
|
-
puts "The deprecated property #{ old_method } is being set."
|
141
|
-
puts "Please update your config to use the property #{ new_method } instead."
|
142
|
-
|
127
|
+
log_deprecated_property(old_method, new_method)
|
143
128
|
new_keys = new_method.split('.')
|
144
|
-
|
145
129
|
# We changed the seconds values into ms values. Multiply them accordingly
|
146
130
|
old_value = old_value.to_i * 1000 if new_method.end_with?(MILLISECOND_MARKER)
|
147
|
-
|
148
131
|
new_value = config
|
149
132
|
end_idx = new_keys.length - 1
|
150
133
|
new_keys.each_with_index do |new_key, index|
|
@@ -161,21 +144,6 @@ module Contrast
|
|
161
144
|
config
|
162
145
|
end
|
163
146
|
|
164
|
-
def deprecate_fields hash
|
165
|
-
REMOVE_FIELDS.each do |field|
|
166
|
-
path = field.split('.')
|
167
|
-
active_path = hash
|
168
|
-
path.each_with_index do |delete_path, index|
|
169
|
-
if index == path.length - 1 && active_path
|
170
|
-
active_path.delete(delete_path)
|
171
|
-
elsif active_path
|
172
|
-
active_path = active_path[delete_path]
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
hash
|
177
|
-
end
|
178
|
-
|
179
147
|
# Base paths to check for the contrast configuration file, sorted by
|
180
148
|
# reverse order of precedence (first is most important).
|
181
149
|
def configuration_paths
|
@@ -208,5 +176,78 @@ module Contrast
|
|
208
176
|
end
|
209
177
|
new_hash
|
210
178
|
end
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
# We cannot use all access components at this point, unfortunately, as they
|
183
|
+
# may not have been initialized. Instead, we need to access the logger
|
184
|
+
# directly.
|
185
|
+
def logger
|
186
|
+
@_logger ||= (Contrast::Logger::Log.instance.logger if defined?(Contrast::Logger::Log))
|
187
|
+
end
|
188
|
+
|
189
|
+
# When we fail to parse a configuration because it is misformatted, log an
|
190
|
+
# appropriate message based on the Agent Onboarding specification
|
191
|
+
def log_yaml_parse_error path, exception
|
192
|
+
hash = {
|
193
|
+
path: path,
|
194
|
+
pwd: Dir.pwd
|
195
|
+
}
|
196
|
+
if exception.is_a?(Psych::SyntaxError)
|
197
|
+
hash[:context] = exception.context
|
198
|
+
hash[:column] = exception.column
|
199
|
+
hash[:line] = exception.line
|
200
|
+
hash[:offset] = exception.offset
|
201
|
+
hash[:problem] = exception.problem
|
202
|
+
end
|
203
|
+
|
204
|
+
if logger
|
205
|
+
logger.warn('YAML validator found an error', hash)
|
206
|
+
else
|
207
|
+
puts "CONTRAST - WARN: YAML validator found an error. #{ hash.inspect }"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def log_file_read_error path
|
212
|
+
if logger
|
213
|
+
logger.warn('Configuration file is not readable by current user', path: path)
|
214
|
+
else
|
215
|
+
puts "CONTRAST - WARN: Configuration file is not readable by current user; path: #{ path }"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def log_deprecated_property old_method, new_method
|
220
|
+
if logger
|
221
|
+
logger.warn('Deprecated property in use', old_method: old_method, new_method: new_method)
|
222
|
+
else
|
223
|
+
puts "CONTRAST - WARN: Deprecated property in use; old_method: #{ old_method }, new_method: #{ new_method }"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Convert this entire configuration into a hash, walking down the entries
|
228
|
+
# in the thing to convert and setting them in the given hash. For now, this
|
229
|
+
# logs every possible key, whether set or not. If we want to change that
|
230
|
+
# behavior, we can skip adding keys to the hash if the value is nil, blank,
|
231
|
+
# or Contrast::Config::DefaultValue depending on desired behavior
|
232
|
+
#
|
233
|
+
# @param hash [Hash] the hash to populate
|
234
|
+
# @param convert [Contrast::Config::BaseConfiguration, Object] the level of
|
235
|
+
# configuration from which to convert. Note that at least one top level
|
236
|
+
# Contrast::Config::BaseConfiguration is required for anything to be set
|
237
|
+
# in the hash
|
238
|
+
# @return [Hash, Object] the leaf of each
|
239
|
+
# Contrast::Config::BaseConfiguration will be returned in the N > 0 steps
|
240
|
+
# the Hash will be returned at the end of the 0 level
|
241
|
+
def convert_to_hash convert = root, hash = {}
|
242
|
+
case convert
|
243
|
+
when Contrast::Config::BaseConfiguration
|
244
|
+
convert.cs__class::KEYS.each_key do |key|
|
245
|
+
hash[key] = convert_to_hash(convert.send(key), {})
|
246
|
+
end
|
247
|
+
hash
|
248
|
+
else
|
249
|
+
convert
|
250
|
+
end
|
251
|
+
end
|
211
252
|
end
|
212
253
|
end
|
@@ -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
|