contrast-agent 4.4.1 → 4.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/.gitmodules +1 -1
- data/.simplecov +2 -1
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/Rakefile +2 -3
- data/exe/contrast_service +1 -1
- data/ext/build_funchook.rb +4 -4
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +1 -1
- data/ext/cs__assess_active_record_named/extconf.rb +1 -1
- data/ext/cs__assess_array/cs__assess_array.c +1 -1
- data/ext/cs__assess_array/extconf.rb +1 -1
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +1 -1
- data/ext/cs__assess_basic_object/extconf.rb +1 -1
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
- data/ext/cs__assess_fiber_track/extconf.rb +1 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +4 -2
- data/ext/cs__assess_hash/extconf.rb +1 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
- data/ext/cs__assess_kernel/extconf.rb +1 -1
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +1 -1
- data/ext/cs__assess_marshal_module/extconf.rb +1 -1
- data/ext/cs__assess_module/cs__assess_module.c +1 -1
- data/ext/cs__assess_module/extconf.rb +1 -1
- data/ext/cs__assess_regexp/cs__assess_regexp.c +1 -1
- data/ext/cs__assess_regexp/extconf.rb +1 -1
- data/ext/cs__assess_string/cs__assess_string.c +1 -1
- data/ext/cs__assess_string/extconf.rb +1 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -1
- data/ext/cs__assess_string_interpolation26/extconf.rb +1 -1
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -1
- data/ext/cs__assess_yield_track/extconf.rb +1 -1
- data/ext/cs__common/cs__common.c +5 -5
- data/ext/cs__common/cs__common.h +4 -4
- data/ext/cs__common/extconf.rb +1 -1
- data/ext/cs__contrast_patch/cs__contrast_patch.c +22 -25
- data/ext/cs__contrast_patch/extconf.rb +1 -1
- data/ext/cs__protect_kernel/cs__protect_kernel.c +1 -1
- data/ext/cs__protect_kernel/extconf.rb +1 -1
- data/ext/extconf_common.rb +2 -6
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +44 -15
- data/lib/contrast/agent.rb +1 -3
- data/lib/contrast/agent/assess.rb +2 -2
- data/lib/contrast/agent/assess/contrast_event.rb +54 -72
- data/lib/contrast/agent/assess/contrast_object.rb +3 -3
- data/lib/contrast/agent/assess/events/event_factory.rb +3 -2
- data/lib/contrast/agent/assess/events/source_event.rb +7 -2
- data/lib/contrast/agent/assess/finalizers/freeze.rb +1 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +28 -38
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +24 -20
- data/lib/contrast/agent/assess/policy/patcher.rb +17 -22
- data/lib/contrast/agent/assess/policy/policy.rb +2 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +26 -34
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +4 -6
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -6
- data/lib/contrast/agent/assess/policy/propagation_method.rb +12 -25
- data/lib/contrast/agent/assess/policy/propagation_node.rb +20 -9
- data/lib/contrast/agent/assess/policy/propagator.rb +2 -1
- data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +3 -2
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +4 -7
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +4 -2
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
- data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +23 -19
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/select.rb +3 -13
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/split.rb +13 -14
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -11
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +64 -45
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +14 -11
- data/lib/contrast/agent/assess/policy/source_method.rb +97 -86
- data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +8 -6
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +2 -4
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -3
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +7 -11
- data/lib/contrast/agent/assess/policy/trigger_method.rb +104 -77
- data/lib/contrast/agent/assess/policy/trigger_node.rb +6 -5
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +5 -4
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -3
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +2 -9
- data/lib/contrast/agent/assess/properties.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +9 -6
- data/lib/contrast/agent/assess/property/tagged.rb +1 -1
- data/lib/contrast/agent/assess/property/updated.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +12 -6
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +5 -2
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +8 -10
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +1 -1
- data/lib/contrast/agent/at_exit_hook.rb +4 -4
- data/lib/contrast/agent/class_reopener.rb +10 -7
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/policy.rb +7 -3
- data/lib/contrast/agent/disable_reaction.rb +5 -8
- data/lib/contrast/agent/exclusion_matcher.rb +8 -15
- data/lib/contrast/agent/inventory.rb +1 -2
- data/lib/contrast/agent/inventory/dependencies.rb +3 -1
- data/lib/contrast/agent/inventory/dependency_analysis.rb +3 -7
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +38 -28
- data/lib/contrast/agent/inventory/policy/datastores.rb +4 -5
- data/lib/contrast/agent/inventory/policy/policy.rb +2 -2
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +52 -80
- data/lib/contrast/agent/module_data.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +10 -10
- data/lib/contrast/agent/patching/policy/method_policy.rb +7 -3
- data/lib/contrast/agent/patching/policy/module_policy.rb +15 -8
- data/lib/contrast/agent/patching/policy/patch.rb +32 -38
- data/lib/contrast/agent/patching/policy/patch_status.rb +7 -8
- data/lib/contrast/agent/patching/policy/patcher.rb +29 -28
- data/lib/contrast/agent/patching/policy/policy.rb +16 -25
- data/lib/contrast/agent/patching/policy/policy_node.rb +17 -8
- data/lib/contrast/agent/patching/policy/trigger_node.rb +22 -9
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +2 -2
- 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 -4
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +6 -10
- data/lib/contrast/agent/protect/policy/policy.rb +2 -2
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +8 -10
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +1 -1
- data/lib/contrast/agent/protect/rule/base.rb +26 -40
- data/lib/contrast/agent/protect/rule/base_service.rb +10 -6
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +19 -24
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +7 -14
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +4 -15
- data/lib/contrast/agent/protect/rule/no_sqli.rb +7 -3
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +2 -4
- data/lib/contrast/agent/protect/rule/path_traversal.rb +7 -11
- data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
- data/lib/contrast/agent/protect/rule/sqli/default_sql_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/sqli/mysql_sql_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/sqli/postgres_sql_scanner.rb +2 -2
- data/lib/contrast/agent/protect/rule/sqli/sqlite_sql_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -2
- data/lib/contrast/agent/protect/rule/xss.rb +2 -2
- data/lib/contrast/agent/protect/rule/xxe.rb +6 -13
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -3
- data/lib/contrast/agent/reaction_processor.rb +14 -14
- data/lib/contrast/agent/request.rb +29 -27
- data/lib/contrast/agent/request_context.rb +20 -30
- data/lib/contrast/agent/request_handler.rb +6 -4
- data/lib/contrast/agent/response.rb +3 -4
- data/lib/contrast/agent/rewriter.rb +10 -7
- data/lib/contrast/agent/rule_set.rb +6 -5
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +5 -7
- data/lib/contrast/agent/static_analysis.rb +7 -6
- data/lib/contrast/agent/thread.rb +3 -5
- data/lib/contrast/agent/thread_watcher.rb +4 -5
- data/lib/contrast/agent/tracepoint_hook.rb +6 -6
- data/lib/contrast/agent/version.rb +2 -2
- data/lib/contrast/agent/worker_thread.rb +1 -1
- data/lib/contrast/api.rb +1 -1
- data/lib/contrast/api/communication.rb +1 -1
- data/lib/contrast/api/communication/connection_status.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +5 -6
- data/lib/contrast/api/communication/response_processor.rb +13 -15
- data/lib/contrast/api/communication/service_lifecycle.rb +10 -7
- data/lib/contrast/api/communication/socket.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +23 -32
- data/lib/contrast/api/communication/speedracer.rb +10 -15
- 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 +1 -1
- data/lib/contrast/api/decorators/address.rb +3 -4
- data/lib/contrast/api/decorators/agent_startup.rb +8 -10
- data/lib/contrast/api/decorators/application_settings.rb +1 -1
- data/lib/contrast/api/decorators/application_startup.rb +14 -10
- data/lib/contrast/api/decorators/application_update.rb +1 -5
- data/lib/contrast/api/decorators/http_request.rb +4 -8
- data/lib/contrast/api/decorators/input_analysis.rb +1 -1
- data/lib/contrast/api/decorators/instrumentation_mode.rb +35 -0
- data/lib/contrast/api/decorators/library.rb +9 -7
- data/lib/contrast/api/decorators/library_usage_update.rb +1 -1
- data/lib/contrast/api/decorators/message.rb +10 -10
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +1 -1
- data/lib/contrast/api/decorators/route_coverage.rb +1 -1
- data/lib/contrast/api/decorators/server_features.rb +1 -1
- data/lib/contrast/api/decorators/trace_event.rb +4 -2
- data/lib/contrast/api/decorators/trace_event_object.rb +4 -7
- data/lib/contrast/api/decorators/trace_event_signature.rb +1 -1
- data/lib/contrast/api/decorators/trace_taint_range.rb +1 -1
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +2 -7
- data/lib/contrast/api/decorators/user_input.rb +1 -1
- data/lib/contrast/components/agent.rb +20 -26
- data/lib/contrast/components/app_context.rb +12 -16
- data/lib/contrast/components/assess.rb +20 -25
- data/lib/contrast/components/base.rb +40 -0
- data/lib/contrast/components/config.rb +3 -4
- data/lib/contrast/components/contrast_service.rb +13 -19
- data/lib/contrast/components/heap_dump.rb +6 -5
- data/lib/contrast/components/inventory.rb +3 -8
- data/lib/contrast/components/logger.rb +2 -3
- data/lib/contrast/components/protect.rb +14 -20
- data/lib/contrast/components/sampling.rb +14 -8
- data/lib/contrast/components/scope.rb +2 -5
- data/lib/contrast/components/settings.rb +28 -103
- data/lib/contrast/config.rb +1 -1
- data/lib/contrast/config/agent_configuration.rb +1 -1
- data/lib/contrast/config/application_configuration.rb +1 -1
- data/lib/contrast/config/assess_configuration.rb +1 -1
- data/lib/contrast/config/assess_rules_configuration.rb +2 -4
- data/lib/contrast/config/base_configuration.rb +5 -6
- data/lib/contrast/config/default_value.rb +1 -1
- data/lib/contrast/config/exception_configuration.rb +2 -6
- data/lib/contrast/config/heap_dump_configuration.rb +13 -7
- data/lib/contrast/config/inventory_configuration.rb +1 -1
- data/lib/contrast/config/logger_configuration.rb +2 -6
- data/lib/contrast/config/protect_configuration.rb +1 -1
- data/lib/contrast/config/protect_rule_configuration.rb +23 -1
- data/lib/contrast/config/protect_rules_configuration.rb +1 -1
- data/lib/contrast/config/root_configuration.rb +1 -1
- data/lib/contrast/config/ruby_configuration.rb +1 -1
- data/lib/contrast/config/sampling_configuration.rb +1 -1
- data/lib/contrast/config/server_configuration.rb +1 -1
- data/lib/contrast/config/service_configuration.rb +1 -1
- data/lib/contrast/configuration.rb +7 -19
- data/lib/contrast/extension/assess.rb +1 -1
- data/lib/contrast/extension/assess/array.rb +4 -11
- data/lib/contrast/extension/assess/erb.rb +2 -8
- data/lib/contrast/extension/assess/eval_trigger.rb +5 -14
- data/lib/contrast/extension/assess/exec_trigger.rb +4 -14
- data/lib/contrast/extension/assess/fiber.rb +9 -18
- data/lib/contrast/extension/assess/hash.rb +4 -4
- data/lib/contrast/extension/assess/kernel.rb +5 -14
- data/lib/contrast/extension/assess/marshal.rb +7 -15
- data/lib/contrast/extension/assess/regexp.rb +7 -11
- data/lib/contrast/extension/assess/string.rb +9 -7
- data/lib/contrast/extension/delegator.rb +1 -1
- data/lib/contrast/extension/inventory.rb +1 -1
- data/lib/contrast/extension/kernel.rb +3 -3
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +1 -1
- data/lib/contrast/extension/protect/kernel.rb +1 -6
- data/lib/contrast/extension/protect/psych.rb +1 -1
- data/lib/contrast/extension/thread.rb +1 -1
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +7 -12
- data/lib/contrast/framework/platform_version.rb +1 -1
- data/lib/contrast/framework/rack/patch/session_cookie.rb +12 -25
- data/lib/contrast/framework/rack/patch/support.rb +7 -5
- data/lib/contrast/framework/rack/support.rb +1 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -1
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +13 -10
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +4 -4
- data/lib/contrast/framework/rails/patch/support.rb +42 -36
- data/lib/contrast/framework/rails/railtie.rb +34 -0
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +5 -2
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +3 -1
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +6 -5
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +3 -1
- data/lib/contrast/framework/rails/support.rb +3 -3
- data/lib/contrast/framework/sinatra/support.rb +4 -2
- data/lib/contrast/funchook/funchook.rb +6 -9
- data/lib/contrast/logger/application.rb +14 -16
- data/lib/contrast/logger/format.rb +3 -6
- data/lib/contrast/logger/log.rb +27 -10
- data/lib/contrast/logger/request.rb +2 -7
- data/lib/contrast/logger/time.rb +1 -1
- data/lib/contrast/security_exception.rb +2 -2
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +7 -8
- data/lib/contrast/utils/assess/sampling_util.rb +3 -4
- data/lib/contrast/utils/assess/tracking_util.rb +4 -7
- data/lib/contrast/utils/class_util.rb +15 -11
- data/lib/contrast/utils/duck_utils.rb +1 -1
- data/lib/contrast/utils/env_configuration_item.rb +1 -1
- data/lib/contrast/utils/hash_digest.rb +16 -24
- data/lib/contrast/utils/heap_dump_util.rb +6 -4
- data/lib/contrast/utils/invalid_configuration_util.rb +5 -4
- data/lib/contrast/utils/inventory_util.rb +3 -4
- data/lib/contrast/utils/io_util.rb +4 -6
- data/lib/contrast/utils/job_servers_running.rb +14 -8
- data/lib/contrast/utils/object_share.rb +1 -1
- data/lib/contrast/utils/os.rb +5 -5
- data/lib/contrast/utils/preflight_util.rb +1 -1
- data/lib/contrast/utils/resource_loader.rb +1 -1
- data/lib/contrast/utils/ruby_ast_rewriter.rb +3 -2
- data/lib/contrast/utils/sha256_builder.rb +1 -1
- data/lib/contrast/utils/stack_trace_utils.rb +1 -1
- data/lib/contrast/utils/string_utils.rb +3 -4
- data/lib/contrast/utils/tag_util.rb +26 -20
- data/lib/contrast/utils/thread_tracker.rb +1 -1
- data/lib/contrast/utils/timer.rb +1 -1
- data/resources/assess/policy.json +60 -2
- data/resources/deadzone/policy.json +7 -17
- data/ruby-agent.gemspec +25 -21
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- data/sonar-project.properties +9 -0
- metadata +108 -51
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +0 -38
- data/lib/contrast/agent/railtie.rb +0 -31
- data/lib/contrast/common_agent_configuration.rb +0 -87
- data/lib/contrast/components/interface.rb +0 -195
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/patching/policy/method_policy'
|
@@ -27,6 +27,9 @@ module Contrast
|
|
27
27
|
class_name = klass.cs__name
|
28
28
|
instance_methods = klass.instance_methods
|
29
29
|
instance_methods.concat(klass.private_instance_methods)
|
30
|
+
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
31
|
+
current_request = current_context&.request
|
32
|
+
|
30
33
|
tainted_columns.each_pair do |field, properties|
|
31
34
|
next unless properties
|
32
35
|
|
@@ -34,14 +37,14 @@ module Contrast
|
|
34
37
|
# Move on if we already know about this Dynamic Source
|
35
38
|
next if Contrast::Agent::Assess::Policy::Policy.instance.find_source_node(class_name, method_name, true)
|
36
39
|
|
37
|
-
dynamic_source_node = create_source_node(class_name, method_name, Set.new(properties.tag_keys)
|
40
|
+
dynamic_source_node = create_source_node(class_name, method_name, Set.new(properties.tag_keys),
|
41
|
+
current_request)
|
38
42
|
Contrast::Agent::Assess::Policy::Policy.instance.add_node(dynamic_source_node, :dynamic_source)
|
39
43
|
method_policy = build_source_policy(method_name, dynamic_source_node)
|
40
44
|
Contrast::Agent::Patching::Policy::Patcher.patch_method(klass, instance_methods, method_policy)
|
41
|
-
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
42
45
|
next unless current_context
|
43
46
|
|
44
|
-
dynamic_source = create_dynamic_source(
|
47
|
+
dynamic_source = create_dynamic_source(current_request, dynamic_source_node, field, properties)
|
45
48
|
node_id = Contrast::Utils::StringUtils.force_utf8(dynamic_source_node.id)
|
46
49
|
current_context.activity.dynamic_sources[node_id] = dynamic_source
|
47
50
|
end
|
@@ -56,8 +59,10 @@ module Contrast
|
|
56
59
|
# @param class_name [String] the name of the Class to patch
|
57
60
|
# @param method_name [Symbol] the name of the Method to patch
|
58
61
|
# @param tags [Set<String>] the tags this event should apply
|
62
|
+
# @param request [Contrast::Agent::Request] the request during
|
63
|
+
# which this source is to be created.
|
59
64
|
# @return [Contrast::Agent::Assess::Policy::SourceNode]
|
60
|
-
def create_source_node class_name, method_name, tags
|
65
|
+
def create_source_node class_name, method_name, tags, request
|
61
66
|
node = Contrast::Agent::Assess::Policy::SourceNode.new
|
62
67
|
node.class_name = class_name
|
63
68
|
node.instance_method = true
|
@@ -72,8 +77,7 @@ module Contrast
|
|
72
77
|
node.add_property(READ_TABLE, class_name)
|
73
78
|
node.add_property(READ_COLUMN, method_name)
|
74
79
|
node.add_property(WRITE_QUERY_TIME, Contrast::Utils::Timer.now_ms)
|
75
|
-
|
76
|
-
node.add_property(WRITE_QUERY_URL, url)
|
80
|
+
node.add_property(WRITE_QUERY_URL, request&.normalized_uri)
|
77
81
|
node
|
78
82
|
end
|
79
83
|
|
@@ -92,8 +96,8 @@ module Contrast
|
|
92
96
|
method_policy
|
93
97
|
end
|
94
98
|
|
95
|
-
# @param
|
96
|
-
#
|
99
|
+
# @param request [Contrast::Agent::Request] the request during
|
100
|
+
# which this source is to be created.
|
97
101
|
# @param source_node [Contrast::Agent::Assess::Policy::SourceNode]
|
98
102
|
# the SourceNode that applies to this method
|
99
103
|
# @param field [String] the name of the method to which this source
|
@@ -104,13 +108,13 @@ module Contrast
|
|
104
108
|
# @return [Contrast::Api::Dtm::DynamicSource] the message to send
|
105
109
|
# to the Service to allow it to report the events leading up to
|
106
110
|
# the creation of the Dynamic Source
|
107
|
-
def create_dynamic_source
|
111
|
+
def create_dynamic_source request, source_node, field, properties
|
108
112
|
dynamic_source = Contrast::Api::Dtm::DynamicSource.new
|
109
113
|
dynamic_source.class_name = Contrast::Utils::StringUtils.force_utf8(source_node.class_name)
|
110
114
|
dynamic_source.method_name = Contrast::Utils::StringUtils.force_utf8(field)
|
111
115
|
dynamic_source.instance_method = source_node.instance_method?
|
112
116
|
dynamic_source.target = Contrast::Utils::StringUtils.force_utf8(source_node.target_string)
|
113
|
-
append_properties!(dynamic_source,
|
117
|
+
append_properties!(dynamic_source, request, source_node, field)
|
114
118
|
append_events!(dynamic_source, properties.event)
|
115
119
|
dynamic_source
|
116
120
|
end
|
@@ -119,18 +123,18 @@ module Contrast
|
|
119
123
|
# in TeamServer
|
120
124
|
#
|
121
125
|
# @param dynamic_source [Contrast::Api::Dtm::DynamicSource] the message to send to the Service to allow it
|
122
|
-
# to report the events leading up to the creation of the Dynamic Source
|
123
|
-
# @param
|
124
|
-
# is to be created.
|
126
|
+
# to report the events leading up to the creation of the Dynamic Source.
|
127
|
+
# @param request [Contrast::Agent::Request] the request during which this source is to be created.
|
125
128
|
# @param source_node [Contrast::Agent::Assess::Policy::SourceNode] the SourceNode that applies to this
|
126
|
-
# method
|
127
|
-
# @param field [String] the name of the method to which this source applies
|
128
|
-
def append_properties! dynamic_source,
|
129
|
+
# method.
|
130
|
+
# @param field [String] the name of the method to which this source applies.
|
131
|
+
def append_properties! dynamic_source, request, source_node, field
|
129
132
|
dynamic_source.properties[READ_TABLE] = Contrast::Utils::StringUtils.force_utf8(source_node.class_name)
|
130
133
|
dynamic_source.properties[READ_COLUMN] = Contrast::Utils::StringUtils.force_utf8(field)
|
131
|
-
dynamic_source.properties[WRITE_QUERY_TIME] =
|
132
|
-
|
133
|
-
dynamic_source.properties[WRITE_QUERY_URL] =
|
134
|
+
dynamic_source.properties[WRITE_QUERY_TIME] =
|
135
|
+
Contrast::Utils::StringUtils.force_utf8(Contrast::Utils::Timer.now_ms)
|
136
|
+
dynamic_source.properties[WRITE_QUERY_URL] =
|
137
|
+
Contrast::Utils::StringUtils.force_utf8(request&.normalized_uri)
|
134
138
|
end
|
135
139
|
|
136
140
|
def append_events! dynamic_source, event
|
@@ -1,11 +1,12 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/assess/policy/policy'
|
5
5
|
require 'contrast/agent/patching/policy/patcher'
|
6
6
|
require 'contrast/agent/patching/policy/method_policy'
|
7
7
|
require 'contrast/agent/patching/policy/module_policy'
|
8
|
-
require 'contrast/components/
|
8
|
+
require 'contrast/components/logger'
|
9
|
+
require 'contrast/components/scope'
|
9
10
|
|
10
11
|
module Contrast
|
11
12
|
module Agent
|
@@ -16,8 +17,9 @@ module Contrast
|
|
16
17
|
# provides a map for which methods our renamed functions need to call
|
17
18
|
# and how.
|
18
19
|
module Patcher
|
19
|
-
|
20
|
-
|
20
|
+
extend Contrast::Components::Logger::InstanceMethods
|
21
|
+
extend Contrast::Components::Scope::InstanceMethods
|
22
|
+
|
21
23
|
|
22
24
|
class << self
|
23
25
|
def policy
|
@@ -34,24 +36,18 @@ module Contrast
|
|
34
36
|
# called. This hook is provided so that patches to those methods can
|
35
37
|
# pass us execution flow once a new method has been made available.
|
36
38
|
def patch_assess_on_eval mod
|
37
|
-
return unless ASSESS.enabled?
|
39
|
+
return unless ::Contrast::ASSESS.enabled?
|
38
40
|
return if in_contrast_scope?
|
39
41
|
|
40
42
|
patcher.patch_specific_module(mod)
|
41
43
|
rescue StandardError => e
|
42
|
-
logger.warn(
|
43
|
-
'Unable to patch assess during eval',
|
44
|
-
e,
|
45
|
-
module: mod.cs__name)
|
44
|
+
logger.warn('Unable to patch assess during eval', e, module: mod.cs__name)
|
46
45
|
end
|
47
46
|
|
48
47
|
# Exposed so that methods can be dynamically patched on creation at
|
49
48
|
# runtime, like those generated by
|
50
49
|
# ActiveRecord::AttributeMethods::Read::ClassMethods#define_method_attribute
|
51
|
-
CLASS_TYPES = [
|
52
|
-
Contrast::Utils::ObjectShare::CLASS,
|
53
|
-
Contrast::Utils::ObjectShare::MODULE
|
54
|
-
].cs__freeze
|
50
|
+
CLASS_TYPES = [Contrast::Utils::ObjectShare::CLASS, Contrast::Utils::ObjectShare::MODULE].cs__freeze
|
55
51
|
def patch_assess_method mod, method_name
|
56
52
|
# Module.define_method is called a lot in Class and Module. We
|
57
53
|
# currently do not expect these define_methods to result in methods
|
@@ -62,7 +58,8 @@ module Contrast
|
|
62
58
|
return if CLASS_TYPES.include?(class_name)
|
63
59
|
return unless ASSESS.enabled?
|
64
60
|
|
65
|
-
source_nodes = Contrast::Agent::Patching::Policy::ModulePolicy.nodes_for_module(policy.sources,
|
61
|
+
source_nodes = Contrast::Agent::Patching::Policy::ModulePolicy.nodes_for_module(policy.sources,
|
62
|
+
class_name)
|
66
63
|
return if source_nodes.empty?
|
67
64
|
|
68
65
|
method_array = []
|
@@ -70,17 +67,15 @@ module Contrast
|
|
70
67
|
source_nodes.each do |source_node|
|
71
68
|
next unless source_node.method_name.to_s == method_name
|
72
69
|
|
73
|
-
method_policy =
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
method_policy =
|
71
|
+
Contrast::Agent::Patching::Policy::MethodPolicy.new(source_node: source_node,
|
72
|
+
method_name: source_node.method_name,
|
73
|
+
method_visibility: source_node.method_visibility,
|
74
|
+
instance_method: true)
|
77
75
|
patcher.patch_method(mod, method_array, method_policy)
|
78
76
|
end
|
79
77
|
rescue StandardError => e
|
80
|
-
logger.warn(
|
81
|
-
'Unable to patch assess during define_method_attribute',
|
82
|
-
e,
|
83
|
-
module: mod.cs__name)
|
78
|
+
logger.warn('Unable to patch assess during define_method_attribute', e, module: mod.cs__name)
|
84
79
|
end
|
85
80
|
end
|
86
81
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'json'
|
@@ -26,7 +26,7 @@ module Contrast
|
|
26
26
|
# Indicates is this feature has been disabled by the configuration,
|
27
27
|
# read at startup, and therefore can never be enabled.
|
28
28
|
def disabled_globally?
|
29
|
-
ASSESS.forcibly_disabled?
|
29
|
+
::Contrast::ASSESS.forcibly_disabled?
|
30
30
|
end
|
31
31
|
|
32
32
|
def node_type
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/patching/policy/policy_node'
|
@@ -35,16 +35,6 @@ module Contrast
|
|
35
35
|
:TYPE_METHOD
|
36
36
|
end
|
37
37
|
|
38
|
-
def target
|
39
|
-
@_target ||= begin
|
40
|
-
if targets&.any?
|
41
|
-
targets[0]
|
42
|
-
elsif sources&.any?
|
43
|
-
sources[0]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
38
|
def target_string= value
|
49
39
|
@target_string = value
|
50
40
|
@targets = convert_policy_markers(value)
|
@@ -85,8 +75,7 @@ module Contrast
|
|
85
75
|
next if Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
|
86
76
|
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
|
87
77
|
|
88
|
-
raise(ArgumentError,
|
89
|
-
"#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
|
78
|
+
raise(ArgumentError, "#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
|
90
79
|
end
|
91
80
|
end
|
92
81
|
|
@@ -100,27 +89,26 @@ module Contrast
|
|
100
89
|
# Trigger (trigger nodes) don't have targets (they are the target)
|
101
90
|
# Everything else (propagation nodes) are Source2Target
|
102
91
|
def build_action
|
103
|
-
@event_action ||=
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
92
|
+
@event_action ||= case node_class
|
93
|
+
when Contrast::Agent::Assess::Policy::SourceNode::SOURCE
|
94
|
+
:CREATION
|
95
|
+
when Contrast::Agent::Assess::Policy::TriggerNode::TRIGGER
|
96
|
+
:TRIGGER
|
97
|
+
else
|
98
|
+
if source_string.nil?
|
99
|
+
:CREATION
|
100
|
+
elsif target_string.nil?
|
101
|
+
:TRIGGER
|
102
|
+
else
|
103
|
+
# TeamServer can't handle the multi-source or multi-target values. Give it some help
|
104
|
+
# by changing them to 'A'
|
105
|
+
source = all_type?(source_string) ? ALL_TYPE : source_string
|
106
|
+
target = all_type?(target_string) ? ALL_TYPE : target_string
|
107
|
+
str = source[0] + TO_MARKER + target[0]
|
108
|
+
str.to_sym
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
124
112
|
@event_action
|
125
113
|
end
|
126
114
|
|
@@ -158,6 +146,10 @@ module Contrast
|
|
158
146
|
end
|
159
147
|
converted
|
160
148
|
end
|
149
|
+
|
150
|
+
def all_type? marker
|
151
|
+
marker.include?(Contrast::Utils::ObjectShare::COMMA)
|
152
|
+
end
|
161
153
|
end
|
162
154
|
end
|
163
155
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require 'contrast/components/interface'
|
5
4
|
require 'contrast/utils/object_share'
|
6
5
|
|
7
6
|
module Contrast
|
@@ -13,8 +12,7 @@ module Contrast
|
|
13
12
|
# of a file vs data flow, such as the detection of Hardcoded Passwords
|
14
13
|
# or Keys.
|
15
14
|
module PolicyScanner
|
16
|
-
|
17
|
-
access_component :analysis
|
15
|
+
|
18
16
|
|
19
17
|
class << self
|
20
18
|
# Use the given trace_point, built from an :end event, to determine
|
@@ -24,8 +22,8 @@ module Contrast
|
|
24
22
|
# @param trace_point [TracePoint] the TracePoint generated by an
|
25
23
|
# :end event at the end of a Module definition.
|
26
24
|
def scan trace_point
|
27
|
-
return unless ASSESS.enabled?
|
28
|
-
return unless ASSESS.require_scan?
|
25
|
+
return unless ::Contrast::ASSESS.enabled?
|
26
|
+
return unless ::Contrast::ASSESS.require_scan?
|
29
27
|
|
30
28
|
provider_values = policy.providers.values
|
31
29
|
return if provider_values.all?(&:disabled?)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require 'contrast/components/
|
4
|
+
require 'contrast/components/logger'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -9,8 +9,8 @@ module Contrast
|
|
9
9
|
# In order to properly shift tags to account for the changes this method
|
10
10
|
# caused, we'll need to store the state before the change occurred.
|
11
11
|
class PreShift
|
12
|
-
include Contrast::Components::
|
13
|
-
|
12
|
+
include Contrast::Components::Logger::InstanceMethods
|
13
|
+
|
14
14
|
|
15
15
|
UNDUPLICABLE_MODULES = [
|
16
16
|
Enumerator # dup'ing results in 'can't copy execution context'
|
@@ -37,7 +37,7 @@ module Contrast
|
|
37
37
|
# being called or nil if one is not required.
|
38
38
|
def build_preshift propagation_node, object, args
|
39
39
|
return unless propagation_node
|
40
|
-
return unless ASSESS.enabled?
|
40
|
+
return unless ::Contrast::ASSESS.enabled?
|
41
41
|
|
42
42
|
initializing = propagation_node.method_name == :initialize
|
43
43
|
return if unsafe_io_object?(object, initializing)
|
@@ -91,7 +91,9 @@ module Contrast
|
|
91
91
|
|
92
92
|
Contrast::Agent::Assess::Tracker.copy(original_arg, preshift_arg)
|
93
93
|
end
|
94
|
-
preshift.arg_lengths = preshift.args.map
|
94
|
+
preshift.arg_lengths = preshift.args.map do |preshift_arg|
|
95
|
+
Contrast::Utils::DuckUtils.quacks_to?(preshift_arg, :length) ? preshift_arg.length : 0
|
96
|
+
end
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'set'
|
5
5
|
|
6
6
|
require 'contrast/agent/assess/policy/propagator'
|
7
|
-
require 'contrast/components/
|
7
|
+
require 'contrast/components/logger'
|
8
8
|
require 'contrast/utils/object_share'
|
9
9
|
require 'contrast/utils/sha256_builder'
|
10
10
|
|
@@ -17,8 +17,8 @@ module Contrast
|
|
17
17
|
# general, these methods work on the String class or a holder of
|
18
18
|
# Strings
|
19
19
|
module PropagationMethod
|
20
|
-
|
21
|
-
|
20
|
+
extend Contrast::Components::Logger::InstanceMethods
|
21
|
+
|
22
22
|
|
23
23
|
APPEND_ACTION = 'APPEND'
|
24
24
|
CENTER_ACTION = 'CENTER'
|
@@ -86,10 +86,6 @@ module Contrast
|
|
86
86
|
SPLIT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Split
|
87
87
|
}.cs__freeze
|
88
88
|
|
89
|
-
def context_available?
|
90
|
-
!!Contrast::Agent::REQUEST_TRACKER.current
|
91
|
-
end
|
92
|
-
|
93
89
|
# I lied above. We had to figure out what the target of the
|
94
90
|
# propagation was. Now that we know, we'll actually do things to
|
95
91
|
# it. Note that the return of this method will replace the original
|
@@ -144,13 +140,7 @@ module Contrast
|
|
144
140
|
!!target
|
145
141
|
end
|
146
142
|
|
147
|
-
ZERO_LENGTH_ACTIONS = [
|
148
|
-
DB_WRITE_ACTION,
|
149
|
-
CUSTOM_ACTION,
|
150
|
-
KEEP_ACTION,
|
151
|
-
REPLACE_ACTION,
|
152
|
-
SPLAT_ACTION
|
153
|
-
].cs__freeze
|
143
|
+
ZERO_LENGTH_ACTIONS = [DB_WRITE_ACTION, CUSTOM_ACTION, KEEP_ACTION, REPLACE_ACTION, SPLAT_ACTION].cs__freeze
|
154
144
|
# If the action required needs a length and the target does not have
|
155
145
|
# one, the length is not valid
|
156
146
|
def valid_length? target, action
|
@@ -225,7 +215,7 @@ module Contrast
|
|
225
215
|
|
226
216
|
# This is checked right before actual propagation
|
227
217
|
def propagation_possible? propagation_node, target
|
228
|
-
return false unless
|
218
|
+
return false unless propagation_node && valid_target?(target, propagation_node)
|
229
219
|
return false unless valid_length?(target, propagation_node.action)
|
230
220
|
|
231
221
|
true
|
@@ -249,7 +239,7 @@ module Contrast
|
|
249
239
|
|
250
240
|
def handle_enumerable_propagation propagation_node, preshift, target, object, ret, args, block
|
251
241
|
target.each do |value|
|
252
|
-
next if target == value
|
242
|
+
next if target == value
|
253
243
|
|
254
244
|
apply_propagator(propagation_node, preshift, value, object, ret, args, block)
|
255
245
|
end
|
@@ -287,9 +277,7 @@ module Contrast
|
|
287
277
|
|
288
278
|
properties.add_properties(propagation_node.properties)
|
289
279
|
properties.build_event(propagation_node, target, object, ret, args)
|
290
|
-
logger.trace('Propagation detected',
|
291
|
-
node_id: propagation_node.id,
|
292
|
-
target_id: target.__id__)
|
280
|
+
logger.trace('Propagation detected', node_id: propagation_node.id, target_id: target.__id__)
|
293
281
|
restore_frozen_state ? ret : nil
|
294
282
|
end
|
295
283
|
|
@@ -300,10 +288,9 @@ module Contrast
|
|
300
288
|
# @return [Contrast::Agent::Assess::Policy::Propagator, nil]
|
301
289
|
def find_propagation_class propagation_node
|
302
290
|
unless (propagation_class = PROPAGATION_ACTIONS.fetch(propagation_node.action, nil))
|
303
|
-
logger.warn(
|
304
|
-
|
305
|
-
|
306
|
-
action: propagation_node.action)
|
291
|
+
logger.warn('Unknown propagation action received. Unable to propagate.',
|
292
|
+
node_id: propagation_node.id,
|
293
|
+
action: propagation_node.action)
|
307
294
|
end
|
308
295
|
propagation_class
|
309
296
|
end
|
@@ -315,7 +302,7 @@ module Contrast
|
|
315
302
|
# propagation event.
|
316
303
|
# @return [Boolean]
|
317
304
|
def can_handle_frozen? propagation_node
|
318
|
-
ASSESS.track_frozen_sources? && propagation_node.targets[0] == Contrast::Utils::ObjectShare::RETURN_KEY
|
305
|
+
::Contrast::ASSESS.track_frozen_sources? && propagation_node.targets[0] == Contrast::Utils::ObjectShare::RETURN_KEY
|
319
306
|
end
|
320
307
|
end
|
321
308
|
end
|