contrast-agent 4.3.0 → 4.5.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 -2
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +87 -58
- 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 +8 -6
- 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 +1 -1
- 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 +9 -2
- 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/common_agent_configuration.rb +1 -1
- data/lib/contrast/components/agent.rb +3 -1
- data/lib/contrast/components/app_context.rb +5 -23
- data/lib/contrast/components/assess.rb +1 -1
- 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 +4 -2
- data/lib/contrast/components/sampling.rb +49 -7
- data/lib/contrast/components/scope.rb +1 -1
- data/lib/contrast/components/settings.rb +7 -6
- 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 +14 -13
- 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 -23
- data/ruby-agent.gemspec +56 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +117 -161
- 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/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/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
|
@@ -384,7 +384,8 @@ module Contrast
|
|
384
384
|
# Ougai::Logger.create_item_with_2args calls Hash#[]=, so we
|
385
385
|
# can't invoke this logging method or we'll seg fault as we'd
|
386
386
|
# change the method definition mid-call
|
387
|
-
# if method_name != :[]=
|
387
|
+
# if method_name != :[]= &&
|
388
|
+
# Contrast::Agent::Logger.defined!
|
388
389
|
# logger.trace(
|
389
390
|
# 'Registered C-defined patch',
|
390
391
|
# implementation: impl,
|
@@ -398,8 +399,9 @@ module Contrast
|
|
398
399
|
# @return [Boolean]
|
399
400
|
def skip_contrast_analysis?
|
400
401
|
return true if in_contrast_scope?
|
401
|
-
return
|
402
|
-
return
|
402
|
+
return false unless defined?(Contrast::Agent::REQUEST_TRACKER)
|
403
|
+
return false unless Contrast::Agent::REQUEST_TRACKER.current
|
404
|
+
return true unless Contrast::Agent::REQUEST_TRACKER.current.analyze_request?
|
403
405
|
|
404
406
|
false
|
405
407
|
end
|
@@ -411,7 +413,7 @@ module Contrast
|
|
411
413
|
def skip_assess_analysis?
|
412
414
|
return true if skip_contrast_analysis?
|
413
415
|
|
414
|
-
!ASSESS
|
416
|
+
!ASSESS&.enabled?
|
415
417
|
end
|
416
418
|
end
|
417
419
|
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)
|
@@ -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'
|
@@ -52,7 +52,7 @@ module Contrast
|
|
52
52
|
# startup to catchup on everything we didn't see get loaded
|
53
53
|
def patch
|
54
54
|
catchup_after_load_patches
|
55
|
-
|
55
|
+
catchup_loaded_methods
|
56
56
|
Contrast::Agent::Assess::Policy::RewriterPatch.rewrite_interpolations
|
57
57
|
end
|
58
58
|
|
@@ -62,10 +62,11 @@ module Contrast
|
|
62
62
|
# where only a subset of the Assess changes are needed.
|
63
63
|
PATCH_MONITOR = Monitor.new
|
64
64
|
|
65
|
-
|
65
|
+
# Iterate over and patch those Modules and Methods which were loaded before the Agent was enabled.
|
66
|
+
def catchup_loaded_methods
|
66
67
|
PATCH_MONITOR.synchronize do
|
67
68
|
t = Contrast::Agent::Thread.new do
|
68
|
-
|
69
|
+
synchronized_catchup_loaded_methods
|
69
70
|
end
|
70
71
|
# aborting on exception makes exceptions propagate.
|
71
72
|
t.abort_on_exception = true
|
@@ -100,7 +101,7 @@ module Contrast
|
|
100
101
|
# @param mod [Module] the module in which the patch should be
|
101
102
|
# placed.
|
102
103
|
# @param methods [Array(Symbol)] all the instance or singleton
|
103
|
-
# methods in this
|
104
|
+
# methods in this mod.
|
104
105
|
# @param method_policy [Contrast::Agent::Patching::Policy::MethodPolicy]
|
105
106
|
# the policy that applies to the given method_name.
|
106
107
|
# @return [Boolean] if patched, either by this invocation or a
|
@@ -149,7 +150,7 @@ module Contrast
|
|
149
150
|
# other functions, like rewriting or scanning. This method should
|
150
151
|
# only be invoked by the patch_methods method above in order to
|
151
152
|
# ensure it is wrapped in a synchronize call
|
152
|
-
def
|
153
|
+
def synchronized_catchup_loaded_methods
|
153
154
|
logger.trace_with_time('Running patching') do
|
154
155
|
patched = []
|
155
156
|
all_module_names.each do |patchable_name|
|
@@ -166,53 +167,37 @@ module Contrast
|
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
169
|
-
# Given the patchers that apply to this class that may apply, patch
|
170
|
-
#
|
170
|
+
# Given the patchers that apply to this class that may apply, patch Contrast method calls into the methods
|
171
|
+
# for which we have rules.
|
171
172
|
#
|
172
|
-
# @param module_data [Contrast::Agent::ModuleData] the module, and
|
173
|
-
#
|
174
|
-
#
|
175
|
-
# regardless of the state of the
|
176
|
-
# Contrast::Agent::Patching::Policy::PatchStatus status on the
|
177
|
-
# Module
|
173
|
+
# @param module_data [Contrast::Agent::ModuleData] the module, and its name, that's being patched into
|
174
|
+
# @param redo_patch [Boolean] a trigger to force patching regardless of the state of the
|
175
|
+
# Contrast::Agent::Patching::Policy::PatchStatus status on the Module
|
178
176
|
def patch_into_module module_data, redo_patch = false
|
179
177
|
status = status_type.get_status(module_data.mod)
|
180
178
|
return if (status&.patched? || status&.patching?) && !redo_patch
|
181
179
|
|
182
|
-
# Begin patching our sources into the given
|
183
|
-
#
|
184
|
-
# patching.
|
185
|
-
# Find all the patchers that apply to this class, sorted by type.
|
180
|
+
# Begin patching our sources into the given module. Any patcher that has the name of the module will be
|
181
|
+
# evaluated for patching. Find all the patchers that apply to this class, sorted by type.
|
186
182
|
module_policy = Contrast::Agent::Patching::Policy::ModulePolicy.create_module_policy(module_data.name)
|
187
|
-
|
188
|
-
|
183
|
+
# If there's nothing to match, then set that status and exit
|
184
|
+
if module_policy.empty?
|
185
|
+
status.no_patch!
|
186
|
+
return
|
187
|
+
end
|
189
188
|
|
190
189
|
status.patching!
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
unless module_policy.empty?
|
196
|
-
instance_methods = all_instance_methods(clazz, true)
|
197
|
-
singleton_methods = clazz.singleton_methods(false)
|
198
|
-
counts += patch_into_methods(clazz, instance_methods, module_policy, true)
|
199
|
-
counts += patch_into_methods(clazz, singleton_methods, module_policy, false)
|
200
|
-
counts = module_policy.num_expected_patches if adjust_for_prepend(clazz)
|
201
|
-
patched = true
|
202
|
-
end
|
190
|
+
num_applied_patches = patch_into_instance_methods(module_data, module_policy)
|
191
|
+
num_applied_patches += patch_into_singleton_methods(module_data, module_policy)
|
192
|
+
if adjust_for_prepend(module_data) ||
|
193
|
+
module_policy.num_expected_patches == num_applied_patches
|
203
194
|
|
204
|
-
|
205
|
-
if module_policy.num_expected_patches == counts
|
206
|
-
status.patched!
|
207
|
-
else
|
208
|
-
status.partial_patch!
|
209
|
-
end
|
195
|
+
status.patched!
|
210
196
|
else
|
211
|
-
status.
|
197
|
+
status.partial_patch!
|
212
198
|
end
|
213
199
|
rescue StandardError => e
|
214
|
-
status
|
215
|
-
status.failed_patch!
|
200
|
+
status&.failed_patch!
|
216
201
|
logger.warn('Patching failed', e, module: module_data.name)
|
217
202
|
ensure
|
218
203
|
logger.trace('Patching complete',
|
@@ -249,18 +234,39 @@ module Contrast
|
|
249
234
|
instance_methods
|
250
235
|
end
|
251
236
|
|
237
|
+
# Patch into the Instance Methods, including private, of the given Module that match the ModulePolicy
|
238
|
+
# provided.
|
239
|
+
#
|
240
|
+
# @param module_data [Contrast::Agent::ModuleData] the module, and its name, that's being patched into
|
241
|
+
# @param module_policy [Contrast::Agent::Patching::Policy::ModulePolicy] All the patchers that apply to
|
242
|
+
# this module, sorted by type.
|
243
|
+
def patch_into_instance_methods module_data, module_policy
|
244
|
+
mod = module_data.mod
|
245
|
+
methods = all_instance_methods(mod, true)
|
246
|
+
patch_into_methods(mod, methods, module_policy, true)
|
247
|
+
end
|
248
|
+
|
249
|
+
# Patch into the Singleton Methods of the given Module that match the ModulePolicy provided.
|
250
|
+
#
|
251
|
+
# @param module_data [Contrast::Agent::ModuleData] the module, and its name, that's being patched into
|
252
|
+
# @param module_policy [Contrast::Agent::Patching::Policy::ModulePolicy] All the patchers that apply to
|
253
|
+
# this module, sorted by type.
|
254
|
+
def patch_into_singleton_methods module_data, module_policy
|
255
|
+
mod = module_data.mod
|
256
|
+
methods = mod.singleton_methods(false)
|
257
|
+
patch_into_methods(mod, methods, module_policy, false)
|
258
|
+
end
|
259
|
+
|
252
260
|
# We've found the patchers that apply to this class (or module). Now we'll
|
253
261
|
# filter on the given method.
|
254
262
|
#
|
255
|
-
# @param mod [Module] The module from which to retrieve instance
|
256
|
-
#
|
257
|
-
# @param
|
258
|
-
#
|
259
|
-
# @param
|
260
|
-
#
|
261
|
-
# @
|
262
|
-
# are the instance or singleton methods for this module.
|
263
|
-
# @return [Integer] number of methods patched
|
263
|
+
# @param mod [Module] The module from which to retrieve instance methods.
|
264
|
+
# @param methods [Array<Symbol>] The names of all the methods in in this module
|
265
|
+
# @param module_policy [Contrast::Agent::Patching::Policy::ModulePolicy] All the patchers that apply to
|
266
|
+
# this class, sorted by type.
|
267
|
+
# @param is_instance_method [Boolean] Indicates if these methods are the instance or singleton methods for
|
268
|
+
# this module.
|
269
|
+
# @return [Integer] number of methods patched.
|
264
270
|
def patch_into_methods mod, methods, module_policy, is_instance_method
|
265
271
|
count = 0
|
266
272
|
methods.each do |method|
|
@@ -279,11 +285,10 @@ module Contrast
|
|
279
285
|
# it has to be reapplied.
|
280
286
|
# TODO: RUBY-620 should remove the need for this
|
281
287
|
#
|
282
|
-
# @param
|
283
|
-
# be accounted
|
288
|
+
# @param module_data [Contrast::Agent::ModuleData] the module, and its name, that's being patched into
|
284
289
|
# @return [Boolean] if an adjustment was made or not
|
285
|
-
def adjust_for_prepend
|
286
|
-
return false unless mod.cs__name == 'CGI::Util'
|
290
|
+
def adjust_for_prepend module_data
|
291
|
+
return false unless module_data.mod.cs__name == 'CGI::Util'
|
287
292
|
|
288
293
|
CGI.include(CGI::Util)
|
289
294
|
CGI.extend(CGI::Util)
|
@@ -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'
|
@@ -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/extension/module'
|
@@ -46,6 +46,11 @@ module Contrast
|
|
46
46
|
raise(ArgumentError,
|
47
47
|
"#{ id } did not have a proper applicator method: #{ applicator } does not respond to #{ applicator_method }. Unable to create.")
|
48
48
|
end
|
49
|
+
validate_properties
|
50
|
+
validate_rule
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate_properties
|
49
54
|
if (required_properties & optional_properties).any?
|
50
55
|
raise(ArgumentError, "#{ rule_id } had overlapping elements between required and optional properties. Unable to create.")
|
51
56
|
end
|
@@ -53,8 +58,6 @@ module Contrast
|
|
53
58
|
raise(ArgumentError, "#{ id } had an unexpected property. Unable to create.")
|
54
59
|
end
|
55
60
|
raise(ArgumentError, "#{ id } did not have a required property. Unable to create.") if (required_properties - properties.keys).any?
|
56
|
-
|
57
|
-
validate_rule
|
58
61
|
end
|
59
62
|
|
60
63
|
def validate_rule
|
@@ -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/protect/rule/cmd_injection'
|
@@ -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/protect/rule/deserialization'
|
@@ -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/protect/rule/no_sqli'
|
@@ -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/protect/rule/path_traversal'
|
@@ -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/protect/rule/sqli'
|
@@ -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/protect/rule/xxe'
|
@@ -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'
|
@@ -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/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
|
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'
|
@@ -36,9 +36,9 @@ module Contrast
|
|
36
36
|
|
37
37
|
attr_reader :mode
|
38
38
|
|
39
|
-
def initialize
|
39
|
+
def initialize
|
40
40
|
PROTECT.rules[name] = self
|
41
|
-
@mode = mode_from_settings
|
41
|
+
@mode = mode_from_settings
|
42
42
|
end
|
43
43
|
|
44
44
|
# Should return the name as it is known to Teamserver; defaults to class
|
@@ -46,27 +46,16 @@ module Contrast
|
|
46
46
|
cs__class.name
|
47
47
|
end
|
48
48
|
|
49
|
-
OFF = 'off'
|
50
|
-
|
51
49
|
def enabled?
|
52
50
|
# 1. it is not enabled because protect is not enabled
|
53
51
|
return false unless AGENT.enabled?
|
54
52
|
return false unless PROTECT.enabled?
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
# 2. it is not enabled because it is in the list of disabled protect rules
|
59
|
-
disabled_rules = rule_configs.disabled_rules
|
60
|
-
return false if disabled_rules&.include?(name)
|
61
|
-
|
62
|
-
# 3. it is not enabled because it has been turned "off" explicitly
|
63
|
-
rule_config = rule_configs.send(name)
|
64
|
-
|
65
|
-
return rule_config.mode != OFF unless rule_config.mode.nil?
|
66
|
-
end
|
54
|
+
# 2. it is not enabled because it is in the list of disabled protect rules
|
55
|
+
return false if PROTECT.rule_config&.disabled_rules&.include?(name)
|
67
56
|
|
68
|
-
#
|
69
|
-
@mode !=
|
57
|
+
# 3. it is enabled so long as its mode is not NO_ACTION
|
58
|
+
@mode != Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
|
70
59
|
end
|
71
60
|
|
72
61
|
def excluded? exclusions
|