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
|
require 'contrast/components/interface'
|
@@ -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/inventory/policy/trigger_node'
|
@@ -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/trigger_node'
|
@@ -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 'ipaddr'
|
@@ -16,18 +16,17 @@ require 'contrast/utils/timer'
|
|
16
16
|
|
17
17
|
module Contrast
|
18
18
|
module Agent
|
19
|
-
# This class allows the Agent to plug into the Rack middleware stack. When the
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# as it goes through the middleware stack inside of #call.
|
19
|
+
# This class allows the Agent to plug into the Rack middleware stack. When the application is first started, we
|
20
|
+
# initialize ourselves as a rack middleware inside of #initialize. Afterwards, we process each http request and
|
21
|
+
# response as it goes through the middleware stack inside of #call.
|
23
22
|
class Middleware
|
24
23
|
include Contrast::Components::Interface
|
25
24
|
access_component :agent, :config, :logging, :scope, :settings
|
26
25
|
|
27
26
|
attr_reader :app
|
28
27
|
|
29
|
-
# Allows the Agent to function as a middleware. We perform all our one-time whole-app routines in here
|
30
|
-
#
|
28
|
+
# Allows the Agent to function as a middleware. We perform all our one-time whole-app routines in here since
|
29
|
+
# we're only going to be initialized a single time. Our initialization order is:
|
31
30
|
# - capture the application
|
32
31
|
# - setup the Agent
|
33
32
|
# - startup the Agent
|
@@ -39,51 +38,27 @@ module Contrast
|
|
39
38
|
setup_agent # THIS MUST BE SECOND AND ALWAYS CALLED!
|
40
39
|
unless AGENT.enabled?
|
41
40
|
logger.error(
|
42
|
-
'The Agent was unable to initialize before the application middleware was initialized.
|
41
|
+
'The Agent was unable to initialize before the application middleware was initialized. ' \
|
42
|
+
'Disabling permanently.')
|
43
43
|
AGENT.disable! # ensure the agent is disabled (probably redundant)
|
44
44
|
return
|
45
45
|
end
|
46
46
|
agent_startup_routine
|
47
47
|
end
|
48
48
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
# processing messages
|
52
|
-
# - start the heartbeat thread, which triggers service startup
|
53
|
-
# - start instrumenting libraries and do a 'catchup' patch for everything
|
54
|
-
# we didn't see get loaded
|
55
|
-
# - enable TracePoint, which handles all class loads and required
|
56
|
-
# instrumentation going forward
|
57
|
-
def agent_startup_routine
|
58
|
-
logger.debug_with_time('middleware: starting service') do
|
59
|
-
Contrast::Agent.thread_watcher.ensure_running?
|
60
|
-
end
|
61
|
-
|
62
|
-
logger.debug_with_time('middleware: instrument shared libraries and patch') do
|
63
|
-
Contrast::Agent::Patching::Policy::Patcher.patch
|
64
|
-
end
|
65
|
-
|
66
|
-
AGENT.enable_tracepoint
|
67
|
-
Contrast::Agent::AtExitHook.exit_hook
|
68
|
-
end
|
69
|
-
|
70
|
-
# This is where we're hooked into the middleware stack. If the agent is enabled, we're ready
|
71
|
-
# to do some processing on a per request basis. If not, we just pass the request along to the
|
72
|
-
# next middleware in the stack.
|
49
|
+
# This is where we're hooked into the middleware stack. If the agent is enabled, we're ready to do some
|
50
|
+
# processing on a per request basis. If not, we just pass the request along to the next middleware in the stack.
|
73
51
|
#
|
74
|
-
# @param env [Hash] the various variables stored by this and other Middlewares to know the state
|
75
|
-
#
|
76
|
-
# @return [Array,Rack::Response] the Response of this and subsequent Middlewares to be passed back
|
77
|
-
#
|
52
|
+
# @param env [Hash] the various variables stored by this and other Middlewares to know the state and values of
|
53
|
+
# this Request
|
54
|
+
# @return [Array,Rack::Response] the Response of this and subsequent Middlewares to be passed back to the user up
|
55
|
+
# the Rack framework.
|
78
56
|
def call env
|
79
|
-
|
57
|
+
return app.call(env) unless AGENT.enabled?
|
80
58
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
else
|
85
|
-
app.call(env)
|
86
|
-
end
|
59
|
+
Contrast::Agent.heapdump_util.start_thread!
|
60
|
+
handle_first_request
|
61
|
+
call_with_agent(env)
|
87
62
|
end
|
88
63
|
|
89
64
|
private
|
@@ -103,73 +78,56 @@ module Contrast
|
|
103
78
|
end
|
104
79
|
end
|
105
80
|
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
81
|
+
# Startup the Agent as part of the initialization process:
|
82
|
+
# - start the service sending thread, responsible for sending and processing messages
|
83
|
+
# - start the heartbeat thread, which triggers service startup
|
84
|
+
# - start instrumenting libraries and do a 'catchup' patch for everything we didn't see get loaded
|
85
|
+
# - enable TracePoint, which handles all class loads and required instrumentation going forward
|
86
|
+
def agent_startup_routine
|
87
|
+
logger.debug_with_time('middleware: starting service') do
|
88
|
+
Contrast::Agent.thread_watcher.ensure_running?
|
89
|
+
end
|
90
|
+
|
91
|
+
logger.debug_with_time('middleware: instrument shared libraries and patch') do
|
92
|
+
Contrast::Agent::Patching::Policy::Patcher.patch
|
93
|
+
end
|
94
|
+
|
95
|
+
logger.debug_with_time('middleware: enabling tracepoint') do
|
96
|
+
AGENT.enable_tracepoint
|
97
|
+
end
|
98
|
+
Contrast::Agent::AtExitHook.exit_hook
|
99
|
+
end
|
100
|
+
|
101
|
+
# Some things have to wait until first request to happen, either because resolution is not complete or because
|
102
|
+
# the framework will preload classes, which confuses some of our instrumentation.
|
109
103
|
def handle_first_request
|
110
104
|
@_handle_first_request ||= begin
|
111
105
|
Contrast::Agent::StaticAnalysis.catchup
|
112
|
-
force_patching
|
113
106
|
true
|
114
107
|
end
|
115
108
|
end
|
116
109
|
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
def force_patching
|
125
|
-
force_patch(ActionDispatch::FileHandler) if defined?(ActionDispatch::FileHandler)
|
126
|
-
force_patch(ActionDispatch::Http::MimeNegotiation) if defined?(ActionDispatch::Http::MimeNegotiation)
|
127
|
-
force_patch(ActionView::Template) if defined?(ActionView::Template)
|
128
|
-
end
|
129
|
-
|
130
|
-
def force_patch mod
|
131
|
-
data = Contrast::Agent::ModuleData.new(mod)
|
132
|
-
Contrast::Agent::Patching::Policy::Patcher.send(:patch_into_module, data, true)
|
133
|
-
end
|
134
|
-
|
135
|
-
# This is where we process each request we intercept as a middleware. We make the request context
|
136
|
-
# available globally so that it can be accessed from anywhere. A RequestHandler object is made
|
137
|
-
# for each request, which handles prefilter and postfilter operations.
|
110
|
+
# This is where we process each request we intercept as a middleware. We make the request context available
|
111
|
+
# globally so that it can be accessed from anywhere. A RequestHandler object is made for each request, which
|
112
|
+
# handles prefilter and postfilter operations.
|
113
|
+
# @param env [Hash] the various variables stored by this and other Middlewares to know the state and values of
|
114
|
+
# this Request
|
115
|
+
# @return [Array,Rack::Response] the Response of this and subsequent Middlewares to be passed back to the user
|
116
|
+
# up the Rack framework.
|
138
117
|
def call_with_agent env
|
139
118
|
Contrast::Agent.thread_watcher.ensure_running?
|
140
|
-
return unless AGENT.enabled?
|
141
|
-
|
142
119
|
framework_request = Contrast::Agent.framework_manager.retrieve_request(env)
|
143
120
|
context = Contrast::Agent::RequestContext.new(framework_request)
|
144
121
|
response = nil
|
145
122
|
|
146
|
-
#
|
123
|
+
# Make the context available for the lifecycle of this request.
|
147
124
|
Contrast::Agent::REQUEST_TRACKER.lifespan(context) do
|
148
125
|
logger.request_start
|
149
126
|
request_handler = Contrast::Agent::RequestHandler.new(context)
|
150
127
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
request_handler.ruleset.prefilter
|
155
|
-
end
|
156
|
-
|
157
|
-
response = application_code(env) # pass request down the Rack chain with original env
|
158
|
-
|
159
|
-
# postfilter sequence
|
160
|
-
with_contrast_scope do
|
161
|
-
context.extract_after(response) # update context with final response information
|
162
|
-
|
163
|
-
if Contrast::Agent.framework_manager.streaming?(env)
|
164
|
-
context.reset_activity
|
165
|
-
request_handler.stream_safe_postfilter
|
166
|
-
else
|
167
|
-
request_handler.ruleset.postfilter
|
168
|
-
# return response stored in the context in case any postfilter rules updated the response data
|
169
|
-
response = context.response&.rack_response || response
|
170
|
-
request_handler.send_activity_messages
|
171
|
-
end
|
172
|
-
end
|
128
|
+
pre_call_with_agent(context, request_handler)
|
129
|
+
response = application_code(env)
|
130
|
+
post_call_with_agent(context, env, request_handler, response)
|
173
131
|
ensure
|
174
132
|
logger.request_end
|
175
133
|
end
|
@@ -179,6 +137,47 @@ module Contrast
|
|
179
137
|
handle_exception(e)
|
180
138
|
end
|
181
139
|
|
140
|
+
# Handle the operations the Agent needs to accomplish prior to the Application code executing during this
|
141
|
+
# request.
|
142
|
+
#
|
143
|
+
# @param context [Contrast::Agent::RequestContext]
|
144
|
+
# @param request_handler [Contrast::Agent::RequestHandler]
|
145
|
+
def pre_call_with_agent context, request_handler
|
146
|
+
with_contrast_scope do
|
147
|
+
context.service_extract_request
|
148
|
+
request_handler.ruleset.prefilter
|
149
|
+
end
|
150
|
+
rescue StandardError => e
|
151
|
+
raise e if security_exception?(e)
|
152
|
+
|
153
|
+
logger.error('Unable to execute agent pre_call', e)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Handle the operations the Agent needs to accomplish after the Application code executes during this request.
|
157
|
+
#
|
158
|
+
# @param context [Contrast::Agent::RequestContext]
|
159
|
+
# @param env [Hash] the various variables stored by this and other Middlewares to know the state and values of
|
160
|
+
# this Request
|
161
|
+
# @param request_handler [Contrast::Agent::RequestHandler]
|
162
|
+
# @param response [Array,Rack::Response]
|
163
|
+
def post_call_with_agent context, env, request_handler, response
|
164
|
+
with_contrast_scope do
|
165
|
+
context.extract_after(response) # update context with final response information
|
166
|
+
|
167
|
+
if Contrast::Agent.framework_manager.streaming?(env)
|
168
|
+
context.reset_activity
|
169
|
+
request_handler.stream_safe_postfilter
|
170
|
+
else
|
171
|
+
request_handler.ruleset.postfilter
|
172
|
+
request_handler.send_activity_messages
|
173
|
+
end
|
174
|
+
end
|
175
|
+
rescue StandardError => e
|
176
|
+
raise e if security_exception?(e)
|
177
|
+
|
178
|
+
logger.error('Unable to execute agent post_call', e)
|
179
|
+
end
|
180
|
+
|
182
181
|
def application_code env
|
183
182
|
logger.trace_with_time('application') do
|
184
183
|
app.call(env)
|
@@ -189,12 +188,10 @@ module Contrast
|
|
189
188
|
end
|
190
189
|
|
191
190
|
SECURITY_EXCEPTION_MARKER = 'Contrast::SecurityException'
|
192
|
-
# We're only going to suppress SecurityExceptions indicating a blocked attack.
|
193
|
-
#
|
191
|
+
# We're only going to suppress SecurityExceptions indicating a blocked attack. And, only if the
|
192
|
+
# config.agent.ruby.exceptions.capture? is set
|
194
193
|
def handle_exception exception
|
195
|
-
if
|
196
|
-
exception.message&.include?(SECURITY_EXCEPTION_MARKER)
|
197
|
-
|
194
|
+
if security_exception?(exception)
|
198
195
|
exception_control = AGENT.exception_control
|
199
196
|
raise exception unless exception_control[:enable]
|
200
197
|
|
@@ -205,18 +202,24 @@ module Contrast
|
|
205
202
|
end
|
206
203
|
end
|
207
204
|
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
205
|
+
# Is the given exception one raised by our Protect code?
|
206
|
+
#
|
207
|
+
# @param exception [Exception]
|
208
|
+
# @return [Boolean]
|
209
|
+
def security_exception? exception
|
210
|
+
exception.is_a?(Contrast::SecurityException) ||
|
211
|
+
exception.message&.include?(SECURITY_EXCEPTION_MARKER)
|
212
|
+
end
|
213
|
+
|
214
|
+
# As we deprecate support to prepare to remove dead code, we need to inform our users still relying on the now
|
215
|
+
# deprecated and soon to be removed functionality. This method handles doing that by leveraging the standard
|
216
|
+
# Kernel#warn approach
|
212
217
|
def inform_deprecations
|
213
|
-
# Ruby 2.5 is currently in security maintenance, meaning int is only
|
214
|
-
#
|
215
|
-
#
|
216
|
-
# the
|
217
|
-
#
|
218
|
-
# TODO: RUBY-715 remove this part of the method, leaving it empty if
|
219
|
-
# there are no other deprecations, when we drop 2.5 support.
|
218
|
+
# Ruby 2.5 is currently in security maintenance, meaning int is only receiving updates for security issues. It
|
219
|
+
# will move to eol on 31 March 2021. As such, we can remove support for it in Q3. We'll begin the deprecation
|
220
|
+
# warnings now so that customers have time to reach out if they'll be impacted.
|
221
|
+
# TODO: RUBY-715 remove this part of the method, leaving it empty if there are no other deprecations, when we
|
222
|
+
# drop 2.5 support.
|
220
223
|
return unless RUBY_VERSION < '2.6.0'
|
221
224
|
|
222
225
|
Kernel.warn('[Contrast Security] [DEPRECATION] Support for Ruby 2.5 will be removed in April 2021. '\
|
@@ -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/components/interface'
|
@@ -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/after_load_patch'
|
@@ -55,6 +55,10 @@ module Contrast
|
|
55
55
|
'Catching up on already loaded afterload patch - applying instrumentation',
|
56
56
|
module: after_load_patch.module_name)
|
57
57
|
after_load_patch.instrument!
|
58
|
+
rescue NameError => e
|
59
|
+
logger.error('Method undefined in afterload patch', e, module: after_load_patch.module_name, method: after_load_patch.method_to_instrument)
|
60
|
+
rescue StandardError => e
|
61
|
+
logger.error('Afterload patch failed to apply', e, module: after_load_patch.module_name, method: after_load_patch.method_to_instrument)
|
58
62
|
end
|
59
63
|
after_load_patches.delete_if(&:applied?)
|
60
64
|
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
|
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/patching/policy/method_policy'
|
@@ -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 'monitor'
|
@@ -178,7 +178,7 @@ module Contrast
|
|
178
178
|
return ret unless method_policy && ASSESS.enabled?
|
179
179
|
|
180
180
|
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
181
|
-
return ret
|
181
|
+
return ret if current_context && !current_context.analyze_request?
|
182
182
|
|
183
183
|
trigger_node = method_policy.trigger_node
|
184
184
|
Contrast::Agent::Assess::Policy::TriggerMethod.apply_trigger_rule(trigger_node, object, ret, args) if trigger_node
|
@@ -362,29 +362,27 @@ module Contrast
|
|
362
362
|
|
363
363
|
case impl
|
364
364
|
when :alias_instance, :alias_singleton
|
365
|
+
# Core to patching. Ignore define method usage cop.
|
366
|
+
# rubocop:disable Performance/Kernel/DefineMethod
|
365
367
|
unless target_module.instance_methods(false).include? underlying_method_name
|
366
368
|
# alias_method may be private
|
367
369
|
target_module.send(:alias_method, underlying_method_name, method_name)
|
368
|
-
# TODO: RUBY-1052
|
369
|
-
# rubocop:disable Performance/Kernel/DefineMethod
|
370
370
|
target_module.send(:define_method, method_name, unbound_method.bind(target_module))
|
371
|
-
# rubocop:enable Performance/Kernel/DefineMethod
|
372
371
|
end
|
373
372
|
target_module.send(visibility, method_name) # e.g., module.private(:my_method)
|
374
373
|
when :prepend
|
375
374
|
prepending_module = Module.new
|
376
|
-
# TODO: RUBY-1052
|
377
|
-
# rubocop:disable Performance/Kernel/DefineMethod
|
378
375
|
prepending_module.send(:define_method, method_name, unbound_method.bind(target_module))
|
379
|
-
# rubocop:enable Performance/Kernel/DefineMethod
|
380
376
|
prepending_module.send(visibility, method_name)
|
381
377
|
# This prepends to the singleton class (it patches a class method)
|
382
378
|
target_module.prepend prepending_module
|
379
|
+
# rubocop:enable Performance/Kernel/DefineMethod
|
383
380
|
end
|
384
381
|
# Ougai::Logger.create_item_with_2args calls Hash#[]=, so we
|
385
382
|
# can't invoke this logging method or we'll seg fault as we'd
|
386
383
|
# change the method definition mid-call
|
387
|
-
# if method_name != :[]=
|
384
|
+
# if method_name != :[]= &&
|
385
|
+
# Contrast::Agent::Logger.defined!
|
388
386
|
# logger.trace(
|
389
387
|
# 'Registered C-defined patch',
|
390
388
|
# implementation: impl,
|
@@ -392,14 +390,15 @@ module Contrast
|
|
392
390
|
# method: method_name,
|
393
391
|
# visibility: visibility)
|
394
392
|
# end
|
395
|
-
underlying_method_name
|
393
|
+
underlying_method_name
|
396
394
|
end
|
397
395
|
|
398
396
|
# @return [Boolean]
|
399
397
|
def skip_contrast_analysis?
|
400
398
|
return true if in_contrast_scope?
|
401
|
-
return
|
402
|
-
return
|
399
|
+
return false unless defined?(Contrast::Agent::REQUEST_TRACKER)
|
400
|
+
return false unless Contrast::Agent::REQUEST_TRACKER.current
|
401
|
+
return true unless Contrast::Agent::REQUEST_TRACKER.current.analyze_request?
|
403
402
|
|
404
403
|
false
|
405
404
|
end
|
@@ -411,7 +410,7 @@ module Contrast
|
|
411
410
|
def skip_assess_analysis?
|
412
411
|
return true if skip_contrast_analysis?
|
413
412
|
|
414
|
-
!ASSESS
|
413
|
+
!ASSESS&.enabled?
|
415
414
|
end
|
416
415
|
end
|
417
416
|
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
|
module Contrast
|
@@ -13,7 +13,7 @@ module Contrast
|
|
13
13
|
# one does not exist.
|
14
14
|
#
|
15
15
|
# @param mod [Module] the Module for which the status is asked
|
16
|
-
# @return [Contrast::Agent::Patching::Policy::
|
16
|
+
# @return [Contrast::Agent::Patching::Policy::PatchStatus]
|
17
17
|
def get_status mod
|
18
18
|
if mod.cs__const_defined?(status_key, false)
|
19
19
|
mod.cs__const_get(status_key, false)
|