contrast-agent 5.1.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cs__assess_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -5
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +7 -7
- data/ext/cs__assess_string/cs__assess_string.c +13 -1
- data/ext/cs__common/cs__common.c +16 -11
- data/ext/cs__common/cs__common.h +1 -0
- data/ext/cs__contrast_patch/cs__contrast_patch.c +100 -64
- data/ext/cs__contrast_patch/cs__contrast_patch.h +2 -0
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +796 -0
- data/ext/cs__scope/cs__scope.h +88 -0
- data/ext/cs__scope/extconf.rb +5 -0
- data/lib/contrast/agent/assess/contrast_event.rb +20 -13
- data/lib/contrast/agent/assess/contrast_object.rb +4 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -5
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -0
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
- data/lib/contrast/agent/assess/policy/trigger_method.rb +6 -1
- data/lib/contrast/agent/assess/property/tagged.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/{autocomplete_rule.rb → auto_complete_rule.rb} +4 -3
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +12 -79
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +109 -0
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +157 -0
- data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +26 -0
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +14 -15
- data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +5 -25
- data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +29 -0
- data/lib/contrast/agent/assess/rule/response/header_rule.rb +70 -0
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +12 -36
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +2 -1
- data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +26 -0
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +35 -0
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
- data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/middleware.rb +4 -1
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +1 -3
- data/lib/contrast/agent/patching/policy/patch.rb +2 -6
- data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
- data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +147 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
- data/lib/contrast/agent/protect/rule/base.rb +61 -2
- data/lib/contrast/agent/protect/rule/base_service.rb +12 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +15 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
- data/lib/contrast/agent/protect/rule/deserialization.rb +6 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +13 -1
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +88 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +118 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +33 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +4 -0
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +44 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +115 -0
- data/lib/contrast/agent/reporting/input_analysis/input_type.rb +44 -0
- data/lib/contrast/agent/reporting/input_analysis/score_level.rb +21 -0
- data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
- data/lib/contrast/agent/reporting/report.rb +3 -0
- data/lib/contrast/agent/reporting/reporter.rb +31 -12
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +69 -36
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +88 -59
- data/lib/contrast/agent/reporting/reporting_events/{finding_object.rb → finding_event_object.rb} +24 -20
- data/lib/contrast/agent/reporting/reporting_events/finding_event_parent_object.rb +39 -0
- data/lib/contrast/agent/reporting/reporting_events/finding_event_property.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/{finding_signature.rb → finding_event_signature.rb} +29 -24
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +12 -8
- data/lib/contrast/agent/reporting/reporting_events/{finding_stack.rb → finding_event_stack.rb} +23 -19
- data/lib/contrast/agent/reporting/reporting_events/{finding_taint_range.rb → finding_event_taint_range.rb} +17 -15
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +26 -53
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +29 -0
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +6 -4
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +1 -0
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +10 -3
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +17 -5
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -45
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +69 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +123 -85
- data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
- data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
- data/lib/contrast/agent/request_context.rb +7 -2
- data/lib/contrast/agent/request_context_extend.rb +85 -21
- data/lib/contrast/agent/request_handler.rb +4 -0
- data/lib/contrast/agent/scope.rb +102 -107
- data/lib/contrast/agent/service_heartbeat.rb +45 -2
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
- data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
- data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
- data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
- data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
- data/lib/contrast/agent/thread_watcher.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +3 -0
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/bot_blocker.rb +37 -0
- data/lib/contrast/api/decorators/ip_denylist.rb +37 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
- data/lib/contrast/api/decorators/response_type.rb +30 -0
- data/lib/contrast/api/decorators/user_input.rb +11 -1
- data/lib/contrast/api/decorators/virtual_patch.rb +34 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/logger.rb +5 -0
- data/lib/contrast/components/protect.rb +6 -4
- data/lib/contrast/components/sampling.rb +7 -11
- data/lib/contrast/components/scope.rb +98 -91
- data/lib/contrast/components/settings.rb +106 -8
- data/lib/contrast/config/agent_configuration.rb +41 -12
- data/lib/contrast/config/api_configuration.rb +37 -12
- data/lib/contrast/config/api_proxy_configuration.rb +12 -3
- data/lib/contrast/config/application_configuration.rb +38 -14
- data/lib/contrast/config/assess_configuration.rb +47 -12
- data/lib/contrast/config/assess_rules_configuration.rb +15 -3
- data/lib/contrast/config/base_configuration.rb +18 -50
- data/lib/contrast/config/certification_configuration.rb +17 -3
- data/lib/contrast/config/exception_configuration.rb +14 -3
- data/lib/contrast/config/heap_dump_configuration.rb +43 -17
- data/lib/contrast/config/inventory_configuration.rb +17 -3
- data/lib/contrast/config/logger_configuration.rb +10 -3
- data/lib/contrast/config/protect_configuration.rb +17 -7
- data/lib/contrast/config/protect_rule_configuration.rb +17 -8
- data/lib/contrast/config/protect_rules_configuration.rb +115 -17
- data/lib/contrast/config/request_audit_configuration.rb +26 -3
- data/lib/contrast/config/root_configuration.rb +52 -12
- data/lib/contrast/config/ruby_configuration.rb +60 -22
- data/lib/contrast/config/sampling_configuration.rb +19 -9
- data/lib/contrast/config/server_configuration.rb +19 -10
- data/lib/contrast/config/service_configuration.rb +27 -11
- data/lib/contrast/configuration.rb +5 -3
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/manager.rb +2 -2
- data/lib/contrast/logger/application.rb +1 -1
- data/lib/contrast/logger/cef_log.rb +151 -0
- data/lib/contrast/tasks/config.rb +90 -3
- data/lib/contrast/utils/assess/object_store.rb +36 -0
- data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
- data/lib/contrast/utils/class_util.rb +3 -12
- data/lib/contrast/utils/hash_digest.rb +14 -6
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/log_utils.rb +114 -0
- data/lib/contrast/utils/middleware_utils.rb +9 -9
- data/lib/contrast/utils/net_http_base.rb +13 -10
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +0 -5
- data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -9
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/telemetry.rb +1 -1
- data/lib/contrast/utils/telemetry_client.rb +1 -1
- data/lib/contrast/utils/telemetry_identifier.rb +1 -1
- data/lib/contrast.rb +4 -3
- data/resources/assess/policy.json +98 -0
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +9 -8
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +103 -38
- data/lib/contrast/agent/assess/rule/response/cachecontrol_rule.rb +0 -184
- data/lib/contrast/agent/assess/rule/response/clickjacking_rule.rb +0 -66
- data/lib/contrast/agent/assess/rule/response/x_content_type_rule.rb +0 -52
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_rule.rb +0 -53
- data/lib/contrast/extension/kernel.rb +0 -54
@@ -0,0 +1,88 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
/* Calls to Contrast modules and classes */
|
4
|
+
VALUE scope_interface;
|
5
|
+
VALUE scope_inst_methods, scope_mod, scope_klass;
|
6
|
+
|
7
|
+
/* IVs */
|
8
|
+
static VALUE rb_iv_cntr_scope;
|
9
|
+
static VALUE rb_iv_dslr_scope;
|
10
|
+
static VALUE rb_iv_split_scope;
|
11
|
+
|
12
|
+
/* Constants */
|
13
|
+
static VALUE rb_const_ec;
|
14
|
+
static VALUE rb_const_mon;
|
15
|
+
static VALUE rb_const_ec_keys;
|
16
|
+
|
17
|
+
/* Symbols */
|
18
|
+
static VALUE rb_sym_scope_mod;
|
19
|
+
static VALUE rb_sym_contrast;
|
20
|
+
static VALUE rb_sym_deserialization;
|
21
|
+
static VALUE rb_sym_split;
|
22
|
+
|
23
|
+
/* methods names - only reusable ones */
|
24
|
+
VALUE rb_method_name_init;
|
25
|
+
VALUE rb_method_name_in_scope;
|
26
|
+
VALUE rb_method_name_enter_scope;
|
27
|
+
VALUE rb_method_name_exit_scope;
|
28
|
+
VALUE rb_method_name_scope_for_current_ec;
|
29
|
+
VALUE rb_method_name_in_cntr_scope;
|
30
|
+
VALUE rb_method_name_enter_cntr_scope;
|
31
|
+
VALUE rb_method_name_exit_cntr_scope;
|
32
|
+
VALUE rb_method_name_in_dslr_scope;
|
33
|
+
VALUE rb_method_name_enter_dslr_scope;
|
34
|
+
VALUE rb_method_name_exit_dslr_scope;
|
35
|
+
VALUE rb_method_name_in_split_scope;
|
36
|
+
VALUE rb_method_name_enter_split_scope;
|
37
|
+
VALUE rb_method_name_exit_split_scope;
|
38
|
+
VALUE rb_method_name_split_scope_depth;
|
39
|
+
|
40
|
+
/* Scope class */
|
41
|
+
VALUE contrast_scope_klass_init(VALUE self, VALUE args);
|
42
|
+
VALUE in_cntr_scope(VALUE self, VALUE args);
|
43
|
+
VALUE enter_cntr_scope(VALUE self, VALUE args);
|
44
|
+
VALUE exit_cntr_scope(VALUE self, VALUE args);
|
45
|
+
VALUE in_split_scope(VALUE self, VALUE args);
|
46
|
+
VALUE enter_split_scope(VALUE self, VALUE args);
|
47
|
+
VALUE exit_split_scope(VALUE self, VALUE args);
|
48
|
+
VALUE split_scope_depth(VALUE self, VALUE args);
|
49
|
+
VALUE in_dsrl_scope_scope(VALUE self, VALUE args);
|
50
|
+
VALUE enter_dsrl_scope(VALUE self, VALUE args);
|
51
|
+
VALUE exit_dsrl_scope(VALUE self, VALUE args);
|
52
|
+
VALUE scope_klass_in_scope(VALUE self, VALUE method_scope_sym);
|
53
|
+
VALUE scope_klass_enter_scope(VALUE self, VALUE method_scope_sym);
|
54
|
+
VALUE scope_klass_exit_scope(VALUE self, VALUE method_scope_sym);
|
55
|
+
|
56
|
+
/* Scope interface */
|
57
|
+
VALUE contrast_scope_interface_init(VALUE self, VALUE args);
|
58
|
+
VALUE contrast_scope_for_current_ec(VALUE self, VALUE args);
|
59
|
+
|
60
|
+
/* Scope instance methods */
|
61
|
+
VALUE inst_methods_in_cntr_scope(VALUE self, VALUE args);
|
62
|
+
VALUE inst_methods_enter_cntr_scope(VALUE self, VALUE args);
|
63
|
+
VALUE inst_methods_exit_cntr_scope(VALUE self, VALUE args);
|
64
|
+
VALUE inst_methods_in_split_scope(VALUE self, VALUE args);
|
65
|
+
VALUE inst_methods_enter_split_scope(VALUE self, VALUE args);
|
66
|
+
VALUE inst_methods_exit_split_scope(VALUE self, VALUE args);
|
67
|
+
VALUE inst_methods_split_scope_depth(VALUE self, VALUE args);
|
68
|
+
VALUE inst_methods_in_dsrl_scope(VALUE self, VALUE args);
|
69
|
+
VALUE inst_methods_enter_dsrl_scope(VALUE self, VALUE args);
|
70
|
+
VALUE inst_methods_exit_dsrl_scope(VALUE self, VALUE args);
|
71
|
+
VALUE inst_methods_in_scope(VALUE self, VALUE method_scope_sym);
|
72
|
+
VALUE inst_methods_enter_scope(VALUE self, VALUE method_scope_sym);
|
73
|
+
VALUE inst_methods_exit_scope(VALUE self, VALUE method_scope_sym);
|
74
|
+
|
75
|
+
/* Scope components module */
|
76
|
+
VALUE scope_mod_sweep_dead_ecs(VALUE self, VALUE args);
|
77
|
+
VALUE inst_methods_enter_method_scope(VALUE self, VALUE scopes_to_enter);
|
78
|
+
VALUE inst_methods_exit_method_scope(VALUE self, VALUE scopes_to_exit);
|
79
|
+
|
80
|
+
/* Helpers */
|
81
|
+
VALUE is_in_scope(int scope);
|
82
|
+
VALUE get_ec();
|
83
|
+
VALUE rb_new_c_scope();
|
84
|
+
void rb_raise_scope_no_method_err(const VALUE method_scope_sym);
|
85
|
+
int scope_increase(int scope);
|
86
|
+
int scope_decrease(int scope);
|
87
|
+
|
88
|
+
void Init_cs__scope(void);
|
@@ -15,20 +15,27 @@ module Contrast
|
|
15
15
|
module Assess
|
16
16
|
# This class holds the data about an event in the application We'll use it to build an event that TeamServer can
|
17
17
|
# consume if the object to which this event belongs ends in a trigger.
|
18
|
-
#
|
19
|
-
# @attr_reader event_id [Integer] the atomic id of this event
|
20
|
-
# @attr_reader policy_node [Contrast::Agent::Assess::Policy::PolicyNode] the node that governs this event.
|
21
|
-
# @attr_reader stack_trace [Array<String>] the execution stack at the time the method for this event was invoked
|
22
|
-
# @attr_reader time [Integer] the time, in epoch ms, when this event was created
|
23
|
-
# @attr_reader thread [Integer] the object id of the thread on which this event was generated
|
24
|
-
# @attr_reader object [Contrast::Agent::Assess::ContrastObject] the safe representation of the Object on which
|
25
|
-
# the method was invoked
|
26
|
-
# @attr_reader ret [Contrast::Agent::Assess::ContrastObject] the safe representation of the Return of the invoked
|
27
|
-
# method
|
28
|
-
# @attr_reader args [Array<Contrast::Agent::Assess::ContrastObject>] the safe representation of the Arguments
|
29
|
-
# with which the method was invoked
|
30
18
|
class ContrastEvent
|
31
|
-
|
19
|
+
# @return [Integer] the atomic id of this event
|
20
|
+
attr_reader :event_id
|
21
|
+
# @return [Contrast::Agent::Assess::Policy::PolicyNode] the node that governs this event.
|
22
|
+
attr_reader :policy_node
|
23
|
+
# @return [Array<String>] the execution stack at the time the method for this event was invoked
|
24
|
+
attr_reader :stack_trace
|
25
|
+
# @return [Integer] the time, in epoch ms, when this event was created
|
26
|
+
attr_reader :time
|
27
|
+
# @return [Integer] the object id of the thread on which this event was generated
|
28
|
+
attr_reader :thread
|
29
|
+
# @return [Contrast::Agent::Assess::ContrastObject] the safe representation of the Object on which the method
|
30
|
+
# was invoked
|
31
|
+
attr_reader :object
|
32
|
+
# @return [Contrast::Agent::Assess::ContrastObject] the safe representation of the Return of the invoked method
|
33
|
+
attr_reader :ret
|
34
|
+
# @return [Array<Contrast::Agent::Assess::ContrastObject, nil>] the safe representation of the Arguments with
|
35
|
+
# which the method was invoked
|
36
|
+
attr_reader :args
|
37
|
+
# @return [Hash<Contrast::Agent::Assess::Tag>]
|
38
|
+
attr_reader :tags
|
32
39
|
|
33
40
|
# We need this to track the parent id's of events to build up a flow chart of the finding
|
34
41
|
@atomic_id = 0
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/utils/duck_utils'
|
5
|
+
require 'contrast/agent/assess/policy/propagation_method'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Agent
|
@@ -66,6 +67,7 @@ module Contrast
|
|
66
67
|
def finalizing_proc
|
67
68
|
@_finalizing_proc ||= proc do |key_id|
|
68
69
|
FROZEN_FINALIZED_IDS.delete(key_id)
|
70
|
+
Contrast::Agent::Assess::Policy::PropagationMethod.instance_variable_get(:@properties).delete(key_id)
|
69
71
|
delete(key_id)
|
70
72
|
end
|
71
73
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'contrast/agent/patching/policy/policy_node'
|
5
5
|
require 'contrast/api/decorators/trace_taint_range_tags'
|
6
|
+
require 'contrast/utils/object_share'
|
7
|
+
require 'contrast/agent/assess/policy/policy_node_utils'
|
6
8
|
|
7
9
|
module Contrast
|
8
10
|
module Agent
|
@@ -11,9 +13,30 @@ module Contrast
|
|
11
13
|
# This class functions to translate our policy.json into an actionable
|
12
14
|
# Ruby object, allowing for dynamic patching over hardcoded patching.
|
13
15
|
class PolicyNode < Contrast::Agent::Patching::Policy::PolicyNode
|
16
|
+
include PolicyNodeUtils
|
17
|
+
|
14
18
|
attr_accessor :tags, :type
|
15
19
|
attr_reader :sources, :targets, :source_string, :target_string
|
16
20
|
|
21
|
+
# Here are all methods that can use original objects without mutation the source.
|
22
|
+
# For methods with REMOVE action, their (!) bang alternative is not listed, since
|
23
|
+
# this methods tends to mutate the original (shortens it's length, remove special
|
24
|
+
# symbols..) and causes mismatch in tags range representation of the target. In
|
25
|
+
# short preshift is needed.
|
26
|
+
ORIGINAL_OBJECT_METHODS = %i[
|
27
|
+
capitalize
|
28
|
+
capitalize!
|
29
|
+
chomp
|
30
|
+
to_s
|
31
|
+
downcase
|
32
|
+
downcase!
|
33
|
+
lstrip
|
34
|
+
strip
|
35
|
+
upcase!
|
36
|
+
upcase
|
37
|
+
].cs__freeze
|
38
|
+
TO_S = 'to_s'
|
39
|
+
|
17
40
|
def initialize policy_hash = {}
|
18
41
|
super(policy_hash)
|
19
42
|
@source_string = policy_hash[JSON_SOURCE]
|
@@ -21,6 +44,20 @@ module Contrast
|
|
21
44
|
@tags = Set.new(policy_hash[JSON_TAGS])
|
22
45
|
@sources = convert_policy_markers(source_string)
|
23
46
|
@targets = convert_policy_markers(target_string)
|
47
|
+
@_use_original_object = ORIGINAL_OBJECT_METHODS.include?(@method_name)
|
48
|
+
@_use_original_on_bang_method = assign_on_bang_check policy_hash
|
49
|
+
end
|
50
|
+
|
51
|
+
def assign_on_bang_check policy_hash
|
52
|
+
# If we have KEEP action on String, and the method is to_s, that method would return self:
|
53
|
+
# String#to_s => self or string. This method is included here to cover the situations such as
|
54
|
+
# String.to_s.html_safe, where normally the dynamic sources properties get lost. To solve this
|
55
|
+
# we will simply return the original object here.
|
56
|
+
return true if @_use_original_object && policy_hash[JSON_METHOD_NAME] == TO_S
|
57
|
+
|
58
|
+
@_use_original_object &&
|
59
|
+
# Check if method name ends with a (!) bang unless is the to_s method:
|
60
|
+
policy_hash[JSON_METHOD_NAME].end_with?(Contrast::Utils::ObjectShare::BANG)
|
24
61
|
end
|
25
62
|
|
26
63
|
def feature
|
@@ -119,36 +156,22 @@ module Contrast
|
|
119
156
|
JSON_TAGS = 'tags'
|
120
157
|
JSON_DATAFLOW = 'dataflow'
|
121
158
|
|
122
|
-
|
123
|
-
|
124
|
-
#
|
125
|
-
# 1) Split on ','
|
126
|
-
# 2) If 'O' or 'R', add the array, else it's P and needs to be
|
127
|
-
# converted. P type will either be P# where # is the index
|
128
|
-
# of the parameter. Drop the P and store the # as an int.
|
159
|
+
# This method will check if a method is fit to use it's original object and
|
160
|
+
# that the method is without bang - it does not change the source, but rather
|
161
|
+
# creates a copy of it.
|
129
162
|
#
|
130
|
-
# @
|
131
|
-
|
132
|
-
|
133
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless markers
|
134
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY if markers.empty?
|
135
|
-
|
136
|
-
converted = []
|
137
|
-
markers.split(Contrast::Utils::ObjectShare::COMMA).each do |t|
|
138
|
-
converted << case t
|
139
|
-
when Contrast::Utils::ObjectShare::OBJECT_KEY,
|
140
|
-
Contrast::Utils::ObjectShare::RETURN_KEY
|
141
|
-
|
142
|
-
t
|
143
|
-
else
|
144
|
-
Integer(t[1..])
|
145
|
-
end
|
146
|
-
end
|
147
|
-
converted
|
163
|
+
# @return true | false
|
164
|
+
def use_original_object?
|
165
|
+
@_use_original_object && Contrast::ASSESS.track_original_object?
|
148
166
|
end
|
149
167
|
|
150
|
-
|
151
|
-
|
168
|
+
# This method will check if a method is fit to use it's original object and
|
169
|
+
# that the target return is the same as object - a bang method modifying the
|
170
|
+
# source.
|
171
|
+
#
|
172
|
+
# @return true | false
|
173
|
+
def use_original_on_bang_method?
|
174
|
+
@_use_original_on_bang_method && Contrast::ASSESS.track_original_object?
|
152
175
|
end
|
153
176
|
end
|
154
177
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/agent/patching/policy/policy_node'
|
5
|
+
require 'contrast/api/decorators/trace_taint_range_tags'
|
6
|
+
require 'contrast/utils/object_share'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Agent
|
10
|
+
module Assess
|
11
|
+
module Policy
|
12
|
+
# This module will extend the PolicyNode, which functions is to translate
|
13
|
+
# our policy.json into an actionable Ruby object, allowing for dynamic
|
14
|
+
# patching over hardcoded patching.
|
15
|
+
module PolicyNodeUtils
|
16
|
+
private
|
17
|
+
|
18
|
+
# Given a policy string in the format A,B,C, populate the given array
|
19
|
+
# 1) Split on ','
|
20
|
+
# 2) If 'O' or 'R', add the array, else it's P and needs to be
|
21
|
+
# converted. P type will either be P# where # is the index
|
22
|
+
# of the parameter. Drop the P and store the # as an int.
|
23
|
+
#
|
24
|
+
# @param markers [String] the String from the policy to parse
|
25
|
+
# @return [Array] the array generated by converting the marker string
|
26
|
+
def convert_policy_markers markers
|
27
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless markers
|
28
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY if markers.empty?
|
29
|
+
|
30
|
+
converted = []
|
31
|
+
markers.split(Contrast::Utils::ObjectShare::COMMA).each do |maker|
|
32
|
+
converted << case maker
|
33
|
+
when Contrast::Utils::ObjectShare::OBJECT_KEY,
|
34
|
+
Contrast::Utils::ObjectShare::RETURN_KEY
|
35
|
+
|
36
|
+
maker
|
37
|
+
else
|
38
|
+
Integer(maker[1..])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
converted
|
42
|
+
end
|
43
|
+
|
44
|
+
def all_type? marker
|
45
|
+
marker.include?(Contrast::Utils::ObjectShare::COMMA)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -14,9 +14,12 @@ module Contrast
|
|
14
14
|
extend Contrast::Components::Logger::InstanceMethods
|
15
15
|
|
16
16
|
@lru_cache = Contrast::Utils::LRUCache.new
|
17
|
-
UNDUPLICABLE_MODULES = [
|
17
|
+
UNDUPLICABLE_MODULES = [ # rubocop: disable Style/MutableConstant
|
18
18
|
Enumerator # dup'ing results in 'can't copy execution context'
|
19
|
-
]
|
19
|
+
]
|
20
|
+
# dup'ing IO::Buffer results in null buffer.
|
21
|
+
UNDUPLICABLE_MODULES << IO::Buffer if RUBY_VERSION >= '3.1.0'
|
22
|
+
UNDUPLICABLE_MODULES.cs__freeze
|
20
23
|
|
21
24
|
attr_accessor :object, :object_length, :args, :arg_lengths
|
22
25
|
|
@@ -41,6 +44,9 @@ module Contrast
|
|
41
44
|
return unless propagation_node
|
42
45
|
return unless ::Contrast::ASSESS.enabled?
|
43
46
|
|
47
|
+
# don't do preshift just use the original object
|
48
|
+
return if propagation_node.use_original_object?
|
49
|
+
|
44
50
|
initializing = propagation_node.method_name == :initialize
|
45
51
|
return if unsafe_io_object?(object, initializing)
|
46
52
|
|
@@ -9,6 +9,7 @@ require 'contrast/utils/object_share'
|
|
9
9
|
require 'contrast/utils/sha256_builder'
|
10
10
|
require 'contrast/utils/assess/propagation_method_utils'
|
11
11
|
require 'contrast/agent/assess/events/event_data'
|
12
|
+
require 'contrast/utils/assess/object_store'
|
12
13
|
|
13
14
|
module Contrast
|
14
15
|
module Agent
|
@@ -21,6 +22,8 @@ module Contrast
|
|
21
22
|
extend Contrast::Components::Logger::InstanceMethods
|
22
23
|
extend Contrast::Utils::Assess::PropagationMethodUtils
|
23
24
|
|
25
|
+
@properties = Contrast::Utils::Assess::ObjectStore.new
|
26
|
+
|
24
27
|
class << self
|
25
28
|
# @param method_policy [Contrast::Agent::Patching::Policy::MethodPolicy] the policy that governs the
|
26
29
|
# patches to this method
|
@@ -33,10 +36,8 @@ module Contrast
|
|
33
36
|
# @return [Object, nil] the tracked Return or nil if no changes were made; will replace the return of the
|
34
37
|
# original function if not nil
|
35
38
|
def apply_propagation method_policy, preshift, object, ret, args, block
|
36
|
-
return unless method_policy.propagation_node
|
37
|
-
return unless preshift
|
38
|
-
|
39
|
-
propagation_node = method_policy.propagation_node
|
39
|
+
return unless (propagation_node = method_policy.propagation_node)
|
40
|
+
return unless propagation_node.use_original_object? || preshift
|
40
41
|
|
41
42
|
target = determine_target(propagation_node, ret, object, args)
|
42
43
|
propagation_data = Contrast::Agent::Assess::Events::EventData.new(nil, nil, object, ret, args)
|
@@ -211,20 +212,39 @@ module Contrast
|
|
211
212
|
# double check that we were able to finalize the replaced return
|
212
213
|
return unless Contrast::Agent::Assess::Tracker.trackable?(target)
|
213
214
|
end
|
214
|
-
|
215
|
+
|
216
|
+
# If we are using the original object tracking, the preshift object is not created.
|
217
|
+
# Instead identify the source as the original object itself and propagate with it.
|
218
|
+
source = propagation_node.use_original_object? ? propagation_data.object : preshift
|
219
|
+
handle_propagation propagation_class, propagation_node, source, target
|
215
220
|
update_properties restore_frozen_state, propagation_node, target, propagation_data, ret
|
216
221
|
end
|
217
222
|
|
223
|
+
def handle_propagation propagation_class, propagation_node, source, target
|
224
|
+
if propagation_node.patch_method
|
225
|
+
propagation_class.send(propagation_node.patch_method, propagation_node, source, target)
|
226
|
+
else
|
227
|
+
propagation_class.propagate(propagation_node, source, target)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
218
231
|
def update_properties restore_frozen_state, propagation_node, target, propagation_data, ret
|
219
|
-
|
220
|
-
|
221
|
-
# Even though we skipped propagating tags from the source if they were included in untags, the target may
|
222
|
-
# have already had some on it. Let's go ahead and remove them. In this order, untags takes precedent over
|
223
|
-
# tags; but we control both and there should never be a propagator that has a tag in its untag.
|
224
|
-
apply_untags(propagation_node, target)
|
225
|
-
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))
|
232
|
+
if propagation_node.use_original_on_bang_method?
|
233
|
+
properties = use_original_object_properties propagation_data
|
226
234
|
|
227
|
-
|
235
|
+
return unless properties
|
236
|
+
else
|
237
|
+
# Once we've propagated, attempt to tag the target if there is a tag(s) to be applied
|
238
|
+
apply_tags(propagation_node, target)
|
239
|
+
# Even though we skipped propagating tags from the source if they were included in untags, the target
|
240
|
+
# may have already had some on it. Let's go ahead and remove them. In this order, untags takes
|
241
|
+
# precedent over tags; but we control both and there should never be a propagator that has a
|
242
|
+
# tag in its untag.
|
243
|
+
apply_untags(propagation_node, target)
|
244
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))
|
245
|
+
|
246
|
+
properties.add_properties(propagation_node.properties)
|
247
|
+
end
|
228
248
|
event_data = Contrast::Agent::Assess::Events::EventData.new(propagation_node,
|
229
249
|
target,
|
230
250
|
propagation_data.object,
|
@@ -259,6 +279,20 @@ module Contrast
|
|
259
279
|
::Contrast::ASSESS.track_frozen_sources? &&
|
260
280
|
propagation_node.targets[0] == Contrast::Utils::ObjectShare::RETURN_KEY
|
261
281
|
end
|
282
|
+
|
283
|
+
# For certain bang methods we return the same object, no need to create expensive new properties.
|
284
|
+
#
|
285
|
+
# @param propagation_data [Contrast::Agent::Assess::Events::EventData] used to hold object, args
|
286
|
+
# and ret.
|
287
|
+
# @return properties [Contrast::Agent::Assess::Properties] the original properties transfered to
|
288
|
+
# target.
|
289
|
+
def use_original_object_properties propagation_data
|
290
|
+
unless @properties[propagation_data.object.__id__]
|
291
|
+
@properties[propagation_data.object.__id__] = Contrast::Agent::Assess::Tracker.properties!(
|
292
|
+
propagation_data.object)
|
293
|
+
end
|
294
|
+
@properties[propagation_data.object.__id__]
|
295
|
+
end
|
262
296
|
end
|
263
297
|
end
|
264
298
|
# rubocop:enable Metrics/ModuleLength
|
@@ -118,11 +118,8 @@ module Contrast
|
|
118
118
|
# it is an interesting security event that has a meaningful
|
119
119
|
# change.
|
120
120
|
def tagger?
|
121
|
-
@_tagger
|
122
|
-
|
123
|
-
has_untags = untags&.any?
|
124
|
-
has_tags || has_untags
|
125
|
-
end
|
121
|
+
@_tagger = tags&.any? || untags&.any? if @_tagger.nil?
|
122
|
+
@_tagger
|
126
123
|
end
|
127
124
|
end
|
128
125
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Copyright (c) 2022 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/policy/propagator/select'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Assess
|
9
|
+
module Policy
|
10
|
+
module Propagator
|
11
|
+
# Propagation that results in all the tags of the source being
|
12
|
+
# applied to the target at the point of insertion. The target's
|
13
|
+
# preexisting tags are shifted to account for this insertion.
|
14
|
+
class Buffer < Contrast::Agent::Assess::Policy::Propagator::Base
|
15
|
+
class << self
|
16
|
+
# For the source, append its tags to the target.
|
17
|
+
# Once the tag is applied, shift it to the location of the insert
|
18
|
+
# Unlike additive propagation, this currently only supports one source
|
19
|
+
# We assume that insert changes the preshift target
|
20
|
+
def propagate_insert propagation_node, preshift, target
|
21
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))
|
22
|
+
|
23
|
+
source = find_source(propagation_node.sources[0], preshift)
|
24
|
+
|
25
|
+
patcher_target = propagation_node.targets[0]
|
26
|
+
preshift_target = case patcher_target
|
27
|
+
when Contrast::Utils::ObjectShare::OBJECT_KEY
|
28
|
+
preshift.object
|
29
|
+
else
|
30
|
+
# this is hardly reached b/c insert supports only one source
|
31
|
+
# changed to second argument: string.insert[idx, string_to_insert]
|
32
|
+
# previously was args[int] => produces exception
|
33
|
+
preshift.args[1]
|
34
|
+
end
|
35
|
+
|
36
|
+
# in case of situations, where buffer is initialized with X size and it's not fully
|
37
|
+
preshift_target = preshift_target.get_string
|
38
|
+
target = target.get_string
|
39
|
+
# Find the first difference between the source to which
|
40
|
+
# we inserted and the result. That is the insertion
|
41
|
+
# point on which all tags need to be adjusted
|
42
|
+
# If the insertion point is the end of the string, preshift length is returned
|
43
|
+
# https://stackoverflow.com/questions/31714522/find-the-first-differing-character-between-two-strings-in-ruby
|
44
|
+
insert_point = (0...preshift_target.length).find do |i|
|
45
|
+
preshift_target[i] != target[i]
|
46
|
+
end || preshift_target.length
|
47
|
+
# Depending what's inserted, we might be wrong. For instance, inserting 'foo'
|
48
|
+
# into 'asdfasdf' could result in 'asdfoofasdf'. we'd be off by one b/c of the 'f'
|
49
|
+
insert_point = target.rindex(source, insert_point)
|
50
|
+
overflow = insert_point...(insert_point + source.length)
|
51
|
+
|
52
|
+
# handle shifting the inserted range
|
53
|
+
properties.shift_tags([overflow])
|
54
|
+
|
55
|
+
properties.copy_from(source, target, insert_point, propagation_node.untags)
|
56
|
+
properties.cleanup_tags
|
57
|
+
end
|
58
|
+
|
59
|
+
# This method will implement both KEEP and SPLAT actions.
|
60
|
+
#
|
61
|
+
# @param propagation_node [Contrast::Agent::Assess::Policy::PropagationNode]
|
62
|
+
# @param preshift [Contrast::Agent::Assess::Preshift]
|
63
|
+
# @param ret [Object] Return target from method invocation.
|
64
|
+
def buffer_keep_splat propagation_node, preshift, ret
|
65
|
+
# If IO::Buffer gets duplicated the dup buffer is not allocated,
|
66
|
+
# it's empty, So a way of doing it is to use the original object
|
67
|
+
# itself. The class is included in the preshift's UNDUPLICABLE_MODULES.
|
68
|
+
return unless preshift.object
|
69
|
+
# We need the return in both propagation cases. So this propagation is
|
70
|
+
# applied in the Contrast::Utils::Patching::PatchUtils.apply_post_patch.
|
71
|
+
# we use this for the IO::Buffer#get_value and it requires 2 args always.
|
72
|
+
return unless ret || Contrast::Agent::Assess::Tracker.tracked?(preshift.object)
|
73
|
+
|
74
|
+
if preshift.args[1] == 0 # rubocop:disable Style/NumericPredicate
|
75
|
+
# KEEP
|
76
|
+
Contrast::Agent::Assess::Policy::Propagator::Keep.propagate(propagation_node, preshift, ret)
|
77
|
+
else
|
78
|
+
# SPLAT
|
79
|
+
Contrast::Agent::Assess::Policy::Propagator::Splat.propagate(propagation_node, preshift, ret)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# This method will implement both SELECT and KEEP actions for
|
84
|
+
# IO::Buffer
|
85
|
+
#
|
86
|
+
# @param propagation_node [Contrast::Agent::Assess::Policy::PropagationNode]
|
87
|
+
# @param preshift [Contrast::Agent::Assess::Preshift]
|
88
|
+
# @param ret [Object] Return targer from method invocation.
|
89
|
+
# @param _block [nil, {}] block passed.
|
90
|
+
def propagate_keep_select propagation_node, preshift, ret, _block
|
91
|
+
# We need the return in both propagation cases. So this propagation is
|
92
|
+
# applied in the Contrast::Utils::Patching::PatchUtils.apply_post_patch.
|
93
|
+
# If IO::Buffer gets duplicated the dup buffer is not allocated,
|
94
|
+
# it's empty, So a way of doing it is to use the original object
|
95
|
+
# itself. The class is handled with no dup in preshift.
|
96
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret)) &&
|
97
|
+
(source = preshift.object)
|
98
|
+
|
99
|
+
# KEEP means the tags just pass from the source to the target as is.
|
100
|
+
# There is a case with IO::Buffer use, when we don't pass any args,
|
101
|
+
# and the target (ret) in this case is the whole strings. We should
|
102
|
+
# use Keep action. Otherwise the SELECT action covers all other cases.
|
103
|
+
if preshift.args.empty?
|
104
|
+
# KEEP
|
105
|
+
properties.copy_from(source, ret, 0, propagation_node.untags)
|
106
|
+
ret
|
107
|
+
else
|
108
|
+
# SELECT
|
109
|
+
Contrast::Agent::Assess::Policy::Propagator::Select.select_tagger propagation_node, preshift, ret, nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -11,12 +11,27 @@ module Contrast
|
|
11
11
|
# are unaffected beyond any merging of overlapping tags.
|
12
12
|
class Keep < Contrast::Agent::Assess::Policy::Propagator::Base
|
13
13
|
class << self
|
14
|
-
# Keep means the tags just pass from the source to the target
|
15
|
-
#
|
16
|
-
|
14
|
+
# Keep means the tags just pass from the source to the target as is.
|
15
|
+
#
|
16
|
+
# @param propagation_node [Contrast::Agent::Assess::Policy::PropagationNode] Current node
|
17
|
+
# governing the propagation.
|
18
|
+
# @param preshift_or_object [Contrast::Agent::Assess::Preshift] current preshift state or
|
19
|
+
# source object passed if track_original_object flag is active.
|
20
|
+
# @param target [Object] To where the tainted data flows.
|
21
|
+
def propagate propagation_node, preshift_or_object, target
|
17
22
|
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))
|
18
23
|
|
19
|
-
source =
|
24
|
+
source = if propagation_node.use_original_object?
|
25
|
+
# for now this is used with string based object and with methods not mutating
|
26
|
+
# original object, so we will always return 'O' key which is the object itself.
|
27
|
+
# Because preshift is disabled for this methods we use it's parameter to pass
|
28
|
+
# in the original object, preshift = object. To see list of methods in which
|
29
|
+
# this is used:
|
30
|
+
# Contrast::Utils::MethodCheck::ORIGINAL_OBJECT_METHODS
|
31
|
+
preshift_or_object
|
32
|
+
else
|
33
|
+
find_source(propagation_node.sources[0], preshift_or_object)
|
34
|
+
end
|
20
35
|
properties.copy_from(source, target, 0, propagation_node.untags)
|
21
36
|
end
|
22
37
|
end
|
@@ -13,10 +13,26 @@ module Contrast
|
|
13
13
|
class << self
|
14
14
|
# For the source, append its tags to the target. Once the tag is applied, remove the section that was
|
15
15
|
# removed by the delete. Unlike additive propagation, this currently only supports one source.
|
16
|
-
|
16
|
+
#
|
17
|
+
# @param propagation_node [Contrast::Agent::Assess::Policy::PropagationNode] Current node
|
18
|
+
# governing the propagation.
|
19
|
+
# @param preshift_or_object [Contrast::Agent::Assess::Preshift] current preshift state or
|
20
|
+
# source object passed if track_original_object flag is active.
|
21
|
+
# @param target [Object] To where the tainted data flows.
|
22
|
+
def propagate propagation_node, preshift_or_object, target
|
17
23
|
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(target))
|
18
24
|
|
19
|
-
source =
|
25
|
+
source = if propagation_node.use_original_object?
|
26
|
+
# for now this is used with string based object and with methods not mutating
|
27
|
+
# original object (clearing empty spaces, \n..) so we will always return 'O' key
|
28
|
+
# which is the object itself. Because preshift is disabled for this methods
|
29
|
+
# we use it's parameter to pass in the original object( in this case just a unchained
|
30
|
+
# source), preshift = object. To see list of methods in which this is used:
|
31
|
+
# Contrast::Utils::MethodCheck::ORIGINAL_OBJECT_METHODS
|
32
|
+
preshift_or_object
|
33
|
+
else
|
34
|
+
find_source(propagation_node.sources[0], preshift_or_object)
|
35
|
+
end
|
20
36
|
properties.copy_from(source, target, 0, propagation_node.untags)
|
21
37
|
handle_removal(propagation_node, source, target)
|
22
38
|
end
|