contrast-agent 4.3.1 → 4.6.0
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/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/Rakefile +1 -1
- data/exe/contrast_service +1 -1
- data/ext/build_funchook.rb +1 -1
- 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 +1 -1
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +20 -1
- data/lib/contrast/agent.rb +6 -4
- data/lib/contrast/agent/assess.rb +1 -10
- data/lib/contrast/agent/assess/contrast_event.rb +54 -71
- data/lib/contrast/agent/assess/contrast_object.rb +6 -3
- data/lib/contrast/agent/assess/events/event_factory.rb +1 -1
- 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 +33 -34
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +30 -15
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
- data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +30 -19
- data/lib/contrast/agent/assess/policy/propagation_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/append.rb +29 -14
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +22 -17
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +1 -1
- 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/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 +1 -1
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +24 -14
- data/lib/contrast/agent/assess/policy/propagator/split.rb +15 -8
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +31 -15
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +66 -35
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_method.rb +87 -76
- 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 +1 -1
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +3 -3
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +7 -8
- data/lib/contrast/agent/assess/policy/trigger_method.rb +106 -64
- data/lib/contrast/agent/assess/policy/trigger_node.rb +31 -10
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +59 -0
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -3
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +7 -5
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +3 -5
- data/lib/contrast/agent/assess/properties.rb +1 -3
- data/lib/contrast/agent/assess/property/evented.rb +1 -1
- data/lib/contrast/agent/assess/property/tagged.rb +38 -20
- 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 +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +1 -1
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +2 -2
- data/lib/contrast/agent/at_exit_hook.rb +1 -1
- data/lib/contrast/agent/class_reopener.rb +1 -1
- 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 +1 -1
- data/lib/contrast/agent/exclusion_matcher.rb +1 -1
- data/lib/contrast/agent/inventory.rb +1 -2
- data/lib/contrast/agent/inventory/dependencies.rb +1 -1
- data/lib/contrast/agent/inventory/dependency_analysis.rb +1 -1
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +35 -23
- data/lib/contrast/agent/inventory/policy/datastores.rb +1 -1
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +112 -109
- data/lib/contrast/agent/module_data.rb +1 -1
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +1 -1
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +5 -1
- data/lib/contrast/agent/patching/policy/method_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/patch.rb +12 -13
- data/lib/contrast/agent/patching/policy/patch_status.rb +2 -2
- data/lib/contrast/agent/patching/policy/patcher.rb +59 -54
- data/lib/contrast/agent/patching/policy/policy.rb +14 -21
- data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/patching/policy/trigger_node.rb +6 -3
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/policy.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +1 -1
- data/lib/contrast/agent/protect/rule/base.rb +7 -18
- data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +2 -2
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +2 -2
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -1
- data/lib/contrast/agent/protect/rule/sqli.rb +18 -12
- 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 +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +1 -1
- data/lib/contrast/agent/railtie.rb +1 -1
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- data/lib/contrast/agent/request.rb +2 -1
- data/lib/contrast/agent/request_context.rb +17 -10
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +1 -1
- data/lib/contrast/agent/rewriter.rb +1 -1
- data/lib/contrast/agent/rule_set.rb +3 -3
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +1 -1
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/thread.rb +2 -2
- data/lib/contrast/agent/thread_watcher.rb +21 -6
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- 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 +19 -22
- data/lib/contrast/api/communication/response_processor.rb +11 -4
- 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 +23 -15
- data/lib/contrast/api/communication/speedracer.rb +3 -3
- 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 +3 -1
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/agent_startup.rb +58 -0
- data/lib/contrast/api/decorators/application_settings.rb +1 -1
- data/lib/contrast/api/decorators/application_startup.rb +53 -0
- data/lib/contrast/api/decorators/application_update.rb +1 -1
- data/lib/contrast/api/decorators/http_request.rb +1 -1
- data/lib/contrast/api/decorators/input_analysis.rb +1 -1
- data/lib/contrast/api/decorators/instrumentation_mode.rb +37 -0
- data/lib/contrast/api/decorators/library.rb +1 -1
- data/lib/contrast/api/decorators/library_usage_update.rb +1 -1
- data/lib/contrast/api/decorators/message.rb +1 -1
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +1 -1
- data/lib/contrast/api/decorators/route_coverage.rb +16 -6
- data/lib/contrast/api/decorators/server_features.rb +1 -1
- data/lib/contrast/api/decorators/trace_event.rb +43 -15
- data/lib/contrast/api/decorators/trace_event_object.rb +1 -1
- 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 +1 -1
- data/lib/contrast/api/decorators/user_input.rb +1 -1
- data/lib/contrast/components/agent.rb +7 -11
- data/lib/contrast/components/app_context.rb +5 -23
- data/lib/contrast/components/assess.rb +6 -11
- data/lib/contrast/components/config.rb +1 -1
- data/lib/contrast/components/contrast_service.rb +1 -1
- data/lib/contrast/components/heap_dump.rb +1 -1
- data/lib/contrast/components/interface.rb +1 -1
- data/lib/contrast/components/inventory.rb +1 -1
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/protect.rb +11 -14
- data/lib/contrast/components/sampling.rb +49 -7
- data/lib/contrast/components/scope.rb +2 -1
- data/lib/contrast/components/settings.rb +27 -99
- 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 +1 -1
- data/lib/contrast/config/base_configuration.rb +1 -1
- data/lib/contrast/config/default_value.rb +1 -1
- data/lib/contrast/config/exception_configuration.rb +1 -1
- data/lib/contrast/config/heap_dump_configuration.rb +1 -1
- data/lib/contrast/config/inventory_configuration.rb +1 -1
- data/lib/contrast/config/logger_configuration.rb +1 -1
- 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 +1 -1
- data/lib/contrast/delegators/input_analysis.rb +12 -0
- data/lib/contrast/extension/assess.rb +1 -1
- data/lib/contrast/extension/assess/array.rb +1 -1
- data/lib/contrast/extension/assess/erb.rb +1 -1
- data/lib/contrast/extension/assess/eval_trigger.rb +1 -5
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -5
- data/lib/contrast/extension/assess/fiber.rb +1 -1
- data/lib/contrast/extension/assess/hash.rb +1 -1
- data/lib/contrast/extension/assess/kernel.rb +1 -1
- data/lib/contrast/extension/assess/marshal.rb +1 -5
- data/lib/contrast/extension/assess/regexp.rb +1 -1
- data/lib/contrast/extension/assess/string.rb +1 -1
- data/lib/contrast/extension/delegator.rb +1 -1
- data/lib/contrast/extension/inventory.rb +1 -1
- data/lib/contrast/extension/kernel.rb +1 -1
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +1 -1
- data/lib/contrast/extension/protect/kernel.rb +1 -1
- 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 +13 -15
- data/lib/contrast/framework/platform_version.rb +1 -1
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rack/patch/support.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +1 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -1
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +4 -4
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +1 -1
- data/lib/contrast/framework/rails/support.rb +43 -44
- data/lib/contrast/framework/sinatra/support.rb +101 -42
- data/lib/contrast/funchook/funchook.rb +1 -1
- data/lib/contrast/logger/application.rb +1 -1
- data/lib/contrast/logger/format.rb +1 -1
- data/lib/contrast/logger/log.rb +32 -16
- data/lib/contrast/logger/request.rb +1 -1
- data/lib/contrast/logger/time.rb +1 -1
- data/lib/contrast/security_exception.rb +1 -1
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +1 -1
- data/lib/contrast/utils/assess/sampling_util.rb +1 -1
- data/lib/contrast/utils/assess/tracking_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +18 -4
- 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 +14 -19
- data/lib/contrast/utils/heap_dump_util.rb +104 -88
- data/lib/contrast/utils/invalid_configuration_util.rb +22 -13
- data/lib/contrast/utils/inventory_util.rb +1 -1
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/job_servers_running.rb +1 -1
- data/lib/contrast/utils/object_share.rb +1 -1
- data/lib/contrast/utils/os.rb +1 -1
- 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 +1 -1
- 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 +1 -1
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -1
- data/lib/contrast/utils/timer.rb +1 -1
- data/resources/assess/policy.json +8 -11
- data/resources/deadzone/policy.json +7 -17
- data/ruby-agent.gemspec +59 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +134 -137
- data/lib/contrast/agent/assess/rule.rb +0 -18
- data/lib/contrast/agent/assess/rule/base.rb +0 -52
- data/lib/contrast/agent/assess/rule/redos.rb +0 -67
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +0 -38
- data/lib/contrast/common_agent_configuration.rb +0 -87
- data/lib/contrast/framework/sinatra/patch/base.rb +0 -83
- data/lib/contrast/framework/sinatra/patch/support.rb +0 -27
- data/lib/contrast/utils/prevent_serialization.rb +0 -52
@@ -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
|
module Contrast
|
@@ -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/assess/policy/source_method'
|
@@ -8,11 +8,13 @@ module Contrast
|
|
8
8
|
module Assess
|
9
9
|
module Policy
|
10
10
|
module SourceValidation
|
11
|
-
# Validator used to assert a CROSS_SITE tag is actually applicable to
|
12
|
-
#
|
11
|
+
# Validator used to assert a CROSS_SITE tag is actually applicable to the given method before applying the
|
12
|
+
# tag to its target
|
13
13
|
module CrossSiteValidator
|
14
|
-
#
|
15
|
-
#
|
14
|
+
# Prevent the application of a tag if it is from a source known to not apply a tag in a provided context.
|
15
|
+
# Note that for Rack, the Header will be HTTP_REFERER. Rails does some help in
|
16
|
+
# ActionDispatch::Http::Headers to convert keys like `referer` to `HTTP_REFERER` before they get to the
|
17
|
+
# Rack::Request#get_header method
|
16
18
|
# https://bitbucket.org/contrastsecurity/assess-specifications/src/master/rules/dataflow/reflected_xss.md
|
17
19
|
def self.valid? tag, source_type, source_name
|
18
20
|
return true unless tag == 'CROSS_SITE'
|
@@ -20,7 +22,7 @@ module Contrast
|
|
20
22
|
return true unless source_type == Contrast::Agent::Assess::Policy::SourceMethod::HEADER_TYPE
|
21
23
|
return false unless source_name
|
22
24
|
|
23
|
-
source_name
|
25
|
+
source_name == 'HTTP_REFERER'
|
24
26
|
end
|
25
27
|
end
|
26
28
|
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 'contrast/agent/assess/policy/source_validation/cross_site_validator'
|
@@ -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
|
module Contrast
|
@@ -24,7 +24,7 @@ module Contrast
|
|
24
24
|
}.cs__freeze
|
25
25
|
TEMPLATE_PROPAGATION_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(NODE_HASH)
|
26
26
|
|
27
|
-
def xss_tilt_trigger
|
27
|
+
def xss_tilt_trigger trigger_node, _source, object, ret, *args
|
28
28
|
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
29
29
|
|
30
30
|
scope = args[0]
|
@@ -44,7 +44,7 @@ module Contrast
|
|
44
44
|
end
|
45
45
|
|
46
46
|
if Contrast::Agent::Assess::Tracker.tracked?(ret)
|
47
|
-
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
|
47
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node, ret, erb_template_prerender, ret, interpolated_inputs)
|
48
48
|
end
|
49
49
|
|
50
50
|
ret
|
@@ -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/components/interface'
|
@@ -19,31 +19,30 @@ module Contrast
|
|
19
19
|
include Contrast::Components::Interface
|
20
20
|
|
21
21
|
class << self
|
22
|
-
def xpath_expression_trigger
|
22
|
+
def xpath_expression_trigger trigger_node, _source, object, ret, *args
|
23
23
|
return ret unless args
|
24
24
|
|
25
|
-
process(
|
25
|
+
process(trigger_node, object, ret, *args)
|
26
26
|
end
|
27
27
|
|
28
|
-
def xpath_oga_trigger
|
28
|
+
def xpath_oga_trigger trigger_node, _source, object, ret, *args
|
29
29
|
return ret unless args
|
30
30
|
|
31
31
|
# convert the options arg in Oga::XML::CharacterNode#initialize into an
|
32
32
|
# array of its values so we can check if any are unsafe
|
33
33
|
args = args.first.values if args.first.cs__is_a?(Hash)
|
34
|
-
process(
|
34
|
+
process(trigger_node, object, ret, *args)
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def process
|
39
|
+
def process trigger_node, object, ret, *args
|
40
40
|
args.each do |arg|
|
41
41
|
next unless arg.cs__is_a?(String) || arg.cs__is_a?(Symbol)
|
42
42
|
next unless Contrast::Agent::Assess::Tracker.tracked?(arg)
|
43
43
|
next unless trigger_node.violated?(arg)
|
44
44
|
|
45
|
-
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
|
46
|
-
context, trigger_node, arg, object, ret, *args)
|
45
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node, arg, object, ret, *args)
|
47
46
|
end
|
48
47
|
|
49
48
|
ret
|
@@ -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/assess/events/event_factory'
|
@@ -27,24 +27,6 @@ module Contrast
|
|
27
27
|
CURRENT_FINDING_VERSION = 4
|
28
28
|
|
29
29
|
class << self
|
30
|
-
# Append the given finding to the given context to be reported when
|
31
|
-
# the Context's activity is sent to the Service or, in the absence
|
32
|
-
# of that Context, generate an Activity and queue it manually
|
33
|
-
# @param finding [Contrast::Api::Dtm::Finding]
|
34
|
-
def report_finding finding
|
35
|
-
context = Contrast::Agent::REQUEST_TRACKER.current
|
36
|
-
if context
|
37
|
-
context.activity.findings << finding
|
38
|
-
else
|
39
|
-
activity = Contrast::Api::Dtm::Activity.new
|
40
|
-
activity.findings << finding
|
41
|
-
|
42
|
-
Contrast::Agent.messaging_queue.send_event_eventually(activity)
|
43
|
-
end
|
44
|
-
logger.debug('Finding reported',
|
45
|
-
rule: finding.rule_id)
|
46
|
-
end
|
47
|
-
|
48
30
|
# This is called from within our woven proc. It will be called as if it
|
49
31
|
# were inline in the Rack application.
|
50
32
|
#
|
@@ -57,22 +39,17 @@ module Contrast
|
|
57
39
|
def apply_trigger_rule trigger_node, object, ret, args
|
58
40
|
return if trigger_node.nil?
|
59
41
|
|
60
|
-
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
61
|
-
return unless current_context&.analyze_request? && ASSESS.enabled?
|
62
|
-
|
63
42
|
if trigger_node.sources&.any?
|
64
43
|
trigger_node.sources.each do |marker|
|
65
44
|
source = determine_source(marker, object, ret, args)
|
66
|
-
apply_trigger(
|
67
|
-
trigger_node,
|
45
|
+
apply_trigger(trigger_node,
|
68
46
|
source,
|
69
47
|
object,
|
70
48
|
ret,
|
71
49
|
*args)
|
72
50
|
end
|
73
51
|
else
|
74
|
-
apply_trigger(
|
75
|
-
trigger_node,
|
52
|
+
apply_trigger(trigger_node,
|
76
53
|
nil,
|
77
54
|
object,
|
78
55
|
ret,
|
@@ -80,15 +57,13 @@ module Contrast
|
|
80
57
|
end
|
81
58
|
end
|
82
59
|
|
83
|
-
def apply_eval_trigger
|
84
|
-
apply_trigger(
|
60
|
+
def apply_eval_trigger trigger_node, source, object, ret, *args
|
61
|
+
apply_trigger(trigger_node, source, object, ret, *args)
|
85
62
|
end
|
86
63
|
|
87
64
|
# This converts the source of the finding, and the events leading
|
88
65
|
# up to it into a Finding
|
89
66
|
#
|
90
|
-
# @param context [Contrast::Agent::RequestContext] the current
|
91
|
-
# request context
|
92
67
|
# @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode]
|
93
68
|
# the node to direct applying this trigger event
|
94
69
|
# @param source [Object] the source of the Trigger Event
|
@@ -99,39 +74,96 @@ module Contrast
|
|
99
74
|
# @return [Contrast::Api::Dtm::Finding, nil] the
|
100
75
|
# Contrast::Api::Dtm::Finding to send to TeamServer or nil if
|
101
76
|
# conditions were not met
|
102
|
-
def build_finding
|
77
|
+
def build_finding trigger_node, source, object, ret, *args
|
103
78
|
return unless Contrast::Agent::Assess::Policy::TriggerValidation.valid?(trigger_node, object, ret, args)
|
104
79
|
|
105
|
-
request =
|
106
|
-
|
107
|
-
return if defined?(ActionController::Live) &&
|
108
|
-
env &&
|
109
|
-
env['action_controller.instance'].cs__class.included_modules.include?(ActionController::Live)
|
80
|
+
request = find_request(source)
|
81
|
+
return unless reportable?(request&.env)
|
110
82
|
|
111
83
|
finding = Contrast::Api::Dtm::Finding.new
|
112
84
|
finding.rule_id = Contrast::Utils::StringUtils.protobuf_safe_string(trigger_node.rule_id)
|
113
|
-
|
114
|
-
|
115
|
-
finding
|
116
|
-
|
117
|
-
finding.routes << context.route if context.route
|
85
|
+
|
86
|
+
append_events(finding, trigger_node, source, object, ret, args)
|
87
|
+
append_route(finding, request)
|
88
|
+
append_hash(finding, source, request)
|
118
89
|
finding.version = determine_compliance_version(finding)
|
119
90
|
logger.trace('Finding created',
|
120
91
|
node_id: trigger_node.id,
|
121
92
|
source_id: source.__id__,
|
122
93
|
rule: trigger_node.rule_id)
|
123
|
-
report_finding(finding)
|
94
|
+
report_finding(finding, request)
|
124
95
|
rescue StandardError => e
|
125
96
|
logger.error('Unable to build a finding', e, rule: trigger_node.rule_id, node_id: trigger_node.id)
|
126
97
|
end
|
127
98
|
|
99
|
+
# Given a finding, append it to an activity message and send it to
|
100
|
+
# the Service for processing.
|
101
|
+
#
|
102
|
+
# @param finding [Contrast::Api::Dtm::Finding] the Finding to
|
103
|
+
# report.
|
104
|
+
# @param request [Contrast::Agent::Request] our wrapper around the
|
105
|
+
# Rack::Request.
|
106
|
+
def report_finding finding, request = nil
|
107
|
+
context = Contrast::Agent::REQUEST_TRACKER.current
|
108
|
+
if context
|
109
|
+
context.activity.findings << finding
|
110
|
+
return
|
111
|
+
end
|
112
|
+
|
113
|
+
activity = Contrast::Api::Dtm::Activity.new
|
114
|
+
activity.findings << finding
|
115
|
+
if request
|
116
|
+
activity.http_request = request.dtm
|
117
|
+
else
|
118
|
+
logger.debug('Attempted to report finding without request', finding: finding)
|
119
|
+
end
|
120
|
+
|
121
|
+
# If we're out of request context, then we need to report this
|
122
|
+
# finding ourselves, so we'll send it in the one-off activity we
|
123
|
+
# created.
|
124
|
+
Contrast::Agent.messaging_queue.send_event_eventually(activity)
|
125
|
+
end
|
126
|
+
|
128
127
|
private
|
129
128
|
|
129
|
+
# A request is reportable if it is not from ActionController::Live
|
130
|
+
#
|
131
|
+
# @param env [Hash] the env of the Request
|
132
|
+
# @return [Boolean]
|
133
|
+
def reportable? env
|
134
|
+
!(defined?(ActionController::Live) &&
|
135
|
+
env &&
|
136
|
+
env['action_controller.instance'].cs__class.included_modules.include?(ActionController::Live))
|
137
|
+
end
|
138
|
+
|
139
|
+
# Find the request for this finding. This assumes, for now, that if
|
140
|
+
# there is an active request, then that is the request to report.
|
141
|
+
# Otherwise, we'll use the first request found in the events of the
|
142
|
+
# source_object.
|
143
|
+
#
|
144
|
+
# @param source [Object,nil] some Object used as the source of a
|
145
|
+
# trigger event
|
146
|
+
# @return [Contrast::Agent::Request,nil] the request from which the
|
147
|
+
# dataflow on the request originated.
|
148
|
+
def find_request source
|
149
|
+
return Contrast::Agent::REQUEST_TRACKER.current.request if Contrast::Agent::REQUEST_TRACKER.current
|
150
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties(source))
|
151
|
+
|
152
|
+
properties.events.each do |event|
|
153
|
+
next unless event.cs__is_a?(Contrast::Agent::Assess::Events::SourceEvent)
|
154
|
+
|
155
|
+
return event.request if event.request
|
156
|
+
end
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
|
160
|
+
def settings
|
161
|
+
Contrast::Agent::FeatureState.instance
|
162
|
+
end
|
163
|
+
|
130
164
|
# This is our method that actually checks the taint on the object
|
131
165
|
# our trigger_node targets.
|
132
166
|
#
|
133
|
-
# @param context [Contrast::Agent::RequestContext] the current
|
134
|
-
# request context
|
135
167
|
# @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode]
|
136
168
|
# the node to direct applying this trigger event
|
137
169
|
# @param source [Object] the source of the Trigger Event
|
@@ -139,19 +171,19 @@ module Contrast
|
|
139
171
|
# @param ret [Object] the Return of the invoked method
|
140
172
|
# @param args [Array<Object>] the Arguments with which the method
|
141
173
|
# was invoked
|
142
|
-
def apply_trigger
|
143
|
-
return unless
|
174
|
+
def apply_trigger trigger_node, source, object, ret, *args
|
175
|
+
return unless trigger_node
|
144
176
|
return if trigger_node.rule_disabled?
|
145
177
|
return if trigger_node.dataflow? && source.nil?
|
146
178
|
|
147
179
|
if trigger_node.regexp_rule?
|
148
|
-
apply_regexp_rule(
|
180
|
+
apply_regexp_rule(trigger_node, source, object, ret, *args)
|
149
181
|
elsif trigger_node.custom_trigger?
|
150
|
-
trigger_node.apply_custom_trigger(
|
182
|
+
trigger_node.apply_custom_trigger(trigger_node, source, object, ret, *args)
|
151
183
|
elsif trigger_node.dataflow?
|
152
|
-
apply_dataflow_rule(
|
184
|
+
apply_dataflow_rule(trigger_node, source, object, ret, *args)
|
153
185
|
else # trigger rule - just calling the method is dangerous
|
154
|
-
build_finding(
|
186
|
+
build_finding(trigger_node, source, object, ret, *args)
|
155
187
|
end
|
156
188
|
rescue StandardError => e
|
157
189
|
logger.warn('Unable to apply trigger', e, node_id: trigger_node.id)
|
@@ -199,8 +231,6 @@ module Contrast
|
|
199
231
|
# This is our method that actually checks the taint on the object
|
200
232
|
# our trigger_node targets for our Regexp based rules.
|
201
233
|
#
|
202
|
-
# @param context [Contrast::Agent::RequestContext] the current
|
203
|
-
# request context
|
204
234
|
# @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode]
|
205
235
|
# the node to direct applying this trigger event
|
206
236
|
# @param source [Object] the source of the Trigger Event
|
@@ -208,19 +238,17 @@ module Contrast
|
|
208
238
|
# @param ret [Object] the Return of the invoked method
|
209
239
|
# @param args [Array<Object>] the Arguments with which the method
|
210
240
|
# was invoked
|
211
|
-
def apply_regexp_rule
|
241
|
+
def apply_regexp_rule trigger_node, source, object, ret, *args
|
212
242
|
return unless source.is_a?(String)
|
213
243
|
return if trigger_node.good_value && source.match?(trigger_node.good_value)
|
214
244
|
return if trigger_node.bad_value && source !~ trigger_node.bad_value
|
215
245
|
|
216
|
-
build_finding(
|
246
|
+
build_finding(trigger_node, source, object, ret, *args)
|
217
247
|
end
|
218
248
|
|
219
249
|
# This is our method that actually checks the taint on the object
|
220
250
|
# our trigger_node targets for our Dataflow based rules.
|
221
251
|
#
|
222
|
-
# @param context [Contrast::Agent::RequestContext] the current
|
223
|
-
# request context
|
224
252
|
# @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode]
|
225
253
|
# the node to direct applying this trigger event
|
226
254
|
# @param source [Object] the source of the Trigger Event
|
@@ -228,22 +256,22 @@ module Contrast
|
|
228
256
|
# @param ret [Object] the Return of the invoked method
|
229
257
|
# @param args [Array<Object>] the Arguments with which the method
|
230
258
|
# was invoked
|
231
|
-
def apply_dataflow_rule
|
259
|
+
def apply_dataflow_rule trigger_node, source, object, ret, *args
|
232
260
|
return unless source
|
233
261
|
|
234
262
|
if Contrast::Agent::Assess::Tracker.trackable?(source)
|
235
263
|
return unless Contrast::Agent::Assess::Tracker.tracked?(source)
|
236
264
|
return unless trigger_node.violated?(source)
|
237
265
|
|
238
|
-
build_finding(
|
266
|
+
build_finding(trigger_node, source, object, ret, *args)
|
239
267
|
elsif Contrast::Utils::DuckUtils.iterable_hash?(source)
|
240
268
|
source.each_pair do |key, value|
|
241
|
-
apply_dataflow_rule(
|
242
|
-
apply_dataflow_rule(
|
269
|
+
apply_dataflow_rule(trigger_node, key, object, ret, *args)
|
270
|
+
apply_dataflow_rule(trigger_node, value, object, ret, *args)
|
243
271
|
end
|
244
272
|
elsif Contrast::Utils::DuckUtils.iterable_enumerable?(source)
|
245
273
|
source.each do |value|
|
246
|
-
apply_dataflow_rule(
|
274
|
+
apply_dataflow_rule(trigger_node, value, object, ret, *args)
|
247
275
|
end
|
248
276
|
else
|
249
277
|
logger.debug('Trigger source is untrackable. Unable to inspect.',
|
@@ -255,7 +283,12 @@ module Contrast
|
|
255
283
|
end
|
256
284
|
end
|
257
285
|
|
258
|
-
def
|
286
|
+
def append_events finding, trigger_node, source, object, ret, args
|
287
|
+
append_from_source(finding, source)
|
288
|
+
finding.events << Contrast::Agent::Assess::Events::EventFactory.build(trigger_node, source, object, ret, args).to_dtm_event
|
289
|
+
end
|
290
|
+
|
291
|
+
def append_from_source finding, source
|
259
292
|
return unless source
|
260
293
|
return unless Contrast::Agent::Assess::Tracker.trackable?(source)
|
261
294
|
|
@@ -286,8 +319,17 @@ module Contrast
|
|
286
319
|
finding.events << event.to_dtm_event
|
287
320
|
end
|
288
321
|
|
289
|
-
def
|
290
|
-
|
322
|
+
def append_route finding, request
|
323
|
+
context = Contrast::Agent::REQUEST_TRACKER.current
|
324
|
+
if context
|
325
|
+
finding.routes << context.route if context.route
|
326
|
+
elsif request&.route
|
327
|
+
finding.routes << request.route
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def append_hash finding, source, request
|
332
|
+
hash_code = Contrast::Utils::HashDigest.generate_event_hash(finding, source, request)
|
291
333
|
finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash_code)
|
292
334
|
finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
|
293
335
|
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 'contrast/agent/assess/policy/trigger/reflected_xss'
|
@@ -47,8 +47,8 @@ module Contrast
|
|
47
47
|
TRIGGER
|
48
48
|
end
|
49
49
|
|
50
|
-
def apply_custom_trigger
|
51
|
-
custom_trigger_class.send(@trigger_method,
|
50
|
+
def apply_custom_trigger trigger_node, source, object, ret, *args
|
51
|
+
custom_trigger_class.send(@trigger_method, trigger_node, source, object, ret, *args)
|
52
52
|
end
|
53
53
|
|
54
54
|
def custom_trigger_class
|
@@ -185,11 +185,7 @@ module Contrast
|
|
185
185
|
# @return [Array<Contrast::Agent::Assess::Tag>] the ranges satisfied
|
186
186
|
# by the given conditions
|
187
187
|
def ranges_with_all_tags length, properties, required_tags
|
188
|
-
|
189
|
-
# all the required tags, we can just return here.
|
190
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless properties.tracked?
|
191
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless required_tags&.any?
|
192
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless required_tags.all? { |tag| properties.tag_keys.include?(tag) }
|
188
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless matches_tags?(properties, required_tags)
|
193
189
|
|
194
190
|
ranges = []
|
195
191
|
chunking = false
|
@@ -229,8 +225,7 @@ module Contrast
|
|
229
225
|
# by the given conditions
|
230
226
|
def ranges_with_any_tag properties, tags
|
231
227
|
# if there aren't any all_tags or tags, break early
|
232
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless properties
|
233
|
-
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags&.any?
|
228
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless search_tags?(properties, tags)
|
234
229
|
|
235
230
|
ranges = []
|
236
231
|
tags.each do |desired|
|
@@ -243,6 +238,32 @@ module Contrast
|
|
243
238
|
end
|
244
239
|
ranges
|
245
240
|
end
|
241
|
+
|
242
|
+
# We should only try to match tags on properties if those properties have any tags (are tracked) and there
|
243
|
+
# are tags to try and match on. Some rules, like regexp rules, have no tags. Some rules, like trigger, have
|
244
|
+
# no properties.
|
245
|
+
#
|
246
|
+
# @param properties [Contrast::Agent::Assess::Properties] the properties to check for the tags
|
247
|
+
# @param tags [Set<String>] the list of tags on which to match
|
248
|
+
# @return [Boolean] if the given properties has instances of every tag in tags
|
249
|
+
def search_tags? properties, tags
|
250
|
+
return false unless properties.tracked?
|
251
|
+
return false unless tags&.any?
|
252
|
+
|
253
|
+
true
|
254
|
+
end
|
255
|
+
|
256
|
+
# Determine if the given properties have instances of all the given tags or not.
|
257
|
+
#
|
258
|
+
# @param properties [Contrast::Agent::Assess::Properties] the properties to check for the tags
|
259
|
+
# @param tags [Set<String>] the list of tags on which to match
|
260
|
+
# @return [Boolean] if the given properties has instances of every tag in tags
|
261
|
+
def matches_tags? properties, tags
|
262
|
+
return false unless search_tags?(properties, tags)
|
263
|
+
return false unless tags.all? { |tag| properties.tag_keys.include?(tag) }
|
264
|
+
|
265
|
+
true
|
266
|
+
end
|
246
267
|
end
|
247
268
|
end
|
248
269
|
end
|