contrast-agent 3.11.0 → 3.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +0 -1
- data/.flayignore +1 -0
- data/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/ext/build_funchook.rb +0 -2
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +7 -2
- data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
- data/ext/cs__assess_array/cs__assess_array.c +2 -1
- data/ext/cs__assess_array/cs__assess_array.h +1 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +3 -7
- data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -8
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
- data/ext/cs__assess_module/cs__assess_module.c +5 -7
- data/ext/cs__assess_module/cs__assess_module.h +3 -0
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -6
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -5
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +25 -1
- data/ext/cs__common/cs__common.h +3 -0
- data/ext/cs__common/extconf.rb +0 -14
- data/ext/cs__protect_kernel/cs__protect_kernel.c +4 -2
- data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
- data/ext/extconf_common.rb +0 -28
- data/lib/contrast.rb +3 -2
- data/lib/contrast/agent.rb +33 -24
- data/lib/contrast/agent/assess.rb +0 -9
- data/lib/contrast/agent/assess/contrast_event.rb +28 -167
- data/lib/contrast/agent/assess/events/source_event.rb +3 -7
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +4 -2
- data/lib/contrast/agent/assess/policy/propagation_node.rb +5 -1
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- 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 +1 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +9 -1
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/split.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
- data/lib/contrast/agent/assess/policy/source_method.rb +1 -2
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
- data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -14
- data/lib/contrast/agent/assess/policy/trigger_node.rb +20 -5
- data/lib/contrast/agent/assess/properties.rb +4 -382
- data/lib/contrast/agent/assess/property/evented.rb +78 -0
- data/lib/contrast/agent/assess/property/tagged.rb +339 -0
- data/lib/contrast/agent/assess/rule/base.rb +0 -15
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +5 -6
- data/lib/contrast/agent/assess/rule/redos.rb +0 -1
- data/lib/contrast/agent/assess/tag.rb +27 -12
- data/lib/contrast/agent/at_exit_hook.rb +4 -2
- data/lib/contrast/agent/class_reopener.rb +9 -4
- data/lib/contrast/agent/exclusion_matcher.rb +2 -3
- data/lib/contrast/agent/inventory/policy/datastores.rb +53 -0
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +36 -44
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +11 -2
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +51 -56
- data/lib/contrast/agent/patching/policy/patch.rb +3 -2
- data/lib/contrast/agent/patching/policy/patcher.rb +10 -12
- data/lib/contrast/agent/patching/policy/policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
- data/lib/contrast/agent/protect/policy/policy.rb +6 -6
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
- data/lib/contrast/agent/protect/rule.rb +0 -5
- data/lib/contrast/agent/protect/rule/base.rb +25 -36
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +3 -3
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -7
- data/lib/contrast/agent/protect/rule/path_traversal.rb +2 -7
- data/lib/contrast/agent/protect/rule/sqli.rb +4 -4
- data/lib/contrast/agent/protect/rule/xxe.rb +1 -0
- data/lib/contrast/agent/railtie.rb +1 -0
- data/lib/contrast/agent/reaction_processor.rb +3 -3
- data/lib/contrast/agent/request.rb +91 -334
- data/lib/contrast/agent/request_context.rb +17 -18
- data/lib/contrast/agent/request_handler.rb +2 -2
- data/lib/contrast/agent/response.rb +2 -83
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +8 -10
- data/lib/contrast/agent/static_analysis.rb +2 -3
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +3 -5
- data/lib/contrast/api/communication.rb +20 -0
- data/lib/contrast/api/communication/connection_status.rb +41 -0
- data/lib/contrast/api/communication/messaging_queue.rb +79 -0
- data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +15 -22
- data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
- data/lib/contrast/api/communication/socket.rb +45 -0
- data/lib/contrast/api/communication/socket_client.rb +76 -0
- data/lib/contrast/api/communication/speedracer.rb +111 -0
- data/lib/contrast/api/communication/tcp_socket.rb +31 -0
- data/lib/contrast/api/communication/unix_socket.rb +27 -0
- data/lib/contrast/api/decorators.rb +10 -0
- data/lib/contrast/api/decorators/address.rb +60 -0
- data/lib/contrast/api/decorators/application_settings.rb +7 -3
- data/lib/contrast/api/decorators/application_update.rb +0 -9
- data/lib/contrast/api/decorators/http_request.rb +139 -0
- data/lib/contrast/api/decorators/message.rb +75 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +28 -0
- data/lib/contrast/api/decorators/route_coverage.rb +57 -0
- data/lib/contrast/api/decorators/trace_event.rb +99 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +57 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +46 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +51 -0
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
- data/lib/contrast/api/decorators/user_input.rb +40 -0
- data/lib/contrast/components/agent.rb +17 -12
- data/lib/contrast/components/app_context.rb +27 -2
- data/lib/contrast/components/assess.rb +25 -15
- data/lib/contrast/components/config.rb +4 -9
- data/lib/contrast/components/contrast_service.rb +23 -67
- data/lib/contrast/components/interface.rb +5 -13
- data/lib/contrast/components/inventory.rb +5 -1
- data/lib/contrast/components/logger.rb +2 -2
- data/lib/contrast/components/protect.rb +40 -4
- data/lib/contrast/components/scope.rb +2 -52
- data/lib/contrast/components/settings.rb +18 -18
- data/lib/contrast/config/protect_rules_configuration.rb +0 -1
- data/lib/contrast/configuration.rb +2 -2
- data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -15
- data/lib/contrast/extension/assess/array.rb +77 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +3 -4
- data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -0
- data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +1 -1
- data/lib/contrast/{extensions/ruby_core → extension}/assess/fiber.rb +7 -6
- data/lib/contrast/{extensions/ruby_core → extension}/assess/hash.rb +2 -2
- data/lib/contrast/extension/assess/kernel.rb +110 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/regexp.rb +4 -4
- data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +6 -6
- data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -3
- data/lib/contrast/extension/kernel.rb +54 -0
- data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
- data/lib/contrast/extension/protect/kernel.rb +44 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
- data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
- data/lib/contrast/framework/base_support.rb +22 -23
- data/lib/contrast/framework/manager.rb +31 -15
- data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
- data/lib/contrast/framework/rack/patch/support.rb +24 -0
- data/lib/contrast/framework/rack/support.rb +22 -0
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +41 -0
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +102 -0
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
- data/lib/contrast/framework/rails/patch/support.rb +67 -0
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
- data/lib/contrast/framework/rails/support.rb +86 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
- data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
- data/lib/contrast/framework/sinatra/support.rb +98 -0
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +80 -0
- data/lib/contrast/logger/format.rb +51 -0
- data/lib/contrast/{agent/logger.rb → logger/log.rb} +39 -63
- data/lib/contrast/logger/time.rb +50 -0
- data/lib/contrast/tasks/config.rb +54 -0
- data/lib/contrast/tasks/service.rb +1 -5
- data/lib/contrast/utils/assess/tracking_util.rb +45 -20
- data/lib/contrast/utils/class_util.rb +4 -2
- data/lib/contrast/utils/gemfile_reader.rb +2 -2
- data/lib/contrast/utils/hash_digest.rb +13 -9
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -18
- data/lib/contrast/utils/inventory_util.rb +2 -7
- data/lib/contrast/utils/job_servers_running.rb +4 -2
- data/lib/contrast/utils/object_share.rb +0 -2
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/stack_trace_utils.rb +0 -1
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -14
- data/lib/contrast/utils/timer.rb +1 -17
- data/resources/assess/policy.json +9 -50
- data/resources/inventory/policy.json +2 -2
- data/resources/protect/policy.json +6 -6
- data/ruby-agent.gemspec +9 -5
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +103 -139
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4964
- data/funchook/autom4te.cache/requests +0 -77
- data/funchook/autom4te.cache/traces.0 +0 -361
- data/funchook/config.log +0 -651
- data/funchook/config.status +0 -1015
- data/funchook/configure +0 -4964
- data/funchook/src/Makefile +0 -70
- data/funchook/src/config.h +0 -101
- data/funchook/src/config.h.in +0 -100
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.dylib +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +0 -43
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
- data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
- data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
- data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -53
- data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -136
- data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
- data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
- data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
- data/lib/contrast/agent/feature_state.rb +0 -346
- data/lib/contrast/agent/protect/rule/csrf.rb +0 -119
- data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -100
- data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
- data/lib/contrast/agent/settings_state.rb +0 -88
- data/lib/contrast/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- data/lib/contrast/api/decorators/exclusion.rb +0 -20
- data/lib/contrast/api/socket.rb +0 -43
- data/lib/contrast/api/speedracer.rb +0 -188
- data/lib/contrast/api/tcp_socket.rb +0 -29
- data/lib/contrast/api/unix_socket.rb +0 -25
- data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
- data/lib/contrast/extensions/framework/rack/request.rb +0 -24
- data/lib/contrast/extensions/framework/rack/response.rb +0 -23
- data/lib/contrast/extensions/framework/rails/action_controller_inheritance.rb +0 -39
- data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
- data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
- data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -58
- data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
- data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
- data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
- data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
- data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -96
- data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
- data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -78
- data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
- data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -51
- data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
- data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -61
- data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -50
- data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -66
- data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -115
- data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -53
- data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -127
- data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
- data/lib/contrast/extensions/ruby_core/protect/rule_applicator.rb +0 -50
- data/lib/contrast/framework/rails_support.rb +0 -104
- data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
- data/lib/contrast/framework/sinatra_support.rb +0 -104
- data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
- data/lib/contrast/internal_exception.rb +0 -8
- data/lib/contrast/utils/cache.rb +0 -58
- data/lib/contrast/utils/data_store_util.rb +0 -23
- data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
- data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
- data/lib/contrast/utils/random_util.rb +0 -22
- data/lib/contrast/utils/service_sender_util.rb +0 -110
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
- data/resources/csrf/inject.js +0 -44
@@ -89,14 +89,12 @@ module Contrast
|
|
89
89
|
|
90
90
|
finding = Contrast::Api::Dtm::Finding.new
|
91
91
|
finding.rule_id = Contrast::Utils::StringUtils.protobuf_safe_string(trigger_node.rule_id)
|
92
|
-
finding.session_id = Contrast::Agent::FeatureState.instance.current_session_id
|
93
92
|
finding.version = CURRENT_FINDING_VERSION
|
94
93
|
|
95
94
|
build_from_source(finding, source)
|
96
95
|
trigger_event = Contrast::Agent::Assess::Events::EventFactory.build(trigger_node, source, object, ret, args).to_dtm_event
|
97
96
|
finding.events << trigger_event
|
98
97
|
build_hash(finding, source)
|
99
|
-
build_tags(context)
|
100
98
|
finding.routes << context.route if context.route
|
101
99
|
context.activity.findings << finding
|
102
100
|
logger.trace('Finding created',
|
@@ -109,10 +107,6 @@ module Contrast
|
|
109
107
|
|
110
108
|
private
|
111
109
|
|
112
|
-
def settings
|
113
|
-
Contrast::Agent::FeatureState.instance
|
114
|
-
end
|
115
|
-
|
116
110
|
# This is our method that actually checks the taint on the object
|
117
111
|
# our trigger_node targets.
|
118
112
|
#
|
@@ -140,7 +134,7 @@ module Contrast
|
|
140
134
|
build_finding(context, trigger_node, source, object, ret, *args)
|
141
135
|
end
|
142
136
|
rescue StandardError => e
|
143
|
-
logger.warn('Unable to apply trigger', e, node_id:
|
137
|
+
logger.warn('Unable to apply trigger', e, node_id: trigger_node.id)
|
144
138
|
end
|
145
139
|
|
146
140
|
# Given the marker from the trigger_node (the pointer indicating
|
@@ -234,7 +228,7 @@ module Contrast
|
|
234
228
|
else
|
235
229
|
logger.warn('Trigger source is of unknown type. Unable to inspect.',
|
236
230
|
node_id: trigger_node.id,
|
237
|
-
source_id:
|
231
|
+
source_id: source.__id__,
|
238
232
|
source_type: source.cs__class.to_s)
|
239
233
|
logger.trace(source.to_s[0..99])
|
240
234
|
end
|
@@ -269,12 +263,6 @@ module Contrast
|
|
269
263
|
finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash_code)
|
270
264
|
finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
|
271
265
|
end
|
272
|
-
|
273
|
-
def build_tags context
|
274
|
-
return unless ASSESS.tags
|
275
|
-
|
276
|
-
context.activity.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
|
277
|
-
end
|
278
266
|
end
|
279
267
|
end
|
280
268
|
end
|
@@ -1,6 +1,10 @@
|
|
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
|
+
cs__scoped_require 'contrast/agent/assess/policy/trigger/reflected_xss'
|
5
|
+
cs__scoped_require 'contrast/agent/assess/policy/trigger/xpath'
|
6
|
+
cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
|
7
|
+
|
4
8
|
module Contrast
|
5
9
|
module Agent
|
6
10
|
module Assess
|
@@ -64,7 +68,7 @@ module Contrast
|
|
64
68
|
end
|
65
69
|
|
66
70
|
def rule_disabled?
|
67
|
-
|
71
|
+
ASSESS.rule_disabled?(rule_id)
|
68
72
|
end
|
69
73
|
|
70
74
|
# Indicate if this is a dataflow based trigger, meaning it has a proper
|
@@ -164,8 +168,8 @@ module Contrast
|
|
164
168
|
|
165
169
|
tags.each do |tag|
|
166
170
|
raise(ArgumentError, "Rule #{ rule_id } had an invalid tag. #{ tag } is not a known value.") unless
|
167
|
-
Contrast::
|
168
|
-
Contrast::
|
171
|
+
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
|
172
|
+
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
|
169
173
|
end
|
170
174
|
end
|
171
175
|
|
@@ -188,10 +192,21 @@ module Contrast
|
|
188
192
|
return find_ranges_by_any_tag(cs__properties, tags) if tags.length == 1
|
189
193
|
|
190
194
|
ranges = []
|
195
|
+
# TODO: RUBY-946 clean this up, perhaps with
|
196
|
+
# tags.each { |tag| applicable << cs__properties.fetch_tag(tag) }
|
197
|
+
# return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless applicable.length == tags.length
|
198
|
+
# ...
|
191
199
|
# find all the indicies on the source that have all the given tags
|
192
200
|
(0..length).each do |idx|
|
193
|
-
tags_at = cs__properties.
|
194
|
-
ranges << idx if tags.all?
|
201
|
+
tags_at = cs__properties.tags_at(idx)
|
202
|
+
ranges << idx if tags.all? do |tag|
|
203
|
+
found = false
|
204
|
+
tags_at.each do |tag_at|
|
205
|
+
found = tag_at.label == tag
|
206
|
+
break if found
|
207
|
+
end
|
208
|
+
found
|
209
|
+
end
|
195
210
|
end
|
196
211
|
# break early if no indicies satisfy all the tags
|
197
212
|
return Contrast::Utils::ObjectShare::EMPTY_ARRAY if ranges.empty?
|
@@ -4,9 +4,8 @@
|
|
4
4
|
cs__scoped_require 'set'
|
5
5
|
cs__scoped_require 'base64'
|
6
6
|
cs__scoped_require 'contrast/utils/prevent_serialization'
|
7
|
-
cs__scoped_require 'contrast/
|
8
|
-
cs__scoped_require 'contrast/agent/assess/
|
9
|
-
cs__scoped_require 'contrast/agent/assess/events/source_event'
|
7
|
+
cs__scoped_require 'contrast/agent/assess/property/evented'
|
8
|
+
cs__scoped_require 'contrast/agent/assess/property/tagged'
|
10
9
|
|
11
10
|
module Contrast
|
12
11
|
module Agent
|
@@ -19,6 +18,8 @@ module Contrast
|
|
19
18
|
# user input.
|
20
19
|
class Properties
|
21
20
|
include Contrast::Utils::PreventSerialization
|
21
|
+
include Contrast::Agent::Assess::Property::Evented
|
22
|
+
include Contrast::Agent::Assess::Property::Tagged
|
22
23
|
|
23
24
|
# CONTRAST-36937
|
24
25
|
# Creating these on Properties is expensive. We want to delay this for
|
@@ -27,18 +28,6 @@ module Contrast
|
|
27
28
|
@_properties ||= {}
|
28
29
|
end
|
29
30
|
|
30
|
-
def events
|
31
|
-
@_events ||= []
|
32
|
-
end
|
33
|
-
|
34
|
-
def tracked?
|
35
|
-
tags? && tags.any?
|
36
|
-
end
|
37
|
-
|
38
|
-
def tagged? label
|
39
|
-
tags? && tags.key?(label)
|
40
|
-
end
|
41
|
-
|
42
31
|
def add_properties hash
|
43
32
|
return unless hash
|
44
33
|
|
@@ -50,373 +39,6 @@ module Contrast
|
|
50
39
|
|
51
40
|
properties[name] = value
|
52
41
|
end
|
53
|
-
|
54
|
-
def any_tags_between? start, finish
|
55
|
-
return false unless tags?
|
56
|
-
|
57
|
-
range = Contrast::Agent::Assess::Tag.new(start + finish, start)
|
58
|
-
tags.each_value do |tag_array|
|
59
|
-
return true if tag_array.any? { |tag| tag.overlaps?(range) }
|
60
|
-
end
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
# Find all of the ranges that span a given index. This is used
|
65
|
-
# in propagation when we need to shift tags about. For instance, in
|
66
|
-
# the append method when we need to see if any tag at the end needs
|
67
|
-
# to be expanded out to the size of the new String.
|
68
|
-
#
|
69
|
-
# Note: Tags do not know their key, so this is only the range covered
|
70
|
-
#
|
71
|
-
# @param idx [Integer] the index to check for tags
|
72
|
-
# @return [Array<Contrast::Agent::Assess::Tag>] a set of all the Tags
|
73
|
-
# covering the given index. This is only the ranges, not the names.
|
74
|
-
def tags_at idx
|
75
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags?
|
76
|
-
|
77
|
-
at = []
|
78
|
-
tags.each_value do |tag_array|
|
79
|
-
tag_array.each do |tag|
|
80
|
-
if tag.covers?(idx)
|
81
|
-
at << tag
|
82
|
-
elsif tag.above?(idx)
|
83
|
-
break
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
at
|
88
|
-
end
|
89
|
-
|
90
|
-
# Find all of the tag names that span a given index.
|
91
|
-
#
|
92
|
-
# @param idx [Integer] the index to check for tags
|
93
|
-
# @return [Set<String>] a set of all the tags covering the given index.
|
94
|
-
# This is only the names of the tags, not their ranges.
|
95
|
-
def tag_names_at idx
|
96
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags?
|
97
|
-
|
98
|
-
at = Set.new
|
99
|
-
tags.each_pair do |tag_name, tag_array|
|
100
|
-
tag_array.each do |tag|
|
101
|
-
if tag.covers?(idx)
|
102
|
-
at << tag_name
|
103
|
-
elsif tag.above?(idx)
|
104
|
-
break
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
at
|
109
|
-
end
|
110
|
-
|
111
|
-
# given a range, select all tags in that range the selected tags are
|
112
|
-
# shifted such that the start index of the new tag (0) aligns with the
|
113
|
-
# given start index in the range
|
114
|
-
#
|
115
|
-
# current tags: 5-15
|
116
|
-
# range : 5-10
|
117
|
-
# result : 0-05
|
118
|
-
def tags_at_range range
|
119
|
-
return Contrast::Utils::ObjectShare::EMPTY_HASH unless tags?
|
120
|
-
|
121
|
-
at = Hash.new { |h, k| h[k] = [] }
|
122
|
-
length = range.stop - range.start
|
123
|
-
tags.each_pair do |key, value|
|
124
|
-
add = []
|
125
|
-
value.each do |tag|
|
126
|
-
comparison = tag.compare_range(range.start, range.stop)
|
127
|
-
# BELOW and ABOVE are applicable to this check and are removed.
|
128
|
-
case comparison
|
129
|
-
# part of the tag is being selected
|
130
|
-
when Contrast::Agent::Assess::Tag::LOW_SPAN
|
131
|
-
add << Contrast::Agent::Assess::Tag.new(length)
|
132
|
-
# the tag exists in the requested range, figure out the boundaries
|
133
|
-
when Contrast::Agent::Assess::Tag::WITHIN
|
134
|
-
start = tag.start_idx - range.start
|
135
|
-
finish = length - start
|
136
|
-
add << Contrast::Agent::Assess::Tag.new(finish, start)
|
137
|
-
# the tag spans the requested range.
|
138
|
-
when Contrast::Agent::Assess::Tag::WITHOUT
|
139
|
-
add << Contrast::Agent::Assess::Tag.new(length)
|
140
|
-
# part of the tag is being selected
|
141
|
-
when Contrast::Agent::Assess::Tag::HIGH_SPAN
|
142
|
-
add << Contrast::Agent::Assess::Tag.new(length)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
next if add.empty?
|
146
|
-
|
147
|
-
at[key] = add
|
148
|
-
end
|
149
|
-
at
|
150
|
-
end
|
151
|
-
|
152
|
-
# Given a tag name and range object, add a new tag to this
|
153
|
-
# collection. If the given range touches an existing tag,
|
154
|
-
# we'll combine the two, adjusting the existing one and
|
155
|
-
# dropping this new one.
|
156
|
-
#
|
157
|
-
# @param label [String] the name of the tag
|
158
|
-
# @param range [Contrast::Agent::Assess::AdjustedSpan] the span that
|
159
|
-
# the tag covers
|
160
|
-
def add_tag label, range
|
161
|
-
length = range.stop - range.start
|
162
|
-
tag = Contrast::Agent::Assess::Tag.new(length, range.start)
|
163
|
-
existing = fetch_tag(label)
|
164
|
-
tags[label] = Contrast::Utils::TagUtil.ordered_merge(existing, tag)
|
165
|
-
end
|
166
|
-
|
167
|
-
def set_tags label, tag_ranges
|
168
|
-
tags[label] = tag_ranges
|
169
|
-
end
|
170
|
-
|
171
|
-
# Remove all tags with a given label
|
172
|
-
def delete_tags label
|
173
|
-
return unless tags?
|
174
|
-
|
175
|
-
tags.delete(label)
|
176
|
-
end
|
177
|
-
|
178
|
-
# Reset the tag hash
|
179
|
-
def clear_tags
|
180
|
-
return unless tags?
|
181
|
-
|
182
|
-
tags.clear
|
183
|
-
end
|
184
|
-
|
185
|
-
# Returns a list of all current tag labels, most likely to be used for
|
186
|
-
# a splat operation
|
187
|
-
def tag_keys
|
188
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags?
|
189
|
-
|
190
|
-
tags.keys
|
191
|
-
end
|
192
|
-
|
193
|
-
# Calls merge to combine touching or overlapping tags
|
194
|
-
# Deletes empty tags
|
195
|
-
def cleanup_tags
|
196
|
-
return unless tags?
|
197
|
-
|
198
|
-
Contrast::Utils::TagUtil.merge_tags(tags)
|
199
|
-
tags.delete_if { |_, value| value.empty? }
|
200
|
-
end
|
201
|
-
|
202
|
-
# We'll use this as a helper method to retrieve tags from the hash.
|
203
|
-
# Because the hash auto-populates an empty array when we try to access
|
204
|
-
# a tag in it, we cannot use the [] method without side effect. To get
|
205
|
-
# around this, we'll use a fetch work around.
|
206
|
-
def fetch_tag label
|
207
|
-
return unless tags?
|
208
|
-
|
209
|
-
tags.fetch(label, nil)
|
210
|
-
end
|
211
|
-
|
212
|
-
# Convert the tags of this object into the TraceTaintRange requried to
|
213
|
-
# be sent to the service
|
214
|
-
def tags_to_dtm
|
215
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags?
|
216
|
-
|
217
|
-
ranges = []
|
218
|
-
tags.each_pair do |key, value|
|
219
|
-
next if value.empty?
|
220
|
-
|
221
|
-
value.each do |tag|
|
222
|
-
range = Contrast::Api::Dtm::TraceTaintRange.new
|
223
|
-
range.tag = Contrast::Utils::StringUtils.protobuf_safe_string(key)
|
224
|
-
range.range = tag.start_idx.to_s + Contrast::Utils::ObjectShare::COLON + tag.end_idx.to_s
|
225
|
-
ranges << range
|
226
|
-
end
|
227
|
-
end
|
228
|
-
ranges
|
229
|
-
end
|
230
|
-
|
231
|
-
# Remove all tags within the given ranges.
|
232
|
-
# This does not delete an entire tag if part of that tag is
|
233
|
-
# outside this range, meaning we may reduce sizes of tags
|
234
|
-
# or split them.
|
235
|
-
#
|
236
|
-
# If shift is true, it is assumed the characters at those ranges were
|
237
|
-
# removed. If shift is false, it is assumed those ranges were replaced
|
238
|
-
# by the same number of characters and no shift is needed.
|
239
|
-
#
|
240
|
-
# current tags: 0-15
|
241
|
-
# range: 5-10
|
242
|
-
# result: 0-5, 10-15
|
243
|
-
def delete_tags_at_ranges ranges, shift = true
|
244
|
-
return unless tags?
|
245
|
-
|
246
|
-
# Stage one - delete the tags w/o changing their
|
247
|
-
# location.
|
248
|
-
ranges.each do |range|
|
249
|
-
remove_tags(range)
|
250
|
-
end
|
251
|
-
|
252
|
-
return unless shift
|
253
|
-
|
254
|
-
# the amount we've already removed from the string
|
255
|
-
shift = 0
|
256
|
-
# Stage two - shift the tags to the left to account
|
257
|
-
# for the sections that were deleted.
|
258
|
-
ranges.each do |range|
|
259
|
-
shift_tags_for_deletion(range, shift)
|
260
|
-
shift += (range.stop - range.start)
|
261
|
-
end
|
262
|
-
|
263
|
-
# Clean up and merge any touching tags
|
264
|
-
Contrast::Utils::TagUtil.merge_tags(tags)
|
265
|
-
end
|
266
|
-
|
267
|
-
# Shift all the tags in this object by the given ranges.
|
268
|
-
# This method assumes the ranges are sorted, meaning
|
269
|
-
# the leftmost (lowest) range is first
|
270
|
-
#
|
271
|
-
# current tags: 0-15
|
272
|
-
# range: 5-10
|
273
|
-
# result: 0-5, 10-20
|
274
|
-
def shift_tags ranges
|
275
|
-
return unless tags?
|
276
|
-
|
277
|
-
ranges.each do |range|
|
278
|
-
shift_tags_for_insertion(range)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
# Add an event to these properties. It will be used to build
|
283
|
-
# a trace if this object ends up in a trigger.
|
284
|
-
def add_event event
|
285
|
-
events << event
|
286
|
-
self
|
287
|
-
end
|
288
|
-
|
289
|
-
def build_event policy_node, tagged, object, ret, args, source_type = nil, source_name = nil
|
290
|
-
event = Contrast::Agent::Assess::Events::EventFactory.build(policy_node, tagged, object, ret, args, source_type, source_name)
|
291
|
-
add_event(event)
|
292
|
-
report_sources(tagged, event)
|
293
|
-
end
|
294
|
-
|
295
|
-
private
|
296
|
-
|
297
|
-
def report_sources tagged, event
|
298
|
-
return unless tagged && !tagged.to_s.empty?
|
299
|
-
return unless event.cs__is_a?(Contrast::Agent::Assess::Events::SourceEvent)
|
300
|
-
return unless event&.source_type
|
301
|
-
|
302
|
-
current_request = Contrast::Agent::REQUEST_TRACKER.current
|
303
|
-
return unless current_request
|
304
|
-
return if current_request.observed_route.sources.any? { |source| source.type == event.forced_source_type && source.name == event.forced_source_name }
|
305
|
-
|
306
|
-
event_source_dtm = event.build_event_source_dtm
|
307
|
-
return unless event_source_dtm
|
308
|
-
|
309
|
-
current_request.observed_route.sources << event_source_dtm
|
310
|
-
end
|
311
|
-
|
312
|
-
# Because of the auto-fill thing, we should not allow direct access to
|
313
|
-
# the tags hash. Instead, the methods above should be used to do
|
314
|
-
# operations like add, delete, and fetch.
|
315
|
-
#
|
316
|
-
# CONTRAST-22914
|
317
|
-
# please do NOT expose this w/ an attr_reader / accessor. there are
|
318
|
-
# helper methods in this class that safely access the hash. the tags
|
319
|
-
# method is private to avoid the side effect of a direct lookup with
|
320
|
-
# `[]` adding an empty array to the hash.
|
321
|
-
def tags
|
322
|
-
@_tags ||= Hash.new { |h, k| h[k] = [] }
|
323
|
-
end
|
324
|
-
|
325
|
-
# Creating Tags is expensive and we check for Tags all the time on
|
326
|
-
# untracked things. ALWAYS!!! call this method before checking if
|
327
|
-
# an object has tags
|
328
|
-
def tags?
|
329
|
-
instance_variable_defined?(:@_tags)
|
330
|
-
end
|
331
|
-
|
332
|
-
# Remove the tag ranges covering the given range
|
333
|
-
def remove_tags range
|
334
|
-
return unless tags?
|
335
|
-
|
336
|
-
full_delete = []
|
337
|
-
tags.each_pair do |key, value|
|
338
|
-
remove = []
|
339
|
-
add = []
|
340
|
-
value.each do |tag|
|
341
|
-
comparison = tag.compare_range(range.start, range.stop)
|
342
|
-
# ABOVE and BELOW are not affected by this check
|
343
|
-
case comparison
|
344
|
-
when Contrast::Agent::Assess::Tag::LOW_SPAN
|
345
|
-
tag.update_end(range.start)
|
346
|
-
when Contrast::Agent::Assess::Tag::WITHIN
|
347
|
-
remove << tag
|
348
|
-
when Contrast::Agent::Assess::Tag::WITHOUT
|
349
|
-
new_tag = tag.clone
|
350
|
-
new_tag.update_start(range.stop)
|
351
|
-
add << new_tag
|
352
|
-
tag.update_end(range.start)
|
353
|
-
when Contrast::Agent::Assess::Tag::HIGH_SPAN
|
354
|
-
tag.update_start(range.stop)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
value.delete_if { |tag| remove.include?(tag) }
|
358
|
-
Contrast::Utils::TagUtil.ordered_merge(value, add)
|
359
|
-
full_delete << key if value.empty?
|
360
|
-
end
|
361
|
-
full_delete.each { |key| tags.delete(key) }
|
362
|
-
end
|
363
|
-
|
364
|
-
# Shift the tag ranges covering the given range
|
365
|
-
# We assume this is for a deletion, meaning we
|
366
|
-
# have to move tags to the left
|
367
|
-
def shift_tags_for_deletion range, shift
|
368
|
-
return unless tags?
|
369
|
-
|
370
|
-
tags.each_value do |value|
|
371
|
-
value.each do |tag|
|
372
|
-
comparison = tag.compare_range(range.start - shift, range.stop - shift)
|
373
|
-
length = range.stop - range.start
|
374
|
-
case comparison
|
375
|
-
# this is really the only thing we need to shift
|
376
|
-
when Contrast::Agent::Assess::Tag::ABOVE
|
377
|
-
tag.shift(0 - length)
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
# Shift the tag ranges covering the given range
|
384
|
-
# We assume this is for a insertion, meaning we
|
385
|
-
# have to move tags to the right
|
386
|
-
def shift_tags_for_insertion range
|
387
|
-
return unless tags?
|
388
|
-
|
389
|
-
tags.each_value do |value|
|
390
|
-
add = []
|
391
|
-
value.each do |tag|
|
392
|
-
comparison = tag.compare_range(range.start, range.stop)
|
393
|
-
length = range.stop - range.start
|
394
|
-
# BELOW is not affected by this check
|
395
|
-
case comparison
|
396
|
-
# part of the tag is being inserted on
|
397
|
-
when Contrast::Agent::Assess::Tag::LOW_SPAN
|
398
|
-
new_tag = tag.clone
|
399
|
-
new_tag.update_start(range.start)
|
400
|
-
new_tag.shift(length)
|
401
|
-
add << new_tag
|
402
|
-
tag.update_end(range.start)
|
403
|
-
# the tag exists in the inserted range. it is partially shifted
|
404
|
-
when Contrast::Agent::Assess::Tag::WITHIN
|
405
|
-
tag.shift(length)
|
406
|
-
# the tag spans the range. leave the part below alone
|
407
|
-
when Contrast::Agent::Assess::Tag::WITHOUT
|
408
|
-
new_tag = tag.clone
|
409
|
-
new_tag.update_start(range.start)
|
410
|
-
new_tag.shift(length)
|
411
|
-
add << new_tag
|
412
|
-
tag.update_end(range.start)
|
413
|
-
when Contrast::Agent::Assess::Tag::HIGH_SPAN, Contrast::Agent::Assess::Tag::ABOVE
|
414
|
-
tag.shift(length)
|
415
|
-
end
|
416
|
-
end
|
417
|
-
Contrast::Utils::TagUtil.ordered_merge(value, add)
|
418
|
-
end
|
419
|
-
end
|
420
42
|
end
|
421
43
|
end
|
422
44
|
end
|