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
@@ -0,0 +1,99 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/utils/string_utils'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Api
|
8
|
+
module Decorators
|
9
|
+
# Used to decorate the TraceEvent protobuf model
|
10
|
+
module TraceEvent
|
11
|
+
def self.included klass
|
12
|
+
klass.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Wrapper around build_event_object for the args array. Handles
|
16
|
+
# tainting the correct argument.
|
17
|
+
def build_event_args contrast_event, taint_target
|
18
|
+
contrast_event.args.each_index do |idx|
|
19
|
+
truncate_arg = taint_target != idx
|
20
|
+
event_arg = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.args[idx], truncate_arg)
|
21
|
+
args << event_arg
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# TeamServer only supports one object's taint ranges at a time.
|
26
|
+
# We'll find the taint ranges for the target and return those
|
27
|
+
def build_taint_ranges contrast_event, taint_target
|
28
|
+
# If there's no taint_target, this isn't a dataflow trace, but a
|
29
|
+
# trigger one
|
30
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless taint_target
|
31
|
+
|
32
|
+
properties = case taint_target
|
33
|
+
when Contrast::Utils::ObjectShare::OBJECT_KEY
|
34
|
+
contrast_event.object.cs__properties
|
35
|
+
when Contrast::Utils::ObjectShare::RETURN_KEY
|
36
|
+
contrast_event.ret.cs__properties
|
37
|
+
else
|
38
|
+
target = contrast_event.args[taint_target]
|
39
|
+
if target.is_a?(Hash)
|
40
|
+
if contrast_event.policy_node&.targets&.any?
|
41
|
+
target[contrast_event.policy_node.targets[0]].cs__properties
|
42
|
+
else
|
43
|
+
target[contrast_event.policy_node.sources[0]].cs__properties
|
44
|
+
end
|
45
|
+
else
|
46
|
+
target.cs__properties
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless properties.tracked?
|
51
|
+
|
52
|
+
properties.tags_to_dtm
|
53
|
+
end
|
54
|
+
|
55
|
+
# Class methods for TraceEvent
|
56
|
+
module ClassMethods
|
57
|
+
def build contrast_event
|
58
|
+
event_dtm = new
|
59
|
+
# Figure out what the target of this event was. It's a little
|
60
|
+
# annoying for us since P can be named (thanks, Ruby) where
|
61
|
+
# as for everyone else it is idx based.
|
62
|
+
taint_target = contrast_event.determine_taint_target(event_dtm) # This can't be pulled into the decorator because SourceEvent has a custom impl :/
|
63
|
+
|
64
|
+
event_dtm.type = contrast_event.policy_node.node_type
|
65
|
+
event_dtm.action = contrast_event.policy_node.build_action
|
66
|
+
event_dtm.timestamp_ms = contrast_event.time.to_i
|
67
|
+
event_dtm.thread = Contrast::Utils::StringUtils.force_utf8(contrast_event.thread)
|
68
|
+
truncate_obj = Contrast::Utils::ObjectShare::OBJECT_KEY != taint_target
|
69
|
+
event_dtm.object = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.object, truncate_obj)
|
70
|
+
truncate_ret = Contrast::Utils::ObjectShare::RETURN_KEY != taint_target
|
71
|
+
event_dtm.ret = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.ret, truncate_ret)
|
72
|
+
event_dtm.build_event_args(contrast_event, taint_target)
|
73
|
+
|
74
|
+
taint_ranges = event_dtm.build_taint_ranges(contrast_event, taint_target)
|
75
|
+
taint_ranges.each do |range|
|
76
|
+
event_dtm.taint_ranges << range
|
77
|
+
end
|
78
|
+
|
79
|
+
# We delayed doing this as long as possible b/c it's expensive
|
80
|
+
stack = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
|
81
|
+
event_dtm.stack += stack
|
82
|
+
|
83
|
+
event_dtm.object_id = contrast_event.event_id.to_i
|
84
|
+
contrast_event.parent_ids&.each do |id|
|
85
|
+
parent = Contrast::Api::Dtm::ParentObjectId.new
|
86
|
+
parent.id = id.to_i
|
87
|
+
event_dtm.parent_object_ids << parent
|
88
|
+
end
|
89
|
+
|
90
|
+
event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret, contrast_event.policy_node, contrast_event.args)
|
91
|
+
event_dtm
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Contrast::Api::Dtm::TraceEvent.include(Contrast::Api::Decorators::TraceEvent)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/utils/string_utils'
|
5
|
+
cs__scoped_require 'contrast/utils/assess/tracking_util'
|
6
|
+
cs__scoped_require 'base64'
|
7
|
+
cs__scoped_require 'contrast/components/interface'
|
8
|
+
|
9
|
+
module Contrast
|
10
|
+
module Api
|
11
|
+
module Decorators
|
12
|
+
# Used to decorate the TraceEventObject protobuf model
|
13
|
+
module TraceEventObject
|
14
|
+
def self.included klass
|
15
|
+
klass.extend(ClassMethods)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Class methods for TraceEventObject
|
19
|
+
module ClassMethods
|
20
|
+
include Contrast::Components::Interface
|
21
|
+
access_component :scope
|
22
|
+
# Build the event object. We were originally going to include taint on
|
23
|
+
# each one, but TS doesn't accept / use that, so it is a waste of time.
|
24
|
+
#
|
25
|
+
# We'll truncate any object that isn't important to the taint ranges of
|
26
|
+
# this event, so that we don't murder TeamServer by, for instance,
|
27
|
+
# hypothetically sending the entire rendered HTML page >_> <_< >_>
|
28
|
+
ELLIPSIS = '...'
|
29
|
+
UNTRUNCATED_PORTION_LENGTH = 25
|
30
|
+
TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + ELLIPSIS.length
|
31
|
+
def build object, truncate
|
32
|
+
event_object = new
|
33
|
+
with_contrast_scope do
|
34
|
+
obj_string = Contrast::Utils::StringUtils.force_utf8(object)
|
35
|
+
obj_string = truncate(obj_string) if truncate && obj_string.length > TRUNCATION_LENGTH
|
36
|
+
event_object.value = Base64.encode64(obj_string)
|
37
|
+
event_object.tracked = Contrast::Utils::Assess::TrackingUtil.tracked?(object)
|
38
|
+
end
|
39
|
+
event_object
|
40
|
+
end
|
41
|
+
|
42
|
+
def truncate obj_string
|
43
|
+
tmp = []
|
44
|
+
tmp << obj_string[0, UNTRUNCATED_PORTION_LENGTH]
|
45
|
+
tmp << ELLIPSIS
|
46
|
+
tmp << obj_string[
|
47
|
+
obj_string.length - UNTRUNCATED_PORTION_LENGTH,
|
48
|
+
UNTRUNCATED_PORTION_LENGTH]
|
49
|
+
tmp.join
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Contrast::Api::Dtm::TraceEventObject.include(Contrast::Api::Decorators::TraceEventObject)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/utils/string_utils'
|
5
|
+
cs__scoped_require 'contrast/utils/assess/tracking_util'
|
6
|
+
cs__scoped_require 'base64'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Api
|
10
|
+
module Decorators
|
11
|
+
# Used to decorate the TraceEventSignature protobuf model
|
12
|
+
module TraceEventSignature
|
13
|
+
def self.included klass
|
14
|
+
klass.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Class methods for TraceEventSignature
|
18
|
+
module ClassMethods
|
19
|
+
def build ret_obj, policy_node, args
|
20
|
+
signature = new
|
21
|
+
return_type = ret_obj ? ret_obj.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
|
22
|
+
signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
|
23
|
+
signature.class_name = Contrast::Utils::StringUtils.force_utf8(policy_node.class_name)
|
24
|
+
signature.method_name = Contrast::Utils::StringUtils.force_utf8(policy_node.method_name)
|
25
|
+
if args
|
26
|
+
args&.each do |arg|
|
27
|
+
arg_type = arg ? arg.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
|
28
|
+
signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
signature.constructor = policy_node.method_name == :new
|
32
|
+
# if there's a ret, then this method isn't nil. not 100% full proof since you can
|
33
|
+
# return nil, but this is the best we've got currently.
|
34
|
+
signature.void_method = ret_obj.nil?
|
35
|
+
# 8 is STATIC in Java... we have to placate them for now
|
36
|
+
# it has been requested that flags be removed since it isn't used
|
37
|
+
signature.flags = 8 unless policy_node.instance_method?
|
38
|
+
signature
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
Contrast::Api::Dtm::TraceEventSignature.include(Contrast::Api::Decorators::TraceEventSignature)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/utils/object_share'
|
5
|
+
cs__scoped_require 'contrast/utils/string_utils'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Api
|
9
|
+
module Decorators
|
10
|
+
# Used to decorate the TraceTaintRange protobuf model
|
11
|
+
module TraceTaintRange
|
12
|
+
def self.included klass
|
13
|
+
klass.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Class methods for TraceEventObject
|
17
|
+
module ClassMethods
|
18
|
+
# Convert the tags from Contrast::Agent::Assess::Property::Tagged to
|
19
|
+
# the form required for their Event's DTM.
|
20
|
+
#
|
21
|
+
# @param tags [Hash{String => Array<Contrast::Agent::Assess::Tag>}]
|
22
|
+
# @return [Array<Contrast::Api::Dtm::TraceTaintRange>]
|
23
|
+
def build_for_event tags
|
24
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags&.any?
|
25
|
+
|
26
|
+
ranges = []
|
27
|
+
tags.each_value do |value|
|
28
|
+
next if value.empty?
|
29
|
+
|
30
|
+
value.each { |tag| ranges << build(tag) }
|
31
|
+
end
|
32
|
+
ranges
|
33
|
+
end
|
34
|
+
|
35
|
+
# Convert our Tags to their DTM equivalent
|
36
|
+
#
|
37
|
+
# @param tag [Contrast::Agent::Assess::Tag]
|
38
|
+
# @return [Contrast::Api::Dtm::TraceTaintRange]
|
39
|
+
def build tag
|
40
|
+
range = Contrast::Api::Dtm::TraceTaintRange.new
|
41
|
+
range.tag = Contrast::Utils::StringUtils.protobuf_safe_string(tag.label)
|
42
|
+
range.range = tag.start_idx.to_s + Contrast::Utils::ObjectShare::COLON + tag.end_idx.to_s
|
43
|
+
range
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Contrast::Api::Dtm::TraceTaintRange.include(Contrast::Api::Decorators::TraceTaintRange)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Contrast
|
5
|
+
module Api
|
6
|
+
module Decorators
|
7
|
+
# A holder for the valid tags that can be sent to the Service, and
|
8
|
+
# ultimately TS, that we have to honor. Placed here so as not to clutter
|
9
|
+
# other code.
|
10
|
+
module TraceTaintRangeTags
|
11
|
+
# EventTagTypeDTM
|
12
|
+
VALID_TAGS = %w[
|
13
|
+
XML_ENCODED
|
14
|
+
XML_DECODED
|
15
|
+
HTML_ENCODED
|
16
|
+
HTML_DECODED
|
17
|
+
URL_ENCODED
|
18
|
+
URL_DECODED
|
19
|
+
CSS_ENCODED
|
20
|
+
CSS_DECODED
|
21
|
+
BASE64_ENCODED
|
22
|
+
BASE64_DECODED
|
23
|
+
JAVASCRIPT_ENCODED
|
24
|
+
JAVASCRIPT_DECODED
|
25
|
+
JAVA_ENCODED
|
26
|
+
JAVA_DECODED
|
27
|
+
CSV_ENCODED
|
28
|
+
CSV_DECODED
|
29
|
+
SQL_ENCODED
|
30
|
+
SQL_DECODED
|
31
|
+
LDAP_ENCODED
|
32
|
+
LDAP_DECODED
|
33
|
+
XPATH_ENCODED
|
34
|
+
XPATH_DECODED
|
35
|
+
OS_ENCODED
|
36
|
+
OS_DECODED
|
37
|
+
VBSCRIPT_ENCODED
|
38
|
+
VBSCRIPT_DECODED
|
39
|
+
POTENTIAL_SANITIZED
|
40
|
+
POTENTIAL_VALIDATED
|
41
|
+
NO_CONTROL_CHARS
|
42
|
+
CUSTOM
|
43
|
+
|
44
|
+
CUSTOM_ENCODED
|
45
|
+
CUSTOM_ENCODED_CMD_INJECTION
|
46
|
+
CUSTOM_ENCODED_EXPRESSION_LANGUAGE_INJECTION
|
47
|
+
CUSTOM_ENCODED_HEADER_INJECTION
|
48
|
+
CUSTOM_ENCODED_HQL_INJECTION
|
49
|
+
CUSTOM_ENCODED_LDAP_INJECTION
|
50
|
+
CUSTOM_ENCODED_LOG_INJECTION
|
51
|
+
CUSTOM_ENCODED_NOSQL_INJECTION
|
52
|
+
CUSTOM_ENCODED_PATH_TRAVERSAL
|
53
|
+
CUSTOM_ENCODED_REDOS
|
54
|
+
CUSTOM_ENCODED_REFLECTED_XSS
|
55
|
+
CUSTOM_ENCODED_REFLECTION_INJECTION
|
56
|
+
CUSTOM_ENCODED_SMTP_INJECTION
|
57
|
+
CUSTOM_ENCODED_SQL_INJECTION
|
58
|
+
CUSTOM_ENCODED_SSRF
|
59
|
+
CUSTOM_ENCODED_STORED_XSS
|
60
|
+
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION
|
61
|
+
CUSTOM_ENCODED_UNSAFE_CODE_EXECUTION
|
62
|
+
CUSTOM_ENCODED_UNSAFE_READLINE
|
63
|
+
CUSTOM_ENCODED_UNSAFE_XML_DECODE
|
64
|
+
CUSTOM_ENCODED_UNTRUSTED_DESERIALIZATION
|
65
|
+
CUSTOM_ENCODED_UNVALIDATED_FORWARD
|
66
|
+
CUSTOM_ENCODED_UNVALIDATED_REDIRECT
|
67
|
+
CUSTOM_ENCODED_XPATH_INJECTION
|
68
|
+
CUSTOM_ENCODED_XXE
|
69
|
+
CUSTOM_SECURITY_CONTROL_APPLIED
|
70
|
+
|
71
|
+
CUSTOM_VALIDATED
|
72
|
+
CUSTOM_VALIDATED_CMD_INJECTION
|
73
|
+
CUSTOM_VALIDATED_EXPRESSION_LANGUAGE_INJECTION
|
74
|
+
CUSTOM_VALIDATED_HEADER_INJECTION
|
75
|
+
CUSTOM_VALIDATED_HQL_INJECTION
|
76
|
+
CUSTOM_VALIDATED_LDAP_INJECTION
|
77
|
+
CUSTOM_VALIDATED_LOG_INJECTION
|
78
|
+
CUSTOM_VALIDATED_NOSQL_INJECTION
|
79
|
+
CUSTOM_VALIDATED_PATH_TRAVERSAL
|
80
|
+
CUSTOM_VALIDATED_REDOS
|
81
|
+
CUSTOM_VALIDATED_REFLECTED_XSS
|
82
|
+
CUSTOM_VALIDATED_REFLECTION_INJECTION
|
83
|
+
CUSTOM_VALIDATED_SMTP_INJECTION
|
84
|
+
CUSTOM_VALIDATED_SQL_INJECTION
|
85
|
+
CUSTOM_VALIDATED_SSRF
|
86
|
+
CUSTOM_VALIDATED_STORED_XSS
|
87
|
+
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION
|
88
|
+
CUSTOM_VALIDATED_UNSAFE_CODE_EXECUTION
|
89
|
+
CUSTOM_VALIDATED_UNSAFE_READLINE
|
90
|
+
CUSTOM_VALIDATED_UNSAFE_XML_DECODE
|
91
|
+
CUSTOM_VALIDATED_UNTRUSTED_DESERIALIZATION
|
92
|
+
CUSTOM_VALIDATED_UNVALIDATED_FORWARD
|
93
|
+
CUSTOM_VALIDATED_UNVALIDATED_REDIRECT
|
94
|
+
CUSTOM_VALIDATED_XPATH_INJECTION
|
95
|
+
CUSTOM_VALIDATED_XXE
|
96
|
+
|
97
|
+
DATABASE_WRITE
|
98
|
+
].cs__freeze
|
99
|
+
|
100
|
+
VALID_SOURCE_TAGS = %w[
|
101
|
+
NO_NEWLINES
|
102
|
+
UNTRUSTED
|
103
|
+
CROSS_SITE
|
104
|
+
LIMITED_CHARS
|
105
|
+
].cs__freeze
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/utils/string_utils'
|
5
|
+
cs__scoped_require 'contrast/utils/assess/tracking_util'
|
6
|
+
cs__scoped_require 'base64'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Api
|
10
|
+
module Decorators
|
11
|
+
# Used to decorate the TraceEventObject protobuf model
|
12
|
+
module UserInput
|
13
|
+
UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
|
14
|
+
user_input.input_type = :UNKNOWN
|
15
|
+
end.cs__freeze
|
16
|
+
|
17
|
+
def self.included klass
|
18
|
+
klass.extend(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Used to add class methods to UserInput
|
22
|
+
module ClassMethods
|
23
|
+
def build_from_ia_result ia_result
|
24
|
+
return UNKNOWN_USER_INPUT.dup unless ia_result
|
25
|
+
|
26
|
+
user_input = new
|
27
|
+
user_input.input_type = ia_result.input_type.to_i
|
28
|
+
user_input.matcher_ids = ia_result.ids
|
29
|
+
user_input.path = ia_result.path.to_s
|
30
|
+
user_input.key = ia_result.key.to_s
|
31
|
+
user_input.value = ia_result.value.to_s
|
32
|
+
user_input
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Contrast::Api::Dtm::UserInput.include(Contrast::Api::Decorators::UserInput)
|
@@ -32,18 +32,12 @@ module Contrast
|
|
32
32
|
@enabled = false
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def ruleset
|
36
|
+
@_ruleset ||= Contrast::Agent::RuleSet.new(retrieve_ruleset&.values)
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
#
|
42
|
-
# Instead of asking specifically for assess or protect rules, we can ask agent to retrieve
|
43
|
-
# the correct ruleset based on enabled modes. Since these can change on a per request basis,
|
44
|
-
# we shouldn't memoize these.
|
45
|
-
def ruleset
|
46
|
-
Contrast::Agent::RuleSet.new(retrieve_ruleset&.values)
|
39
|
+
def reset_ruleset
|
40
|
+
@_ruleset = nil
|
47
41
|
end
|
48
42
|
|
49
43
|
def patch_interpolation?
|
@@ -64,8 +58,17 @@ module Contrast
|
|
64
58
|
@_interpolation_enabled
|
65
59
|
end
|
66
60
|
|
67
|
-
def
|
68
|
-
|
61
|
+
def omit_body?
|
62
|
+
@_omit_body = true?(CONFIG.root.agent.omit_body) if @_omit_body.nil?
|
63
|
+
@_omit_body
|
64
|
+
end
|
65
|
+
|
66
|
+
def exception_control
|
67
|
+
@_exception_control ||= {
|
68
|
+
enable: true?(CONFIG.root.agent.ruby.exceptions.capture),
|
69
|
+
status: CONFIG.root.agent.ruby.exceptions.override_status || 403,
|
70
|
+
message: CONFIG.root.agent.ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
|
71
|
+
}
|
69
72
|
end
|
70
73
|
|
71
74
|
def skip_instrumentation? loaded_module_name
|
@@ -93,6 +96,8 @@ module Contrast
|
|
93
96
|
end
|
94
97
|
|
95
98
|
def retrieve_ruleset
|
99
|
+
return {} unless enabled?
|
100
|
+
|
96
101
|
if ASSESS.enabled? && PROTECT.enabled?
|
97
102
|
ASSESS.rules.merge(PROTECT.rules)
|
98
103
|
elsif ASSESS.enabled?
|