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
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/utils/object_share'
|
5
5
|
cs__scoped_require 'contrast/components/interface'
|
6
|
-
cs__scoped_require 'contrast/
|
6
|
+
cs__scoped_require 'contrast/extension/assess/assess_extension'
|
7
7
|
|
8
8
|
module Contrast
|
9
9
|
module Agent
|
@@ -28,6 +28,7 @@ module Contrast
|
|
28
28
|
INSERT_ACTION = 'INSERT'
|
29
29
|
KEEP_ACTION = 'KEEP'
|
30
30
|
NEXT_ACTION = 'NEXT'
|
31
|
+
NOOP_ACTION = 'NOOP'
|
31
32
|
PREPEND_ACTION = 'PREPEND'
|
32
33
|
REPLACE_ACTION = 'REPLACE'
|
33
34
|
REMOVE_ACTION = 'REMOVE'
|
@@ -84,6 +85,7 @@ module Contrast
|
|
84
85
|
INSERT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Insert,
|
85
86
|
KEEP_ACTION => Contrast::Agent::Assess::Policy::Propagator::Keep,
|
86
87
|
NEXT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Next,
|
88
|
+
NOOP_ACTION => nil,
|
87
89
|
PREPEND_ACTION => Contrast::Agent::Assess::Policy::Propagator::Prepend,
|
88
90
|
REPLACE_ACTION => Contrast::Agent::Assess::Policy::Propagator::Replace,
|
89
91
|
REMOVE_ACTION => Contrast::Agent::Assess::Policy::Propagator::Remove,
|
@@ -201,8 +203,7 @@ module Contrast
|
|
201
203
|
|
202
204
|
length = Contrast::Utils::StringUtils.ret_length(target)
|
203
205
|
propagation_node.tags.each do |tag|
|
204
|
-
|
205
|
-
target.cs__properties.add_tag(tag, span)
|
206
|
+
target.cs__properties.add_tag(tag, 0...length)
|
206
207
|
end
|
207
208
|
end
|
208
209
|
|
@@ -241,6 +242,7 @@ module Contrast
|
|
241
242
|
end
|
242
243
|
|
243
244
|
def handle_cs_properties_propagation propagation_node, preshift, target, object, ret, args, _block
|
245
|
+
return if propagation_node.action == NOOP_ACTION
|
244
246
|
return unless can_propagate?(propagation_node, preshift, target)
|
245
247
|
|
246
248
|
# propagate all the tags from the sources to the target
|
@@ -2,6 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/agent/assess/policy/policy_node'
|
5
|
+
cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
|
6
|
+
|
5
7
|
module Contrast
|
6
8
|
module Agent
|
7
9
|
module Assess
|
@@ -73,7 +75,9 @@ module Contrast
|
|
73
75
|
return unless untags
|
74
76
|
|
75
77
|
untags.each do |tag|
|
76
|
-
|
78
|
+
unless Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag)
|
79
|
+
raise(ArgumentError, "#{ node_type } #{ id } did not have a valid untag. #{ tag } is not a known value.")
|
80
|
+
end
|
77
81
|
raise(ArgumentError, "#{ node_type } #{ id } had the same tag and untag, #{ tag }.") if tags&.include?(tag)
|
78
82
|
end
|
79
83
|
end
|
@@ -26,7 +26,7 @@ module Contrast
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def propagate _propagation_node, _preshift, _target
|
29
|
-
raise
|
29
|
+
raise NoMethodError("Expected Base propagator subclass: #{ cs__class } to implement #propagate")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
cs__scoped_require 'contrast/
|
4
|
+
cs__scoped_require 'contrast/extension/module'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -45,9 +45,7 @@ module Contrast
|
|
45
45
|
if known_tainted
|
46
46
|
known_tainted.concat(tainted_columns.keys)
|
47
47
|
else
|
48
|
-
unless class_type < Contrast::
|
49
|
-
class_type.send(:include, Contrast::CoreExtensions::Assess::AssessExtension)
|
50
|
-
end
|
48
|
+
class_type.send(:include, Contrast::Extension::Assess::AssessExtension) unless class_type < Contrast::Extension::Assess::AssessExtension
|
51
49
|
ASSESS.tainted_columns[class_name] = tainted_columns.keys
|
52
50
|
end
|
53
51
|
|
@@ -35,10 +35,7 @@ module Contrast
|
|
35
35
|
# Depending what's inserted, we might be wrong. For instance, inserting 'foo'
|
36
36
|
# into 'asdfasdf' could result in 'asdfoofasdf'. we'd be off by one b/c of the 'f'
|
37
37
|
insert_point = target.rindex(source, insert_point)
|
38
|
-
|
39
|
-
overflow = Contrast::Agent::Assess::AdjustedSpan.new(
|
40
|
-
insert_point,
|
41
|
-
insert_point + source.length)
|
38
|
+
overflow = insert_point...(insert_point + source.length)
|
42
39
|
|
43
40
|
# handle shifting the inserted range
|
44
41
|
target.cs__properties.shift_tags([overflow])
|
@@ -14,6 +14,8 @@ module Contrast
|
|
14
14
|
def square_bracket_tagger propagation_node, preshift, ret, _block
|
15
15
|
if ret.is_a?(Array)
|
16
16
|
ret.each_with_index do |return_value, index|
|
17
|
+
next unless return_value
|
18
|
+
|
17
19
|
target_matchdata_index = if preshift.args[0].is_a?(Range)
|
18
20
|
arg_range = preshift.args[0]
|
19
21
|
arg_range.to_a.empty? ? index + 1 : arg_range.to_a[index]
|
@@ -32,6 +34,8 @@ module Contrast
|
|
32
34
|
|
33
35
|
def captures_tagger propagation_node, preshift, ret, _block
|
34
36
|
ret.each_with_index do |return_value, index|
|
37
|
+
next unless return_value
|
38
|
+
|
35
39
|
targetted_index = index + 1
|
36
40
|
square_bracket_single(targetted_index, preshift, return_value, propagation_node)
|
37
41
|
end
|
@@ -40,6 +44,8 @@ module Contrast
|
|
40
44
|
|
41
45
|
def to_a_tagger propagation_node, preshift, ret, _block
|
42
46
|
ret.each_with_index do |return_value, index|
|
47
|
+
next unless return_value
|
48
|
+
|
43
49
|
square_bracket_single(index, preshift, return_value, propagation_node)
|
44
50
|
end
|
45
51
|
ret
|
@@ -47,6 +53,8 @@ module Contrast
|
|
47
53
|
|
48
54
|
def values_at_tagger propagation_node, preshift, ret, _block
|
49
55
|
ret.each_with_index do |return_value, return_index|
|
56
|
+
next unless return_value
|
57
|
+
|
50
58
|
original_group_arg_index = preshift.args[return_index]
|
51
59
|
square_bracket_single(original_group_arg_index, preshift, return_value, propagation_node)
|
52
60
|
end
|
@@ -59,7 +67,7 @@ module Contrast
|
|
59
67
|
original_start_index = preshift.object.begin(argument_index)
|
60
68
|
original_end_index = preshift.object.end(argument_index)
|
61
69
|
original_properties = preshift.object.cs__properties
|
62
|
-
applicable_tags = original_properties.tags_at_range(
|
70
|
+
applicable_tags = original_properties.tags_at_range(original_start_index...original_end_index)
|
63
71
|
return if applicable_tags.empty?
|
64
72
|
|
65
73
|
applicable_tags.each do |tag_name, tag_ranges|
|
@@ -32,7 +32,7 @@ module Contrast
|
|
32
32
|
target_idx = 0
|
33
33
|
|
34
34
|
remove_ranges = []
|
35
|
-
|
35
|
+
start = nil
|
36
36
|
|
37
37
|
# loop over the target, the result of the delete
|
38
38
|
# every range of characters that it differs from the source
|
@@ -44,13 +44,12 @@ module Contrast
|
|
44
44
|
source_char = source_chars[source_idx]
|
45
45
|
if target_char == source_char
|
46
46
|
target_idx += 1
|
47
|
-
if
|
48
|
-
|
49
|
-
|
50
|
-
current_range = nil
|
47
|
+
if start
|
48
|
+
remove_ranges << (start...source_idx)
|
49
|
+
start = nil
|
51
50
|
end
|
52
51
|
else
|
53
|
-
|
52
|
+
start ||= source_idx
|
54
53
|
end
|
55
54
|
source_idx += 1
|
56
55
|
end
|
@@ -58,11 +57,7 @@ module Contrast
|
|
58
57
|
# once we're done looping over the target, anything left
|
59
58
|
# over is extra from the source that was deleted. tags
|
60
59
|
# applying to it need to be removed.
|
61
|
-
if source_idx != source_chars.length
|
62
|
-
remove_ranges << Contrast::Agent::Assess::AdjustedSpan.new(
|
63
|
-
source_idx,
|
64
|
-
source_chars.length)
|
65
|
-
end
|
60
|
+
remove_ranges << (source_idx...source_chars.length) if source_idx != source_chars.length
|
66
61
|
|
67
62
|
# handle deleting the removed ranges
|
68
63
|
target.cs__properties.delete_tags_at_ranges(remove_ranges)
|
@@ -50,19 +50,19 @@ module Contrast
|
|
50
50
|
length = args[1] || 1
|
51
51
|
# (void) negative range
|
52
52
|
arg += source.length if arg.negative?
|
53
|
-
|
53
|
+
arg...(arg + length)
|
54
54
|
end
|
55
55
|
|
56
56
|
def handle_string arg, source
|
57
57
|
idx = source.index(arg)
|
58
|
-
|
58
|
+
idx...(idx + arg.length)
|
59
59
|
end
|
60
60
|
|
61
61
|
def handle_regexp args, arg, source
|
62
62
|
match_data = arg.match(source)
|
63
63
|
# nil has the same meaning as 0. use full match
|
64
64
|
group = args[1] || 0
|
65
|
-
|
65
|
+
match_data.begin(group)...match_data.end(group)
|
66
66
|
end
|
67
67
|
|
68
68
|
def handle_range arg, source
|
@@ -74,7 +74,7 @@ module Contrast
|
|
74
74
|
finish += source.length if finish.negative?
|
75
75
|
finish += 1 unless arg.exclude_end?
|
76
76
|
|
77
|
-
|
77
|
+
start...finish
|
78
78
|
end
|
79
79
|
|
80
80
|
def determine_select_range source, args
|
@@ -52,7 +52,7 @@ module Contrast
|
|
52
52
|
current_index = 0
|
53
53
|
target.each do |elem|
|
54
54
|
elem_length = elem.length
|
55
|
-
range =
|
55
|
+
range = current_index...(current_index + elem_length)
|
56
56
|
tags = source.cs__properties.tags_at_range(range)
|
57
57
|
|
58
58
|
elem.cs__properties.clear_tags
|
@@ -139,7 +139,7 @@ module Contrast
|
|
139
139
|
def instrument_string_split
|
140
140
|
if @_instrument_string_split.nil?
|
141
141
|
@_instrument_string_split = begin
|
142
|
-
cs__scoped_require 'cs__assess_yield_track/cs__assess_yield_track' if AGENT.patch_yield?
|
142
|
+
cs__scoped_require 'cs__assess_yield_track/cs__assess_yield_track' if AGENT.patch_yield? && Funchook.available?
|
143
143
|
true
|
144
144
|
rescue StandardError => e
|
145
145
|
logger.error('Error loading split rb_yield patch', e)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/components/interface'
|
5
|
+
cs__scoped_require 'contrast/utils/duck_utils'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Agent
|
@@ -109,7 +110,7 @@ module Contrast
|
|
109
110
|
last_idx = idx ? idx + 1 : nil
|
110
111
|
start_index = idx
|
111
112
|
end_index = idx + incoming.length
|
112
|
-
ranges <<
|
113
|
+
ranges << (start_index...end_index)
|
113
114
|
break unless global
|
114
115
|
end
|
115
116
|
ret.cs__properties.delete_tags_at_ranges(ranges)
|
@@ -133,12 +134,11 @@ module Contrast
|
|
133
134
|
end
|
134
135
|
|
135
136
|
def pattern_gsub preshift, ret
|
136
|
-
return unless ret
|
137
|
+
return unless Contrast::Utils::DuckUtils.trackable?(ret)
|
137
138
|
|
138
139
|
source = preshift.object
|
139
140
|
source.cs__properties.tag_keys.each do |key|
|
140
|
-
|
141
|
-
ret.cs__properties.add_tag(key, span)
|
141
|
+
ret.cs__properties.add_tag(key, 0...1)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -28,23 +28,19 @@ module Contrast
|
|
28
28
|
else
|
29
29
|
remove_ranges = []
|
30
30
|
ret_chars = ret.chars
|
31
|
-
|
31
|
+
start = nil
|
32
32
|
source_chars.each_with_index do |char, idx|
|
33
33
|
if ret_chars[idx] == char
|
34
|
-
next unless
|
34
|
+
next unless start
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
curr_span = nil
|
36
|
+
remove_ranges << (start...idx)
|
37
|
+
start = nil
|
39
38
|
else
|
40
|
-
|
39
|
+
start ||= idx
|
41
40
|
end
|
42
41
|
end
|
43
42
|
# account for the last char being different
|
44
|
-
if
|
45
|
-
curr_span.stop = source_chars.length
|
46
|
-
remove_ranges << curr_span
|
47
|
-
end
|
43
|
+
remove_ranges << (start...source_chars.length) if start
|
48
44
|
ret.cs__properties.delete_tags_at_ranges(remove_ranges, false)
|
49
45
|
end
|
50
46
|
|
@@ -12,7 +12,6 @@ cs__scoped_require 'set'
|
|
12
12
|
|
13
13
|
cs__scoped_require 'contrast/utils/object_share'
|
14
14
|
cs__scoped_require 'contrast/utils/sha256_builder'
|
15
|
-
cs__scoped_require 'contrast/agent/assess/adjusted_span'
|
16
15
|
cs__scoped_require 'contrast/agent/assess/policy/source_validation/source_validation'
|
17
16
|
|
18
17
|
cs__scoped_require 'contrast/components/interface'
|
@@ -170,7 +169,7 @@ module Contrast
|
|
170
169
|
next unless Contrast::Agent::Assess::Policy::SourceValidation.valid?(tag, source_type, source_name)
|
171
170
|
|
172
171
|
length = Contrast::Utils::StringUtils.ret_length(target)
|
173
|
-
target.cs__properties.add_tag(tag,
|
172
|
+
target.cs__properties.add_tag(tag, 0...length)
|
174
173
|
target.cs__properties.add_properties(source_node.properties)
|
175
174
|
logger.trace('Source detected',
|
176
175
|
node_id: source_node.id,
|
@@ -0,0 +1,90 @@
|
|
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 Agent
|
6
|
+
module Assess
|
7
|
+
module Policy
|
8
|
+
module Trigger
|
9
|
+
# This acts a trigger to handle the special cases of the Tilt
|
10
|
+
# library gem. Reflected XSS data may come into the trigger methods
|
11
|
+
# from these classes.
|
12
|
+
class ReflectedXss
|
13
|
+
class << self
|
14
|
+
NODE_HASH = {
|
15
|
+
'class_name' => 'Tilt::Template',
|
16
|
+
'instance_method' => true,
|
17
|
+
'method_name' => 'render',
|
18
|
+
'method_visibility' => 'public',
|
19
|
+
'action' => 'CUSTOM',
|
20
|
+
'source' => 'O,P0',
|
21
|
+
'target' => 'R',
|
22
|
+
'patch_class' => 'Contrast::Agent::Assess::Policy::Trigger::ReflectedXss',
|
23
|
+
'patch_method' => 'xss_tilt_trigger'
|
24
|
+
}.cs__freeze
|
25
|
+
TEMPLATE_PROPAGATION_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(NODE_HASH)
|
26
|
+
|
27
|
+
def xss_tilt_trigger context, trigger_node, _source, object, ret, *args
|
28
|
+
scope = args[0]
|
29
|
+
|
30
|
+
erb_template_prerender = object.instance_variable_get(:@data)
|
31
|
+
interpolated_inputs = []
|
32
|
+
handle_binding_variables(scope, erb_template_prerender, ret, interpolated_inputs)
|
33
|
+
|
34
|
+
handle_local_variables(args, erb_template_prerender, ret, interpolated_inputs)
|
35
|
+
|
36
|
+
unless interpolated_inputs.empty?
|
37
|
+
interpolated_inputs.each do |input|
|
38
|
+
input.cs__properties.events.each do |event|
|
39
|
+
ret.cs__properties.events << event
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ret.cs__properties.build_event(TEMPLATE_PROPAGATION_NODE, ret, erb_template_prerender, ret, interpolated_inputs)
|
43
|
+
end
|
44
|
+
|
45
|
+
if ret.cs__tracked?
|
46
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(context, trigger_node, ret, erb_template_prerender, ret, interpolated_inputs)
|
47
|
+
end
|
48
|
+
|
49
|
+
ret
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def handle_binding_variables scope, erb_template_prerender, ret, interpolated_inputs
|
55
|
+
binding_variables = scope.instance_variables
|
56
|
+
|
57
|
+
binding_variables.each do |bound_variable_sym|
|
58
|
+
bound_variable_value = scope.instance_variable_get(bound_variable_sym)
|
59
|
+
|
60
|
+
next unless bound_variable_value.cs__respond_to?(:cs__tracked?) && bound_variable_value.cs__tracked?
|
61
|
+
next unless erb_template_prerender.include?(bound_variable_sym.to_s)
|
62
|
+
|
63
|
+
start_index = ret.index(bound_variable_value)
|
64
|
+
next if start_index.nil?
|
65
|
+
|
66
|
+
ret.cs__copy_from(bound_variable_value, start_index)
|
67
|
+
interpolated_inputs << bound_variable_sym
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def handle_local_variables args, erb_template_prerender, ret, interpolated_inputs
|
72
|
+
locals = args[1]
|
73
|
+
locals.each do |local_name, local_value|
|
74
|
+
next unless local_value.cs__respond_to?(:cs__tracked?) && local_value.cs__tracked?
|
75
|
+
next unless erb_template_prerender.include?(local_name.to_s)
|
76
|
+
|
77
|
+
start_index = ret.index(local_value)
|
78
|
+
next if start_index.nil?
|
79
|
+
|
80
|
+
ret.cs__copy_from(local_value, start_index)
|
81
|
+
interpolated_inputs << local_name
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -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/components/interface'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Assess
|
9
|
+
module Policy
|
10
|
+
module Trigger
|
11
|
+
# This acts a trigger to handle the special cases of the XPath
|
12
|
+
# library gem and the Oga gem. Untrusted data may come into the
|
13
|
+
# trigger methods from these classes as an array or hash,
|
14
|
+
# respectively. Since untrusted user input comes into these triggers
|
15
|
+
# as a splat argument or an options hash, we need to iterate through
|
16
|
+
# these objects to see if we were tracking on any of them and report
|
17
|
+
# a finding if so.
|
18
|
+
class Xpath
|
19
|
+
include Contrast::Components::Interface
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def xpath_expression_trigger context, trigger_node, _source, object, ret, *args
|
23
|
+
return ret unless args
|
24
|
+
|
25
|
+
process(context, trigger_node, object, ret, *args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def xpath_oga_trigger context, trigger_node, _source, object, ret, *args
|
29
|
+
return ret unless args
|
30
|
+
|
31
|
+
# convert the options arg in Oga::XML::CharacterNode#initialize into an
|
32
|
+
# array of its values so we can check if any are unsafe
|
33
|
+
args = args.first.values if args.first.cs__is_a?(Hash)
|
34
|
+
process(context, trigger_node, object, ret, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def process context, trigger_node, object, ret, *args
|
40
|
+
args.each do |arg|
|
41
|
+
next unless arg.cs__is_a?(String) || arg.cs__is_a?(Symbol)
|
42
|
+
next unless arg.cs__tracked?
|
43
|
+
next unless trigger_node.violated?(arg)
|
44
|
+
|
45
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
|
46
|
+
context, trigger_node, arg, object, ret, args)
|
47
|
+
end
|
48
|
+
|
49
|
+
ret
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|