contrast-agent 5.3.0 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -1
- data/Rakefile +1 -1
- data/ext/build_funchook.rb +3 -3
- data/ext/cs__assess_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +24 -6
- 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 +1 -2
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +1 -1
- data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
- data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
- data/ext/cs__assess_string/cs__assess_string.c +21 -1
- data/ext/cs__assess_test/cs__assess_test.h +9 -0
- data/ext/cs__assess_test/cs__assess_tests.c +22 -0
- data/ext/cs__assess_test/extconf.rb +5 -0
- data/ext/cs__common/cs__common.c +113 -11
- data/ext/cs__common/cs__common.h +29 -5
- data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +146 -97
- data/ext/cs__tests/cs__tests.c +12 -0
- data/ext/cs__tests/cs__tests.h +3 -0
- data/ext/cs__tests/extconf.rb +5 -0
- data/ext/extconf_common.rb +1 -1
- data/lib/contrast/agent/assess/contrast_object.rb +16 -16
- data/lib/contrast/agent/assess/events/source_event.rb +17 -19
- data/lib/contrast/agent/assess/finalizers/hash.rb +4 -2
- data/lib/contrast/agent/assess/policy/policy.rb +9 -10
- data/lib/contrast/agent/assess/policy/policy_node.rb +58 -36
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +48 -14
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +119 -0
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- 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/split.rb +17 -21
- 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 +2 -2
- 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/source_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +11 -17
- data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +2 -2
- data/lib/contrast/agent/assess/property/tagged.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
- data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
- data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
- data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
- data/lib/contrast/agent/assess/tag.rb +13 -14
- data/lib/contrast/agent/at_exit_hook.rb +12 -1
- 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/inventory/database_config.rb +10 -3
- data/lib/contrast/agent/middleware.rb +10 -5
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
- data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
- data/lib/contrast/agent/patching/policy/patch.rb +20 -19
- data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
- data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
- data/lib/contrast/agent/patching/policy/policy.rb +13 -15
- data/lib/contrast/agent/patching/policy/policy_node.rb +32 -21
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +132 -75
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
- data/lib/contrast/agent/protect/rule/base.rb +53 -9
- data/lib/contrast/agent/protect/rule/base_service.rb +31 -12
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +23 -3
- 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/default_scanner.rb +2 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
- 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 +72 -46
- 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 -2
- data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +2 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
- 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/xss.rb +17 -0
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
- data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- 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/masker/masker.rb +243 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
- data/lib/contrast/agent/reporting/report.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +29 -22
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +13 -5
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
- data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +44 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
- data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +8 -11
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
- data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
- data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +29 -13
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +163 -122
- data/lib/contrast/agent/reporting/settings/application_settings.rb +10 -1
- data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +7 -35
- data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
- data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
- data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
- 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/reporting/settings/server_features.rb +2 -2
- data/lib/contrast/agent/request.rb +5 -5
- data/lib/contrast/agent/request_context.rb +25 -21
- data/lib/contrast/agent/request_context_extend.rb +12 -25
- data/lib/contrast/agent/request_handler.rb +7 -3
- data/lib/contrast/agent/response.rb +2 -0
- data/lib/contrast/agent/rule_set.rb +2 -2
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +6 -48
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/telemetry/base.rb +155 -0
- data/lib/contrast/agent/telemetry/events/event.rb +35 -0
- data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +59 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
- data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
- data/lib/contrast/agent/thread_watcher.rb +52 -68
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +8 -0
- data/lib/contrast/agent.rb +4 -3
- data/lib/contrast/api/communication/messaging_queue.rb +29 -12
- data/lib/contrast/api/communication/response_processor.rb +7 -10
- data/lib/contrast/api/communication/service_lifecycle.rb +1 -1
- data/lib/contrast/api/communication/socket.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +1 -1
- data/lib/contrast/api/communication/speedracer.rb +3 -3
- data/lib/contrast/api/decorators/activity.rb +33 -0
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/agent_startup.rb +10 -9
- data/lib/contrast/api/decorators/application_settings.rb +1 -1
- data/lib/contrast/api/decorators/application_startup.rb +4 -4
- data/lib/contrast/api/decorators/http_request.rb +1 -1
- data/lib/contrast/api/decorators/response_type.rb +17 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/agent.rb +1 -1
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/base.rb +1 -1
- data/lib/contrast/components/config.rb +19 -28
- data/lib/contrast/components/contrast_service.rb +13 -1
- data/lib/contrast/components/protect.rb +2 -2
- data/lib/contrast/components/sampling.rb +8 -12
- data/lib/contrast/components/settings.rb +151 -19
- data/lib/contrast/config/agent_configuration.rb +34 -41
- data/lib/contrast/config/api_configuration.rb +16 -75
- data/lib/contrast/config/api_proxy_configuration.rb +9 -48
- data/lib/contrast/config/application_configuration.rb +24 -95
- data/lib/contrast/config/assess_configuration.rb +21 -76
- data/lib/contrast/config/assess_rules_configuration.rb +13 -38
- data/lib/contrast/config/base_configuration.rb +11 -76
- data/lib/contrast/config/certification_configuration.rb +15 -68
- data/lib/contrast/config/exception_configuration.rb +15 -59
- data/lib/contrast/config/heap_dump_configuration.rb +19 -73
- data/lib/contrast/config/inventory_configuration.rb +11 -55
- data/lib/contrast/config/logger_configuration.rb +8 -41
- data/lib/contrast/config/protect_configuration.rb +23 -10
- data/lib/contrast/config/protect_rule_configuration.rb +23 -37
- data/lib/contrast/config/protect_rules_configuration.rb +39 -43
- data/lib/contrast/config/request_audit_configuration.rb +16 -55
- data/lib/contrast/config/root_configuration.rb +71 -14
- data/lib/contrast/config/ruby_configuration.rb +14 -47
- data/lib/contrast/config/sampling_configuration.rb +12 -65
- data/lib/contrast/config/server_configuration.rb +13 -45
- data/lib/contrast/config/service_configuration.rb +18 -54
- data/lib/contrast/configuration.rb +25 -17
- data/lib/contrast/extension/assess/array.rb +1 -1
- data/lib/contrast/extension/assess/erb.rb +1 -1
- data/lib/contrast/extension/assess/marshal.rb +1 -1
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/extension.rb +2 -2
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/base_support.rb +8 -8
- data/lib/contrast/framework/grape/support.rb +3 -3
- data/lib/contrast/framework/manager.rb +7 -7
- data/lib/contrast/framework/manager_extend.rb +1 -1
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +14 -46
- data/lib/contrast/framework/rails/support.rb +2 -2
- data/lib/contrast/framework/sinatra/support.rb +1 -1
- data/lib/contrast/logger/aliased_logging.rb +94 -0
- data/lib/contrast/logger/application.rb +1 -5
- data/lib/contrast/logger/cef_log.rb +15 -15
- data/lib/contrast/logger/format.rb +1 -1
- data/lib/contrast/logger/log.rb +8 -8
- data/lib/contrast/tasks/config.rb +100 -4
- data/lib/contrast/tasks/service.rb +2 -2
- 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/assess/tracking_util.rb +4 -4
- data/lib/contrast/utils/class_util.rb +9 -22
- data/lib/contrast/utils/findings.rb +3 -3
- data/lib/contrast/utils/hash_digest.rb +6 -7
- data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
- data/lib/contrast/utils/log_utils.rb +7 -5
- data/lib/contrast/utils/lru_cache.rb +1 -1
- data/lib/contrast/utils/metrics_hash.rb +1 -1
- data/lib/contrast/utils/middleware_utils.rb +15 -14
- data/lib/contrast/utils/net_http_base.rb +5 -5
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +1 -6
- data/lib/contrast/utils/patching/policy/patch_utils.rb +6 -7
- data/lib/contrast/utils/request_utils.rb +2 -2
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/sha256_builder.rb +4 -4
- data/lib/contrast/utils/stack_trace_utils.rb +31 -13
- data/lib/contrast/utils/telemetry.rb +22 -7
- data/lib/contrast/utils/telemetry_client.rb +28 -16
- data/lib/contrast/utils/telemetry_hash.rb +41 -0
- data/lib/contrast/utils/telemetry_identifier.rb +18 -3
- data/lib/contrast/utils/timer.rb +1 -1
- data/lib/contrast.rb +9 -0
- data/resources/assess/policy.json +99 -1
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +10 -9
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +99 -29
- data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
- data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
- data/lib/contrast/agent/telemetry.rb +0 -137
- data/lib/contrast/agent/telemetry_event.rb +0 -33
- data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -18,11 +18,20 @@ module Contrast
|
|
18
18
|
# This is just a holder for our policy. Takes the policy JSON and
|
19
19
|
# converts it into hashes that we can access nicely
|
20
20
|
class Policy < Contrast::Agent::Patching::Policy::Policy
|
21
|
+
PROVIDER_CLASSES = [
|
22
|
+
Contrast::Agent::Assess::Rule::Provider::HardcodedKey,
|
23
|
+
Contrast::Agent::Assess::Rule::Provider::HardcodedPassword
|
24
|
+
].cs__freeze
|
21
25
|
# Indicates the folder in `resources` where this policy lives.
|
22
26
|
def self.policy_folder
|
23
27
|
'assess'
|
24
28
|
end
|
25
29
|
|
30
|
+
def initialize
|
31
|
+
super
|
32
|
+
load_providers
|
33
|
+
end
|
34
|
+
|
26
35
|
# Indicates is this feature has been disabled by the configuration,
|
27
36
|
# read at startup, and therefore can never be enabled.
|
28
37
|
def disabled_globally?
|
@@ -33,11 +42,6 @@ module Contrast
|
|
33
42
|
Contrast::Agent::Assess::Policy::TriggerNode
|
34
43
|
end
|
35
44
|
|
36
|
-
def initialize
|
37
|
-
super
|
38
|
-
load_providers
|
39
|
-
end
|
40
|
-
|
41
45
|
# Our policy for dataflow rules is a 'dope ass' JSON file. Rather than
|
42
46
|
# hard code in a bunch of things to monkey patch, we let the JSON file
|
43
47
|
# define the conditions in which sources, propagators, and triggers are
|
@@ -88,11 +92,6 @@ module Contrast
|
|
88
92
|
providers[instance.rule_id] = instance
|
89
93
|
end
|
90
94
|
end
|
91
|
-
|
92
|
-
PROVIDER_CLASSES = [
|
93
|
-
Contrast::Agent::Assess::Rule::Provider::HardcodedKey,
|
94
|
-
Contrast::Agent::Assess::Rule::Provider::HardcodedPassword
|
95
|
-
].cs__freeze
|
96
95
|
end
|
97
96
|
end
|
98
97
|
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,38 @@ 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
|
+
JSON_TAGS = 'tags'
|
18
|
+
JSON_DATAFLOW = 'dataflow'
|
19
|
+
# The keys used to read from policy.json to create the individual
|
20
|
+
# policy nodes. These are common across node types
|
21
|
+
JSON_SOURCE = 'source'
|
22
|
+
ALL_TYPE = 'A'
|
23
|
+
JSON_TARGET = 'target'
|
24
|
+
TO_MARKER = '2'
|
25
|
+
|
14
26
|
attr_accessor :tags, :type
|
15
27
|
attr_reader :sources, :targets, :source_string, :target_string
|
16
28
|
|
29
|
+
# Here are all methods that can use original objects without mutation the source.
|
30
|
+
# For methods with REMOVE action, their (!) bang alternative is not listed, since
|
31
|
+
# this methods tends to mutate the original (shortens it's length, remove special
|
32
|
+
# symbols..) and causes mismatch in tags range representation of the target. In
|
33
|
+
# short preshift is needed.
|
34
|
+
ORIGINAL_OBJECT_METHODS = %i[
|
35
|
+
capitalize
|
36
|
+
capitalize!
|
37
|
+
chomp
|
38
|
+
to_s
|
39
|
+
downcase
|
40
|
+
downcase!
|
41
|
+
lstrip
|
42
|
+
strip
|
43
|
+
upcase!
|
44
|
+
upcase
|
45
|
+
].cs__freeze
|
46
|
+
TO_S = 'to_s'
|
47
|
+
|
17
48
|
def initialize policy_hash = {}
|
18
49
|
super(policy_hash)
|
19
50
|
@source_string = policy_hash[JSON_SOURCE]
|
@@ -21,6 +52,20 @@ module Contrast
|
|
21
52
|
@tags = Set.new(policy_hash[JSON_TAGS])
|
22
53
|
@sources = convert_policy_markers(source_string)
|
23
54
|
@targets = convert_policy_markers(target_string)
|
55
|
+
@_use_original_object = ORIGINAL_OBJECT_METHODS.include?(@method_name)
|
56
|
+
@_use_original_on_bang_method = assign_on_bang_check(policy_hash)
|
57
|
+
end
|
58
|
+
|
59
|
+
def assign_on_bang_check policy_hash
|
60
|
+
# If we have KEEP action on String, and the method is to_s, that method would return self:
|
61
|
+
# String#to_s => self or string. This method is included here to cover the situations such as
|
62
|
+
# String.to_s.html_safe, where normally the dynamic sources properties get lost. To solve this
|
63
|
+
# we will simply return the original object here.
|
64
|
+
return true if @_use_original_object && policy_hash[JSON_METHOD_NAME] == TO_S
|
65
|
+
|
66
|
+
@_use_original_object &&
|
67
|
+
# Check if method name ends with a (!) bang unless is the to_s method:
|
68
|
+
policy_hash[JSON_METHOD_NAME].end_with?(Contrast::Utils::ObjectShare::BANG)
|
24
69
|
end
|
25
70
|
|
26
71
|
def feature
|
@@ -79,8 +124,6 @@ module Contrast
|
|
79
124
|
end
|
80
125
|
end
|
81
126
|
|
82
|
-
ALL_TYPE = 'A'
|
83
|
-
TO_MARKER = '2'
|
84
127
|
# Convert our action, built from our source and target, into
|
85
128
|
# the TS appropriate action. That's a single source to single
|
86
129
|
# target marker (A,O,P,R)
|
@@ -112,43 +155,22 @@ module Contrast
|
|
112
155
|
@event_action
|
113
156
|
end
|
114
157
|
|
115
|
-
#
|
116
|
-
#
|
117
|
-
|
118
|
-
JSON_TARGET = 'target'
|
119
|
-
JSON_TAGS = 'tags'
|
120
|
-
JSON_DATAFLOW = 'dataflow'
|
121
|
-
|
122
|
-
private
|
123
|
-
|
124
|
-
# Given a policy string in the format A,B,C, populate the given array
|
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.
|
158
|
+
# This method will check if a method is fit to use it's original object and
|
159
|
+
# that the method is without bang - it does not change the source, but rather
|
160
|
+
# creates a copy of it.
|
129
161
|
#
|
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
|
162
|
+
# @return true | false
|
163
|
+
def use_original_object?
|
164
|
+
@_use_original_object && Contrast::ASSESS.track_original_object?
|
148
165
|
end
|
149
166
|
|
150
|
-
|
151
|
-
|
167
|
+
# This method will check if a method is fit to use it's original object and
|
168
|
+
# that the target return is the same as object - a bang method modifying the
|
169
|
+
# source.
|
170
|
+
#
|
171
|
+
# @return true | false
|
172
|
+
def use_original_on_bang_method?
|
173
|
+
@_use_original_on_bang_method && Contrast::ASSESS.track_original_object?
|
152
174
|
end
|
153
175
|
end
|
154
176
|
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
|
@@ -32,22 +32,8 @@ module Contrast
|
|
32
32
|
mod = trace_point.self
|
33
33
|
return if mod.cs__frozen? || mod.singleton_class?
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def different_ruby_version trace_point, provider_values, mod
|
39
|
-
# TODO: RUBY-1014 - remove non-AST approach
|
40
|
-
if RUBY_VERSION >= '2.6.0'
|
41
|
-
# TODO: RUBY-714 EOL 2.5. That check will be removed and the code will be brought back in here.
|
42
|
-
ast = RubyVM::AbstractSyntaxTree.parse_file(trace_point.path)
|
43
|
-
provider_values.each do |provider|
|
44
|
-
provider.parse(trace_point, ast)
|
45
|
-
end
|
46
|
-
else
|
47
|
-
provider_values.each do |provider|
|
48
|
-
provider.analyze(mod)
|
49
|
-
end
|
50
|
-
end
|
35
|
+
ast = RubyVM::AbstractSyntaxTree.parse_file(trace_point.path)
|
36
|
+
provider_values.each { |provider| provider.parse(trace_point, ast) }
|
51
37
|
end
|
52
38
|
|
53
39
|
def policy
|
@@ -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
|
-
|
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)
|
220
|
+
update_properties(restore_frozen_state, propagation_node, target, propagation_data, ret)
|
221
|
+
end
|
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
|
216
229
|
end
|
217
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
|
@@ -22,6 +22,8 @@ module Contrast
|
|
22
22
|
attr_reader :untags, :patch_method
|
23
23
|
attr_accessor :action, :patch_class
|
24
24
|
|
25
|
+
TAGGER = 'Tagger'
|
26
|
+
PROPAGATOR = 'Propagator'
|
25
27
|
# Most things here carry over from PolicyNode.
|
26
28
|
# A couple things are new / have new rules
|
27
29
|
#
|
@@ -41,9 +43,6 @@ module Contrast
|
|
41
43
|
validate
|
42
44
|
end
|
43
45
|
|
44
|
-
TAGGER = 'Tagger'
|
45
|
-
PROPAGATOR = 'Propagator'
|
46
|
-
|
47
46
|
def node_class
|
48
47
|
@_node_class ||= tagger? ? TAGGER : PROPAGATOR
|
49
48
|
end
|
@@ -26,7 +26,7 @@ module Contrast
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def propagate _propagation_node, _preshift, _target
|
29
|
-
raise
|
29
|
+
raise(NoMethodError("Expected Base propagator subclass: #{ cs__class } to implement #propagate"))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,119 @@
|
|
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,
|
110
|
+
nil)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -31,7 +31,7 @@ module Contrast
|
|
31
31
|
::Contrast::ASSESS.tainted_columns[class_name] = tainted_columns.keys
|
32
32
|
end
|
33
33
|
|
34
|
-
Contrast::Agent::Assess::Policy::DynamicSourceFactory.create_sources
|
34
|
+
Contrast::Agent::Assess::Policy::DynamicSourceFactory.create_sources(class_type, tainted_columns)
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
@@ -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
|
@@ -19,6 +19,7 @@ module Contrast
|
|
19
19
|
when Contrast::Utils::ObjectShare::OBJECT_KEY
|
20
20
|
tracked_inputs << preshift.object if Contrast::Agent::Assess::Tracker.tracked?(preshift.object)
|
21
21
|
else
|
22
|
+
check_for_buffer(tracked_inputs, preshift.args[source])
|
22
23
|
find_argument_inputs(tracked_inputs, preshift.args[source])
|
23
24
|
end
|
24
25
|
end
|
@@ -47,9 +48,15 @@ module Contrast
|
|
47
48
|
# @param tracked_inputs [Array] storage for the inputs to act on later
|
48
49
|
# @param arg [Object] an input to the method which act as sources for this propagation.
|
49
50
|
def find_argument_inputs tracked_inputs, arg
|
50
|
-
if arg.is_a?(String)
|
51
|
-
tracked_inputs << arg if
|
52
|
-
|
51
|
+
if arg.is_a?(String) || arg.is_a?(File)
|
52
|
+
tracked_inputs << arg if tracked_value?(arg)
|
53
|
+
else
|
54
|
+
iterable_arg(tracked_inputs, arg)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def iterable_arg tracked_inputs, arg
|
59
|
+
if Contrast::Utils::DuckUtils.iterable_hash?(arg)
|
53
60
|
arg.each_pair do |key, value|
|
54
61
|
tracked_inputs << key if tracked_value?(key)
|
55
62
|
tracked_inputs << value if tracked_value?(value)
|
@@ -60,6 +67,13 @@ module Contrast
|
|
60
67
|
end
|
61
68
|
end
|
62
69
|
end
|
70
|
+
|
71
|
+
def check_for_buffer tracked_inputs, arg
|
72
|
+
return if RUBY_VERSION < '3.1.0'
|
73
|
+
return unless arg.is_a?(IO::Buffer) && tracked_value?(arg)
|
74
|
+
|
75
|
+
tracked_inputs << arg
|
76
|
+
end
|
63
77
|
end
|
64
78
|
end
|
65
79
|
end
|