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,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/contrast_event'
|
5
|
+
require 'contrast/agent/assess/events/source_event'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
@@ -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/contrast_event'
|
5
|
+
require 'contrast/utils/string_utils'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
@@ -65,15 +65,11 @@ module Contrast
|
|
65
65
|
# 2) I'll set the event's source and target to TS values.
|
66
66
|
# 3) Return the highlight or the first source/target as the taint
|
67
67
|
# target.
|
68
|
-
def determine_taint_target
|
68
|
+
def determine_taint_target event_dtm
|
69
69
|
return unless @policy_node&.targets&.any?
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
"P#{ @highlight }"
|
74
|
-
else
|
75
|
-
@policy_node.target_string
|
76
|
-
end
|
71
|
+
event_dtm.source = @policy_node.source_string if @policy_node.source_string
|
72
|
+
event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
|
77
73
|
@highlight || @policy_node.targets[0]
|
78
74
|
end
|
79
75
|
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
require 'contrast/agent/assess/finalizers/hash'
|
5
|
+
require 'contrast/agent/assess/finalizers/freeze'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Agent
|
9
|
+
module Assess
|
10
|
+
module Finalizers
|
11
|
+
# Our module for handling finalizing, allowing for the tracking of
|
12
|
+
# Objects without impacting GC and causing a memory leak. Access to any
|
13
|
+
# Finalizers object should run through this module as the Finalizers
|
14
|
+
# have tightly coupled dependencies on each other.
|
15
|
+
module Finalize
|
16
|
+
PROPERTIES_HASH = Contrast::Agent::Assess::Finalizers::Hash.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
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
|
+
# Our patch of the Object#freeze method, allowing any Object we track to
|
5
|
+
# function with our Contrast::Agent::Assess::Finalizers::Hash
|
6
|
+
class Object
|
7
|
+
alias_method :cs__patched_object_freeze, :freeze
|
8
|
+
|
9
|
+
def freeze
|
10
|
+
Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH.pre_freeze(self)
|
11
|
+
cs__patched_object_freeze
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
require 'contrast/utils/duck_utils'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Assess
|
9
|
+
module Finalizers
|
10
|
+
# An extension of Hash that doesn't impact GC of the object being
|
11
|
+
# stored by storing its ID as a Key to lookup and registering a
|
12
|
+
# finalizer on the object to remove its entry from the Hash immediately
|
13
|
+
# after it's GC'd.
|
14
|
+
class Hash < Hash
|
15
|
+
FROZEN_FINALIZED_IDS = Set.new
|
16
|
+
|
17
|
+
def []= key, obj
|
18
|
+
# We can't finalize frozen things, so only act on those that went
|
19
|
+
# through .pre_freeze
|
20
|
+
if key.cs__frozen?
|
21
|
+
return unless FROZEN_FINALIZED_IDS.include?(key.__id__)
|
22
|
+
else
|
23
|
+
ObjectSpace.define_finalizer(key, finalize(key.__id__))
|
24
|
+
end
|
25
|
+
super key.__id__, obj
|
26
|
+
end
|
27
|
+
|
28
|
+
def [] key
|
29
|
+
super key.__id__
|
30
|
+
end
|
31
|
+
|
32
|
+
def finalize key_id
|
33
|
+
proc do
|
34
|
+
FROZEN_FINALIZED_IDS.delete(key_id)
|
35
|
+
delete(key_id)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def pre_freeze key
|
40
|
+
return if key.cs__frozen?
|
41
|
+
return if FROZEN_FINALIZED_IDS.include?(key.__id__)
|
42
|
+
return unless Contrast::Utils::DuckUtils.trackable?(key)
|
43
|
+
|
44
|
+
ObjectSpace.define_finalizer(key, finalize(key.__id__))
|
45
|
+
FROZEN_FINALIZED_IDS << key.__id__
|
46
|
+
rescue StandardError => _e
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/agent/patching/policy/method_policy'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -20,7 +20,7 @@ module Contrast
|
|
20
20
|
# such that calls to that method will result in a Source Event.
|
21
21
|
#
|
22
22
|
# @param klass [Class] the Class to taint
|
23
|
-
# @param tainted_columns [Hash
|
23
|
+
# @param tainted_columns [Hash{String => Contrast::Agent::Assess::Properties}]
|
24
24
|
# the name of the method to taint, mapped to the properties it
|
25
25
|
# should apply
|
26
26
|
def create_sources klass, tainted_columns
|
@@ -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/policy/policy'
|
5
|
+
require 'contrast/agent/patching/policy/patcher'
|
6
|
+
require 'contrast/agent/patching/policy/method_policy'
|
7
|
+
require 'contrast/agent/patching/policy/module_policy'
|
8
|
+
require 'contrast/components/interface'
|
9
9
|
|
10
10
|
module Contrast
|
11
11
|
module Agent
|
@@ -1,15 +1,15 @@
|
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
require 'json'
|
5
|
+
require 'contrast/agent/assess/rule/provider/hardcoded_value_rule'
|
6
|
+
require 'contrast/agent/assess/rule/provider/hardcoded_key'
|
7
|
+
require 'contrast/agent/assess/rule/provider/hardcoded_password'
|
8
|
+
require 'contrast/agent/assess/policy/policy_node'
|
9
|
+
require 'contrast/agent/assess/policy/source_node'
|
10
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
11
|
+
require 'contrast/agent/assess/policy/trigger_node'
|
12
|
+
require 'contrast/agent/patching/policy/policy'
|
13
13
|
|
14
14
|
module Contrast
|
15
15
|
module Agent
|
@@ -1,7 +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
|
-
|
4
|
+
require 'contrast/agent/patching/policy/policy_node'
|
5
|
+
require 'contrast/api/decorators/trace_taint_range_tags'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Agent
|
@@ -69,7 +70,7 @@ module Contrast
|
|
69
70
|
# 1) Split on ','
|
70
71
|
# 2) If 'O', add the source, else it's P (we don't have R sources) and
|
71
72
|
# needs to be converted. P type will either be P:name or P# where #
|
72
|
-
# is the index of the
|
73
|
+
# is the index of the parameter. Drop the P and store the int as int
|
73
74
|
# or name as symbol
|
74
75
|
def generate_sources
|
75
76
|
if source_string
|
@@ -137,7 +138,8 @@ module Contrast
|
|
137
138
|
return unless tags
|
138
139
|
|
139
140
|
tags.each do |tag|
|
140
|
-
next if VALID_TAGS.include?(tag) ||
|
141
|
+
next if Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
|
142
|
+
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
|
141
143
|
|
142
144
|
raise(ArgumentError,
|
143
145
|
"#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
|
@@ -173,102 +175,6 @@ module Contrast
|
|
173
175
|
@event_action
|
174
176
|
end
|
175
177
|
|
176
|
-
# EventTagTypeDTM
|
177
|
-
VALID_TAGS = %w[
|
178
|
-
XML_ENCODED
|
179
|
-
XML_DECODED
|
180
|
-
HTML_ENCODED
|
181
|
-
HTML_DECODED
|
182
|
-
URL_ENCODED
|
183
|
-
URL_DECODED
|
184
|
-
CSS_ENCODED
|
185
|
-
CSS_DECODED
|
186
|
-
BASE64_ENCODED
|
187
|
-
BASE64_DECODED
|
188
|
-
JAVASCRIPT_ENCODED
|
189
|
-
JAVASCRIPT_DECODED
|
190
|
-
JAVA_ENCODED
|
191
|
-
JAVA_DECODED
|
192
|
-
CSV_ENCODED
|
193
|
-
CSV_DECODED
|
194
|
-
SQL_ENCODED
|
195
|
-
SQL_DECODED
|
196
|
-
LDAP_ENCODED
|
197
|
-
LDAP_DECODED
|
198
|
-
XPATH_ENCODED
|
199
|
-
XPATH_DECODED
|
200
|
-
OS_ENCODED
|
201
|
-
OS_DECODED
|
202
|
-
VBSCRIPT_ENCODED
|
203
|
-
VBSCRIPT_DECODED
|
204
|
-
POTENTIAL_SANITIZED
|
205
|
-
POTENTIAL_VALIDATED
|
206
|
-
NO_CONTROL_CHARS
|
207
|
-
CUSTOM
|
208
|
-
|
209
|
-
CUSTOM_ENCODED
|
210
|
-
CUSTOM_ENCODED_CMD_INJECTION
|
211
|
-
CUSTOM_ENCODED_EXPRESSION_LANGUAGE_INJECTION
|
212
|
-
CUSTOM_ENCODED_HEADER_INJECTION
|
213
|
-
CUSTOM_ENCODED_HQL_INJECTION
|
214
|
-
CUSTOM_ENCODED_LDAP_INJECTION
|
215
|
-
CUSTOM_ENCODED_LOG_INJECTION
|
216
|
-
CUSTOM_ENCODED_NOSQL_INJECTION
|
217
|
-
CUSTOM_ENCODED_PATH_TRAVERSAL
|
218
|
-
CUSTOM_ENCODED_REDOS
|
219
|
-
CUSTOM_ENCODED_REFLECTED_XSS
|
220
|
-
CUSTOM_ENCODED_REFLECTION_INJECTION
|
221
|
-
CUSTOM_ENCODED_SMTP_INJECTION
|
222
|
-
CUSTOM_ENCODED_SQL_INJECTION
|
223
|
-
CUSTOM_ENCODED_SSRF
|
224
|
-
CUSTOM_ENCODED_STORED_XSS
|
225
|
-
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION
|
226
|
-
CUSTOM_ENCODED_UNSAFE_CODE_EXECUTION
|
227
|
-
CUSTOM_ENCODED_UNSAFE_READLINE
|
228
|
-
CUSTOM_ENCODED_UNSAFE_XML_DECODE
|
229
|
-
CUSTOM_ENCODED_UNTRUSTED_DESERIALIZATION
|
230
|
-
CUSTOM_ENCODED_UNVALIDATED_FORWARD
|
231
|
-
CUSTOM_ENCODED_UNVALIDATED_REDIRECT
|
232
|
-
CUSTOM_ENCODED_XPATH_INJECTION
|
233
|
-
CUSTOM_ENCODED_XXE
|
234
|
-
CUSTOM_SECURITY_CONTROL_APPLIED
|
235
|
-
|
236
|
-
CUSTOM_VALIDATED
|
237
|
-
CUSTOM_VALIDATED_CMD_INJECTION
|
238
|
-
CUSTOM_VALIDATED_EXPRESSION_LANGUAGE_INJECTION
|
239
|
-
CUSTOM_VALIDATED_HEADER_INJECTION
|
240
|
-
CUSTOM_VALIDATED_HQL_INJECTION
|
241
|
-
CUSTOM_VALIDATED_LDAP_INJECTION
|
242
|
-
CUSTOM_VALIDATED_LOG_INJECTION
|
243
|
-
CUSTOM_VALIDATED_NOSQL_INJECTION
|
244
|
-
CUSTOM_VALIDATED_PATH_TRAVERSAL
|
245
|
-
CUSTOM_VALIDATED_REDOS
|
246
|
-
CUSTOM_VALIDATED_REFLECTED_XSS
|
247
|
-
CUSTOM_VALIDATED_REFLECTION_INJECTION
|
248
|
-
CUSTOM_VALIDATED_SMTP_INJECTION
|
249
|
-
CUSTOM_VALIDATED_SQL_INJECTION
|
250
|
-
CUSTOM_VALIDATED_SSRF
|
251
|
-
CUSTOM_VALIDATED_STORED_XSS
|
252
|
-
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION
|
253
|
-
CUSTOM_VALIDATED_UNSAFE_CODE_EXECUTION
|
254
|
-
CUSTOM_VALIDATED_UNSAFE_READLINE
|
255
|
-
CUSTOM_VALIDATED_UNSAFE_XML_DECODE
|
256
|
-
CUSTOM_VALIDATED_UNTRUSTED_DESERIALIZATION
|
257
|
-
CUSTOM_VALIDATED_UNVALIDATED_FORWARD
|
258
|
-
CUSTOM_VALIDATED_UNVALIDATED_REDIRECT
|
259
|
-
CUSTOM_VALIDATED_XPATH_INJECTION
|
260
|
-
CUSTOM_VALIDATED_XXE
|
261
|
-
|
262
|
-
DATABASE_WRITE
|
263
|
-
].cs__freeze
|
264
|
-
|
265
|
-
VALID_SOURCE_TAGS = %w[
|
266
|
-
NO_NEWLINES
|
267
|
-
UNTRUSTED
|
268
|
-
CROSS_SITE
|
269
|
-
LIMITED_CHARS
|
270
|
-
].cs__freeze
|
271
|
-
|
272
178
|
# The keys used to read from policy.json to create the individual
|
273
179
|
# policy nodes. These are common across node types
|
274
180
|
JSON_SOURCE = 'source'
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
|
+
require 'contrast/extension/assess/assess_extension'
|
6
|
+
require 'contrast/utils/object_share'
|
7
7
|
|
8
8
|
module Contrast
|
9
9
|
module Agent
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -69,21 +69,31 @@ module Contrast
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def append_object_details preshift, initializing, object
|
72
|
-
|
73
|
-
preshift.object
|
72
|
+
can = can_dup?(initializing, object)
|
73
|
+
preshift.object = can ? object.dup : object
|
74
74
|
preshift.object_length = if Contrast::Utils::DuckUtils.quacks_to?(preshift.object, :length)
|
75
75
|
object.length
|
76
76
|
else
|
77
77
|
0
|
78
78
|
end
|
79
|
+
return unless can
|
80
|
+
|
81
|
+
props = Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[object]
|
82
|
+
return unless props
|
83
|
+
|
84
|
+
Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[preshift.object] ||= props.dup
|
79
85
|
end
|
80
86
|
|
81
87
|
def append_arg_details preshift, args
|
82
88
|
preshift.args = args.dup
|
83
89
|
preshift.args.each_with_index do |arg, index|
|
84
|
-
|
90
|
+
original_arg = args[index]
|
91
|
+
next if arg.__id__ == original_arg.__id__
|
92
|
+
|
93
|
+
props = Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[original_arg]
|
94
|
+
next unless props
|
85
95
|
|
86
|
-
arg.
|
96
|
+
Contrast::Agent::Assess::Finalizers::Finalize::PROPERTIES_HASH[arg] ||= props.dup
|
87
97
|
end
|
88
98
|
preshift.arg_lengths = preshift.args.map { |arg| Contrast::Utils::DuckUtils.quacks_to?(arg, :length) ? arg.length : 0 }
|
89
99
|
end
|
@@ -1,24 +1,21 @@
|
|
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
|
-
# method that transforms an untrusted value. In general, these methods work on
|
6
|
-
# the String class or a holder of Strings
|
7
|
-
cs__scoped_require 'set'
|
4
|
+
require 'set'
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
cs__scoped_require 'contrast/components/interface'
|
6
|
+
require 'contrast/agent/assess/policy/propagator'
|
7
|
+
require 'contrast/components/interface'
|
8
|
+
require 'contrast/utils/object_share'
|
9
|
+
require 'contrast/utils/sha256_builder'
|
15
10
|
|
16
11
|
module Contrast
|
17
12
|
module Agent
|
18
13
|
module Assess
|
19
14
|
module Policy
|
20
|
-
# This
|
21
|
-
#
|
15
|
+
# This class is responsible for the continuation of traces. A
|
16
|
+
# Propagator is any method that transforms an untrusted value. In
|
17
|
+
# general, these methods work on the String class or a holder of
|
18
|
+
# Strings
|
22
19
|
module PropagationMethod
|
23
20
|
include Contrast::Components::Interface
|
24
21
|
access_component :logging
|
@@ -174,15 +171,7 @@ module Contrast
|
|
174
171
|
# If the source of this patcher is not tracked, there's no need to do
|
175
172
|
# anything. A copy of nothing is still nothing.
|
176
173
|
def can_propagate? propagation_node, preshift, target
|
177
|
-
|
178
|
-
return false unless Contrast::Utils::DuckUtils.quacks_to?(target, :cs__properties)
|
179
|
-
|
180
|
-
# We cannot propagate to frozen things that have not been
|
181
|
-
# previously tracked. We probably shouldn't propagate to frozen
|
182
|
-
# things at all, as they're supposed to be immutable, but third
|
183
|
-
# parties do jenky things, so allow it as long as it is safe to do.
|
184
|
-
return false if target.cs__properties == Contrast::Agent::Assess::Insulator.generate_frozen.properties &&
|
185
|
-
propagation_node.targets[0] != Contrast::Utils::ObjectShare::RETURN_KEY
|
174
|
+
return false unless appropriate_target?(propagation_node, target)
|
186
175
|
return true if Contrast::Utils::Assess::TrackingUtil.tracked?(target)
|
187
176
|
return false unless preshift
|
188
177
|
|
@@ -197,14 +186,28 @@ module Contrast
|
|
197
186
|
false
|
198
187
|
end
|
199
188
|
|
189
|
+
def appropriate_target? propagation_node, target
|
190
|
+
# We cannot propagate to things that do not have cs__properties.
|
191
|
+
return false unless Contrast::Utils::DuckUtils.quacks_to?(target, :cs__properties)
|
192
|
+
|
193
|
+
# We cannot propagate to frozen things that have not been
|
194
|
+
# previously tracked. We probably shouldn't propagate to frozen
|
195
|
+
# things at all, as they're supposed to be immutable, but third
|
196
|
+
# parties do jenky things, so allow it as long as it is safe to do.
|
197
|
+
return false if target.cs__frozen? &&
|
198
|
+
!target.cs__tracked? &&
|
199
|
+
propagation_node.targets[0] != Contrast::Utils::ObjectShare::RETURN_KEY
|
200
|
+
|
201
|
+
true
|
202
|
+
end
|
203
|
+
|
200
204
|
# If this patcher has tags, apply them to the entire target
|
201
205
|
def apply_tags propagation_node, target
|
202
206
|
return unless propagation_node.tags
|
203
207
|
|
204
208
|
length = Contrast::Utils::StringUtils.ret_length(target)
|
205
209
|
propagation_node.tags.each do |tag|
|
206
|
-
|
207
|
-
target.cs__properties.add_tag(tag, span)
|
210
|
+
target.cs__properties.add_tag(tag, 0...length)
|
208
211
|
end
|
209
212
|
end
|
210
213
|
|
@@ -264,7 +267,6 @@ module Contrast
|
|
264
267
|
ret = Contrast::Utils::FreezeUtil.unfreeze_dup(target)
|
265
268
|
target = ret
|
266
269
|
end
|
267
|
-
return if target.cs__properties == Contrast::Agent::Assess::Insulator.generate_frozen.properties
|
268
270
|
|
269
271
|
propagation_class.propagate(propagation_node, preshift, target)
|
270
272
|
|