contrast-agent 3.13.0 → 3.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/contrast_service +1 -7
- 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 +2 -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 +18 -16
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- 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 +31 -16
- data/ext/cs__assess_string/cs__assess_string.h +6 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
- data/ext/cs__common/cs__common.c +48 -39
- data/ext/cs__common/cs__common.h +16 -21
- 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/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +13 -23
- data/lib/contrast/agent.rb +39 -46
- data/lib/contrast/agent/assess.rb +12 -12
- data/lib/contrast/agent/assess/contrast_event.rb +151 -85
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +3 -3
- data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
- data/lib/contrast/agent/assess/policy/policy.rb +9 -11
- data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +9 -4
- data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
- 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/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
- data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +15 -5
- data/lib/contrast/agent/assess/property/evented.rb +7 -20
- data/lib/contrast/agent/assess/property/tagged.rb +13 -7
- data/lib/contrast/agent/assess/property/updated.rb +131 -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_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +84 -16
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +66 -0
- data/lib/contrast/agent/at_exit_hook.rb +6 -6
- data/lib/contrast/agent/class_reopener.rb +14 -11
- 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 +1 -1
- data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
- 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 +32 -32
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
- data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
- data/lib/contrast/agent/patching/policy/patch.rb +15 -15
- data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
- data/lib/contrast/agent/patching/policy/policy.rb +23 -12
- data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
- 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 +4 -4
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- 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 +4 -3
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- 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 +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- 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 +3 -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 +2 -2
- data/lib/contrast/agent/request.rb +45 -43
- data/lib/contrast/agent/request_context.rb +10 -6
- data/lib/contrast/agent/response.rb +23 -12
- data/lib/contrast/agent/rewriter.rb +6 -9
- data/lib/contrast/agent/service_heartbeat.rb +2 -2
- data/lib/contrast/agent/static_analysis.rb +9 -9
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +2 -2
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +4 -4
- data/lib/contrast/api/communication.rb +9 -9
- data/lib/contrast/api/communication/messaging_queue.rb +3 -6
- data/lib/contrast/api/communication/response_processor.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +41 -6
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/communication/tcp_socket.rb +1 -1
- data/lib/contrast/api/communication/unix_socket.rb +1 -1
- data/lib/contrast/api/decorators.rb +14 -14
- data/lib/contrast/api/decorators/address.rb +20 -19
- data/lib/contrast/api/decorators/application_settings.rb +3 -2
- data/lib/contrast/api/decorators/application_update.rb +7 -8
- data/lib/contrast/api/decorators/http_request.rb +13 -12
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- data/lib/contrast/api/decorators/message.rb +4 -2
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
- data/lib/contrast/api/decorators/route_coverage.rb +3 -2
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +28 -25
- data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
- data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
- data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
- data/lib/contrast/api/decorators/user_input.rb +4 -4
- data/lib/contrast/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +2 -2
- data/lib/contrast/components/app_context.rb +50 -39
- data/lib/contrast/components/config.rb +7 -17
- data/lib/contrast/components/contrast_service.rb +10 -10
- data/lib/contrast/components/interface.rb +15 -15
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/components/settings.rb +20 -23
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +93 -52
- data/lib/contrast/extension/assess.rb +21 -22
- data/lib/contrast/extension/assess/array.rb +18 -11
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
- data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
- data/lib/contrast/extension/assess/fiber.rb +14 -14
- data/lib/contrast/extension/assess/hash.rb +7 -6
- data/lib/contrast/extension/assess/kernel.rb +34 -28
- data/lib/contrast/extension/assess/marshal.rb +67 -0
- data/lib/contrast/extension/assess/regexp.rb +10 -9
- data/lib/contrast/extension/assess/string.rb +23 -23
- data/lib/contrast/extension/inventory.rb +4 -4
- 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 +4 -4
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +10 -11
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- 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 +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
- data/lib/contrast/framework/rails/patch/support.rb +4 -4
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +64 -14
- data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +6 -6
- data/lib/contrast/funchook/funchook.rb +1 -1
- data/lib/contrast/logger/application.rb +13 -5
- data/lib/contrast/logger/format.rb +22 -9
- data/lib/contrast/logger/log.rb +17 -10
- 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 +49 -4
- data/lib/contrast/utils/boolean_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +2 -2
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/gemfile_reader.rb +5 -5
- data/lib/contrast/utils/hash_digest.rb +2 -1
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
- data/lib/contrast/utils/inventory_util.rb +4 -4
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/os.rb +1 -1
- 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 -2
- data/lib/contrast/utils/string_utils.rb +11 -6
- data/resources/assess/policy.json +31 -22
- data/resources/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +21 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +67 -29
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/extension/assess/assess_extension.rb +0 -147
- data/lib/contrast/utils/freeze_util.rb +0 -32
@@ -1,49 +0,0 @@
|
|
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/prevent_serialization'
|
5
|
-
cs__scoped_require 'contrast/agent/assess/properties'
|
6
|
-
|
7
|
-
module Contrast
|
8
|
-
module Agent
|
9
|
-
module Assess
|
10
|
-
# This is just a wrapper around Properties so that if they are on a frozen
|
11
|
-
# object, they are left mutable for us.
|
12
|
-
class Insulator
|
13
|
-
# Return a new delegator with a properties method, used to track
|
14
|
-
# properties in a manner that won't be serialized.
|
15
|
-
#
|
16
|
-
# @return [SimpleDelegator<Object>]
|
17
|
-
def self.generate
|
18
|
-
delegator = SimpleDelegator.new(nil)
|
19
|
-
delegator.extend(Contrast::Utils::PreventPsychSerialization)
|
20
|
-
delegator
|
21
|
-
end
|
22
|
-
|
23
|
-
# Return the frozen properties delegator, which is a
|
24
|
-
#
|
25
|
-
# @return [SimpleDelegator<Object>]
|
26
|
-
def self.generate_frozen
|
27
|
-
@_generate_frozen ||= begin
|
28
|
-
delegator = SimpleDelegator.new(nil)
|
29
|
-
delegator.extend(Contrast::Utils::PreventPsychSerialization)
|
30
|
-
delegator
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Our patch of the SimpleDelegator class, allowing us to leverage its
|
39
|
-
# marshal_dump and marshal_load methods to hide our properties on an object so
|
40
|
-
# that they will not be dumped or loaded.
|
41
|
-
# We do this to prevent polluting data that may run on applications that are no
|
42
|
-
# longer instrumented with Contrast
|
43
|
-
class SimpleDelegator
|
44
|
-
# rubocop:disable Naming/MemoizedInstanceVariableName
|
45
|
-
def properties
|
46
|
-
@delegate_properties ||= Contrast::Agent::Assess::Properties.new
|
47
|
-
end
|
48
|
-
# rubocop:enable Naming/MemoizedInstanceVariableName
|
49
|
-
end
|
@@ -1,61 +0,0 @@
|
|
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
|
-
# Thread local way to access the current RequireState. Used as a convenient
|
7
|
-
# wrapper to ensure specific key is used and that we handle the case when
|
8
|
-
# we try to enter a previously unset require scope.
|
9
|
-
# (Note that 'require scopes' track nested requires. This is distinct
|
10
|
-
# from 'contrast scope', which tracks instrumentation.)
|
11
|
-
module RequireStates
|
12
|
-
class << self
|
13
|
-
KEY = :thread_local_contrast_require_scope
|
14
|
-
|
15
|
-
def enter
|
16
|
-
scope = current_scope
|
17
|
-
unless current_scope
|
18
|
-
scope = RequireState.new
|
19
|
-
Thread.current[KEY] = scope
|
20
|
-
end
|
21
|
-
scope.enter
|
22
|
-
end
|
23
|
-
|
24
|
-
def exit
|
25
|
-
current_scope.exit
|
26
|
-
end
|
27
|
-
|
28
|
-
def current_scope
|
29
|
-
Thread.current[KEY]
|
30
|
-
end
|
31
|
-
|
32
|
-
def status
|
33
|
-
current_scope&.scope.to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
def in_scope?
|
37
|
-
scope = current_scope
|
38
|
-
scope && scope.scope > 1
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Simple counter class for tracking how deep in nested requires / file
|
44
|
-
# load operations we currently are.
|
45
|
-
class RequireState
|
46
|
-
attr_reader :scope
|
47
|
-
|
48
|
-
def initialize
|
49
|
-
@scope = 0
|
50
|
-
end
|
51
|
-
|
52
|
-
def enter
|
53
|
-
@scope += 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def exit
|
57
|
-
@scope -= 1
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,147 +0,0 @@
|
|
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/agent/assess/properties'
|
5
|
-
cs__scoped_require 'contrast/agent/assess/insulator'
|
6
|
-
|
7
|
-
module Contrast
|
8
|
-
module Extension
|
9
|
-
module Assess
|
10
|
-
# This module is responsible for maintaining the data we need to
|
11
|
-
# construct a trace event for the object in which it is included. Rather
|
12
|
-
# than have this code all over the place, any class that wants to use
|
13
|
-
# dataflow features should be sent
|
14
|
-
# 'include Contrast::Extension::Assess::AssessExtension'
|
15
|
-
module AssessExtension
|
16
|
-
# Lazily build properties object. Only objects that have been tracked
|
17
|
-
# will have the @_cs__properties, but all will respond to the
|
18
|
-
# cs__properties method call. You should only call this method if you
|
19
|
-
# either intend to start tracking an object or you have already checked
|
20
|
-
# cs__tracked? and it is true.
|
21
|
-
def cs__properties
|
22
|
-
# If this object was tracked before being frozen, it'll have
|
23
|
-
# mutable properties we need inside of the insulator @_cs__properties
|
24
|
-
if cs__frozen?
|
25
|
-
if instance_variable_defined?(:@_cs__properties)
|
26
|
-
@_cs__properties.properties
|
27
|
-
else
|
28
|
-
Contrast::Agent::Assess::Insulator.generate_frozen.properties
|
29
|
-
end
|
30
|
-
else
|
31
|
-
@_cs__properties ||= Contrast::Agent::Assess::Insulator.generate
|
32
|
-
@_cs__properties.properties
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def cs__properties?
|
37
|
-
instance_variable_defined?(:@_cs__properties)
|
38
|
-
end
|
39
|
-
|
40
|
-
# This is a way to check if we are already tracking an object without
|
41
|
-
# adding tracking to it. If the object already has been tracked we will
|
42
|
-
# return the tracking state of its properties. If the object hasn't
|
43
|
-
# already been tracked we will return false without starting to track
|
44
|
-
# it
|
45
|
-
def cs__tracked?
|
46
|
-
cs__properties? && cs__properties.tracked?
|
47
|
-
end
|
48
|
-
|
49
|
-
def cs__reset_properties
|
50
|
-
return unless cs__properties?
|
51
|
-
|
52
|
-
@_cs__properties = nil
|
53
|
-
end
|
54
|
-
|
55
|
-
# copy tags and info from object to self if object support methods
|
56
|
-
# obj: the object from which to copy tags and events
|
57
|
-
# shift: how far to shift the tags, negative moves left
|
58
|
-
# skip_tags: array of tags to skip copying
|
59
|
-
def cs__copy_from obj, shift = 0, skip_tags = nil
|
60
|
-
return if obj.equal?(self)
|
61
|
-
return unless Contrast::Utils::DuckUtils.quacks_to?(obj,
|
62
|
-
:cs__tracked?)
|
63
|
-
return unless obj.cs__tracked?
|
64
|
-
return if cs__properties == Contrast::Agent::Assess::Insulator.generate_frozen.properties
|
65
|
-
|
66
|
-
# This was fun to find...
|
67
|
-
# the clone and dup methods don't apply to instance variables in the
|
68
|
-
# cloned/ duped thing, so the arrays in the properties were the same.
|
69
|
-
# The most infinite of infinite loops ensued.
|
70
|
-
# DO NOT TAKE THIS OUT!
|
71
|
-
cs__reset_properties if obj.cs__properties == cs__properties
|
72
|
-
|
73
|
-
obj.cs__properties.events.each do |event|
|
74
|
-
cs__properties.events << event
|
75
|
-
end
|
76
|
-
|
77
|
-
obj.cs__properties.tag_keys.each do |key|
|
78
|
-
next if skip_tags&.include?(key)
|
79
|
-
|
80
|
-
new_tags = []
|
81
|
-
value = obj.cs__properties.fetch_tag(key)
|
82
|
-
value.each do |tag|
|
83
|
-
new_tags << tag.copy_modified(shift)
|
84
|
-
end
|
85
|
-
existing = cs__properties.fetch_tag(key)
|
86
|
-
if existing
|
87
|
-
existing.concat(new_tags)
|
88
|
-
Contrast::Utils::TagUtil.size_aware_merge(self, existing)
|
89
|
-
else
|
90
|
-
cs__properties.set_tags(key, new_tags)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# Some propagation occurred, but we're not sure what the
|
96
|
-
# exact transformation was. To be safe, we just explode
|
97
|
-
# all the tags from the source to the return.
|
98
|
-
#
|
99
|
-
# If the return already had that tag, the existing tag
|
100
|
-
# range is recycled to save us an object.
|
101
|
-
def cs__splat_tags ret, source = self
|
102
|
-
return unless Contrast::Utils::DuckUtils.trackable?(ret)
|
103
|
-
|
104
|
-
length = Contrast::Utils::StringUtils.ret_length(ret)
|
105
|
-
return if length.zero?
|
106
|
-
|
107
|
-
cs__splat_from_source(ret, length, source)
|
108
|
-
cs__splat_from_ret(ret, length)
|
109
|
-
end
|
110
|
-
|
111
|
-
def cs__splat_from_source ret, ret_length, source
|
112
|
-
splat_source = Contrast::Utils::DuckUtils.trackable?(source)
|
113
|
-
splat_source &&= source.cs__tracked?
|
114
|
-
return unless splat_source
|
115
|
-
|
116
|
-
source.cs__properties.tag_keys.each do |key|
|
117
|
-
existing = ret.cs__properties.fetch_tag(key)
|
118
|
-
# if the tag already exists, drop all but the first range
|
119
|
-
# then change that range to cover the entire return
|
120
|
-
if existing
|
121
|
-
existing.drop(existing.length - 1)
|
122
|
-
range = existing[0]
|
123
|
-
range.repurpose(0, ret_length)
|
124
|
-
else
|
125
|
-
ret.cs__properties.add_tag(key, 0...ret_length)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def cs__splat_from_ret ret, length
|
131
|
-
return unless ret.cs__tracked?
|
132
|
-
|
133
|
-
ret.cs__properties.tag_keys.each do |key|
|
134
|
-
next unless key
|
135
|
-
|
136
|
-
existing = ret.cs__properties.fetch_tag(key)
|
137
|
-
next unless existing
|
138
|
-
|
139
|
-
existing.each do |range|
|
140
|
-
range.update_end(length) if range.end_idx > length
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,32 +0,0 @@
|
|
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/duck_utils'
|
5
|
-
|
6
|
-
module Contrast
|
7
|
-
module Utils
|
8
|
-
# This utility allows us to act on frozen objects, creating an unfrozen
|
9
|
-
# duplicate in those cases where that is possible.
|
10
|
-
class FreezeUtil
|
11
|
-
class << self
|
12
|
-
# Make every attempt to duplicate the frozen object so that it can
|
13
|
-
# be tracked.
|
14
|
-
#
|
15
|
-
# @param original [Object] something frozen, usually a String
|
16
|
-
# @return [Object] the original or an unfrozen copy
|
17
|
-
def unfreeze_dup original
|
18
|
-
return original unless original.cs__frozen?
|
19
|
-
|
20
|
-
copy = original.dup
|
21
|
-
if Contrast::Utils::DuckUtils.iterable_hash?(copy)
|
22
|
-
copy.each_key do |key|
|
23
|
-
value = original[key]
|
24
|
-
copy[key] = value.dup
|
25
|
-
end
|
26
|
-
end
|
27
|
-
copy
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|