contrast-agent 3.12.1 → 3.14.0
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/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/exe/contrast_service +1 -7
- data/ext/build_funchook.rb +0 -2
- 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 +4 -9
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -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 +4 -5
- 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 +20 -4
- data/ext/cs__assess_string/cs__assess_string.h +4 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -7
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +3 -7
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +59 -28
- data/ext/cs__common/cs__common.h +18 -20
- data/ext/cs__common/extconf.rb +0 -14
- 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/ext/extconf_common.rb +0 -28
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +15 -23
- data/lib/contrast/agent.rb +51 -39
- data/lib/contrast/agent/assess.rb +11 -12
- data/lib/contrast/agent/assess/contrast_event.rb +39 -176
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +5 -9
- data/lib/contrast/agent/assess/finalizers/finalize.rb +21 -0
- data/lib/contrast/agent/assess/finalizers/freeze.rb +13 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +53 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -2
- data/lib/contrast/agent/assess/policy/patcher.rb +5 -5
- data/lib/contrast/agent/assess/policy/policy.rb +9 -9
- data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +15 -5
- data/lib/contrast/agent/assess/policy/propagation_method.rb +26 -24
- data/lib/contrast/agent/assess/policy/propagation_node.rb +6 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- 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 -1
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +12 -3
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +5 -0
- 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 +5 -5
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +8 -7
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +6 -16
- 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/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +7 -15
- data/lib/contrast/agent/assess/policy/trigger_node.rb +18 -6
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +13 -383
- 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.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_password.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -22
- 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 +7 -6
- 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 +3 -3
- data/lib/contrast/agent/inventory/policy/datastores.rb +2 -3
- 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 +37 -48
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
- data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/patch.rb +16 -16
- data/lib/contrast/agent/patching/policy/patcher.rb +30 -22
- data/lib/contrast/agent/patching/policy/policy.rb +9 -9
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -3
- 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 +21 -32
- data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
- 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 +3 -8
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- 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 +4 -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 +5 -5
- data/lib/contrast/agent/request.rb +103 -340
- data/lib/contrast/agent/request_context.rb +25 -21
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +8 -20
- data/lib/contrast/agent/rewriter.rb +5 -6
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +8 -10
- data/lib/contrast/agent/static_analysis.rb +4 -4
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +4 -6
- 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} +10 -19
- 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 +14 -4
- data/lib/contrast/api/decorators/address.rb +61 -0
- data/lib/contrast/api/decorators/application_settings.rb +10 -5
- data/lib/contrast/api/decorators/application_update.rb +5 -13
- data/lib/contrast/api/decorators/http_request.rb +140 -0
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- data/lib/contrast/api/decorators/message.rb +76 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
- data/lib/contrast/api/decorators/route_coverage.rb +58 -0
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +100 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +58 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +47 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +52 -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/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +2 -2
- data/lib/contrast/components/app_context.rb +1 -8
- data/lib/contrast/components/config.rb +7 -12
- data/lib/contrast/components/contrast_service.rb +1 -1
- data/lib/contrast/components/interface.rb +16 -16
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/components/settings.rb +0 -6
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/configuration.rb +5 -5
- data/lib/contrast/extension/assess.rb +22 -22
- data/lib/contrast/extension/assess/array.rb +4 -4
- data/lib/contrast/extension/assess/assess_extension.rb +28 -31
- data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
- data/lib/contrast/extension/assess/fiber.rb +3 -3
- data/lib/contrast/extension/assess/hash.rb +5 -3
- data/lib/contrast/extension/assess/kernel.rb +7 -6
- data/lib/contrast/extension/assess/marshal.rb +62 -0
- data/lib/contrast/extension/assess/regexp.rb +3 -3
- data/lib/contrast/extension/assess/string.rb +6 -6
- data/lib/contrast/extension/inventory.rb +4 -5
- 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 +2 -2
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +0 -23
- data/lib/contrast/framework/manager.rb +7 -17
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- 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 +1 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -6
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
- data/lib/contrast/framework/rails/support.rb +56 -37
- data/lib/contrast/framework/sinatra/patch/base.rb +2 -2
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +13 -24
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +3 -3
- data/lib/contrast/logger/format.rb +64 -0
- data/lib/contrast/logger/log.rb +17 -9
- 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 +46 -21
- data/lib/contrast/utils/boolean_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +5 -3
- data/lib/contrast/utils/freeze_util.rb +1 -1
- data/lib/contrast/utils/gemfile_reader.rb +5 -5
- data/lib/contrast/utils/hash_digest.rb +13 -3
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -18
- data/lib/contrast/utils/inventory_util.rb +6 -11
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/object_share.rb +0 -1
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -2
- data/lib/contrast/utils/stack_trace_utils.rb +2 -3
- data/lib/contrast/utils/string_utils.rb +1 -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/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +9 -9
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +60 -79
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4976
- data/funchook/autom4te.cache/requests +0 -78
- data/funchook/autom4te.cache/traces.0 +0 -364
- data/funchook/config.log +0 -490
- data/funchook/config.status +0 -1016
- data/funchook/configure +0 -4976
- 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.so +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/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/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- 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/framework/sinatra/application_helper.rb +0 -51
- 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/service_sender_util.rb +0 -167
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -1,11 +1,11 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
require 'contrast/agent/assess/events/event_factory'
|
5
|
+
require 'contrast/agent/assess/policy/trigger_validation/trigger_validation'
|
6
|
+
require 'contrast/components/interface'
|
7
|
+
require 'contrast/utils/object_share'
|
8
|
+
require 'contrast/utils/sha256_builder'
|
9
9
|
|
10
10
|
module Contrast
|
11
11
|
module Agent
|
@@ -18,7 +18,7 @@ module Contrast
|
|
18
18
|
# it was not, a Finding report is issued to the Service
|
19
19
|
module TriggerMethod
|
20
20
|
include Contrast::Components::Interface
|
21
|
-
access_component :analysis, :logging
|
21
|
+
access_component :analysis, :logging
|
22
22
|
|
23
23
|
# The level of TeamServer compliance our traces meet
|
24
24
|
CURRENT_FINDING_VERSION = 2
|
@@ -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 = SETTINGS.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',
|
@@ -230,7 +228,7 @@ module Contrast
|
|
230
228
|
else
|
231
229
|
logger.warn('Trigger source is of unknown type. Unable to inspect.',
|
232
230
|
node_id: trigger_node.id,
|
233
|
-
source_id:
|
231
|
+
source_id: source.__id__,
|
234
232
|
source_type: source.cs__class.to_s)
|
235
233
|
logger.trace(source.to_s[0..99])
|
236
234
|
end
|
@@ -265,12 +263,6 @@ module Contrast
|
|
265
263
|
finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash_code)
|
266
264
|
finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
|
267
265
|
end
|
268
|
-
|
269
|
-
def build_tags context
|
270
|
-
return unless ASSESS.tags
|
271
|
-
|
272
|
-
context.activity.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
|
273
|
-
end
|
274
266
|
end
|
275
267
|
end
|
276
268
|
end
|
@@ -1,8 +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
|
-
|
4
|
+
require 'contrast/agent/assess/policy/trigger/reflected_xss'
|
5
|
+
require 'contrast/agent/assess/policy/trigger/xpath'
|
6
|
+
require 'contrast/api/decorators/trace_taint_range_tags'
|
6
7
|
|
7
8
|
module Contrast
|
8
9
|
module Agent
|
@@ -167,8 +168,8 @@ module Contrast
|
|
167
168
|
|
168
169
|
tags.each do |tag|
|
169
170
|
raise(ArgumentError, "Rule #{ rule_id } had an invalid tag. #{ tag } is not a known value.") unless
|
170
|
-
Contrast::
|
171
|
-
Contrast::
|
171
|
+
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
|
172
|
+
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
@@ -191,10 +192,21 @@ module Contrast
|
|
191
192
|
return find_ranges_by_any_tag(cs__properties, tags) if tags.length == 1
|
192
193
|
|
193
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
|
+
# ...
|
194
199
|
# find all the indicies on the source that have all the given tags
|
195
200
|
(0..length).each do |idx|
|
196
|
-
tags_at = cs__properties.
|
197
|
-
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
|
198
210
|
end
|
199
211
|
# break early if no indicies satisfy all the tags
|
200
212
|
return Contrast::Utils::ObjectShare::EMPTY_ARRAY if ranges.empty?
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/assess/policy/trigger_validation/ssrf_validator'
|
5
|
+
require 'contrast/agent/assess/policy/trigger_validation/xss_validator'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
cs__scoped_require 'contrast/agent/assess/events/source_event'
|
4
|
+
require 'base64'
|
5
|
+
require 'set'
|
6
|
+
require 'contrast/agent/assess/property/evented'
|
7
|
+
require 'contrast/agent/assess/property/tagged'
|
8
|
+
require 'contrast/utils/prevent_serialization'
|
10
9
|
|
11
10
|
module Contrast
|
12
11
|
module Agent
|
@@ -19,6 +18,10 @@ 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
|
23
|
+
|
24
|
+
attr_accessor :dupped_from
|
22
25
|
|
23
26
|
# CONTRAST-36937
|
24
27
|
# Creating these on Properties is expensive. We want to delay this for
|
@@ -27,18 +30,6 @@ module Contrast
|
|
27
30
|
@_properties ||= {}
|
28
31
|
end
|
29
32
|
|
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
33
|
def add_properties hash
|
43
34
|
return unless hash
|
44
35
|
|
@@ -51,371 +42,10 @@ module Contrast
|
|
51
42
|
properties[name] = value
|
52
43
|
end
|
53
44
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
45
|
+
def dup
|
46
|
+
ret = super
|
47
|
+
ret.dupped_from = __id__
|
48
|
+
ret
|
419
49
|
end
|
420
50
|
end
|
421
51
|
end
|