contrast-agent 3.10.0 → 3.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.flayignore +1 -0
- data/.simplecov +5 -2
- data/ext/build_funchook.rb +12 -7
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +12 -14
- data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
- data/ext/cs__assess_active_record_named/extconf.rb +3 -0
- data/ext/cs__assess_array/cs__assess_array.c +5 -6
- data/ext/cs__assess_array/cs__assess_array.h +1 -0
- data/ext/cs__assess_array/extconf.rb +3 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +13 -11
- data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
- data/ext/cs__assess_basic_object/extconf.rb +3 -0
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -3
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +3 -3
- data/ext/cs__assess_fiber_track/extconf.rb +3 -0
- data/ext/cs__assess_hash/cs__assess_hash.c +40 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +4 -6
- data/ext/cs__assess_hash/extconf.rb +3 -0
- data/ext/cs__assess_kernel/cs__assess_kernel.c +11 -9
- data/ext/cs__assess_kernel/cs__assess_kernel.h +1 -0
- data/ext/cs__assess_kernel/extconf.rb +3 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +3 -6
- data/ext/cs__assess_marshal_module/extconf.rb +3 -0
- data/ext/cs__assess_module/cs__assess_module.c +16 -14
- data/ext/cs__assess_module/cs__assess_module.h +3 -0
- data/ext/cs__assess_module/extconf.rb +3 -0
- data/ext/cs__assess_regexp/cs__assess_regexp.c +13 -9
- data/ext/cs__assess_regexp/cs__assess_regexp.h +1 -0
- data/ext/cs__assess_regexp/extconf.rb +3 -0
- data/ext/cs__assess_string/cs__assess_string.c +5 -8
- data/ext/cs__assess_string/cs__assess_string.h +2 -1
- data/ext/cs__assess_string/extconf.rb +3 -0
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +2 -2
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +3 -3
- data/ext/cs__assess_string_interpolation26/extconf.rb +3 -0
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +1 -1
- data/ext/cs__assess_yield_track/extconf.rb +3 -0
- data/ext/cs__common/cs__common.c +80 -1
- data/ext/cs__common/cs__common.h +34 -0
- data/ext/cs__common/extconf.rb +9 -8
- data/ext/cs__contrast_patch/cs__contrast_patch.h +1 -6
- data/ext/cs__contrast_patch/extconf.rb +3 -0
- data/ext/cs__protect_kernel/cs__protect_kernel.c +23 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
- data/ext/cs__protect_kernel/extconf.rb +3 -0
- data/ext/extconf_common.rb +10 -8
- data/funchook/autom4te.cache/requests +45 -45
- data/funchook/config.log +4 -4
- data/lib/contrast.rb +1 -1
- data/lib/contrast/agent.rb +32 -29
- data/lib/contrast/agent/assess.rb +1 -11
- data/lib/contrast/agent/assess/adjusted_span.rb +3 -1
- data/lib/contrast/agent/assess/contrast_event.rb +16 -62
- data/lib/contrast/agent/assess/events/event_factory.rb +25 -0
- data/lib/contrast/agent/assess/events/source_event.rb +83 -0
- data/lib/contrast/agent/assess/insulator.rb +0 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +1 -8
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -2
- data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +68 -33
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +80 -0
- data/lib/contrast/agent/assess/policy/propagator/select.rb +35 -22
- data/lib/contrast/agent/assess/policy/propagator/split.rb +26 -6
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -0
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +37 -26
- data/lib/contrast/agent/assess/policy/source_method.rb +20 -20
- data/lib/contrast/agent/assess/policy/source_node.rb +0 -15
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
- data/lib/contrast/agent/assess/policy/trigger_method.rb +30 -45
- data/lib/contrast/agent/assess/policy/trigger_node.rb +7 -7
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -31
- data/lib/contrast/agent/assess/properties.rb +5 -3
- data/lib/contrast/agent/assess/rule/base.rb +1 -20
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +23 -6
- data/lib/contrast/agent/assess/rule/redos.rb +4 -5
- data/lib/contrast/agent/assess/tag.rb +24 -14
- data/lib/contrast/agent/at_exit_hook.rb +16 -13
- data/lib/contrast/agent/class_reopener.rb +23 -8
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +3 -4
- data/lib/contrast/agent/exclusion_matcher.rb +7 -48
- data/lib/contrast/agent/inventory/policy/datastores.rb +54 -0
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +101 -260
- data/lib/contrast/agent/module_data.rb +2 -1
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +13 -3
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +59 -47
- data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/module_policy.rb +0 -25
- data/lib/contrast/agent/patching/policy/patch.rb +97 -23
- data/lib/contrast/agent/patching/policy/patcher.rb +28 -30
- data/lib/contrast/agent/patching/policy/policy.rb +7 -7
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -11
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -5
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
- data/lib/contrast/agent/protect/policy/policy.rb +6 -6
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
- data/lib/contrast/agent/protect/rule.rb +0 -5
- data/lib/contrast/agent/protect/rule/base.rb +19 -37
- data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -15
- data/lib/contrast/agent/protect/rule/default_scanner.rb +0 -13
- data/lib/contrast/agent/protect/rule/deserialization.rb +2 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -2
- data/lib/contrast/agent/protect/rule/no_sqli.rb +4 -4
- data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
- data/lib/contrast/agent/protect/rule/sqli.rb +5 -4
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -0
- data/lib/contrast/agent/protect/rule/xss.rb +2 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +10 -4
- data/lib/contrast/agent/railtie.rb +3 -8
- data/lib/contrast/agent/reaction_processor.rb +5 -5
- data/lib/contrast/agent/request.rb +11 -18
- data/lib/contrast/agent/request_context.rb +16 -19
- data/lib/contrast/agent/request_handler.rb +35 -0
- data/lib/contrast/agent/response.rb +39 -86
- data/lib/contrast/agent/rewriter.rb +22 -10
- data/lib/contrast/agent/rule_set.rb +49 -0
- data/lib/contrast/agent/scope.rb +0 -6
- data/lib/contrast/agent/service_heartbeat.rb +3 -4
- data/lib/contrast/agent/socket_client.rb +25 -19
- data/lib/contrast/agent/static_analysis.rb +41 -0
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/tracepoint_hook.rb +1 -5
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +1 -1
- data/lib/contrast/api/decorators.rb +14 -0
- data/lib/contrast/api/decorators/application_settings.rb +37 -0
- data/lib/contrast/api/decorators/application_update.rb +66 -0
- data/lib/contrast/api/decorators/input_analysis.rb +17 -0
- data/lib/contrast/api/decorators/server_features.rb +24 -0
- data/lib/contrast/api/speedracer.rb +28 -24
- data/lib/contrast/api/tcp_socket.rb +0 -2
- data/lib/contrast/components/agent.rb +34 -24
- data/lib/contrast/components/app_context.rb +45 -38
- data/lib/contrast/components/assess.rb +25 -15
- data/lib/contrast/components/config.rb +7 -5
- data/lib/contrast/components/contrast_service.rb +23 -71
- data/lib/contrast/components/heap_dump.rb +12 -8
- data/lib/contrast/components/interface.rb +15 -22
- data/lib/contrast/components/inventory.rb +5 -1
- data/lib/contrast/components/logger.rb +3 -68
- data/lib/contrast/components/protect.rb +40 -4
- data/lib/contrast/components/sampling.rb +22 -11
- data/lib/contrast/components/scope.rb +2 -52
- data/lib/contrast/components/settings.rb +42 -23
- data/lib/contrast/config/base_configuration.rb +1 -0
- data/lib/contrast/config/default_value.rb +1 -0
- data/lib/contrast/config/protect_rule_configuration.rb +0 -14
- data/lib/contrast/config/protect_rules_configuration.rb +0 -1
- data/lib/contrast/configuration.rb +2 -2
- data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -15
- data/lib/contrast/extension/assess/array.rb +77 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +29 -24
- data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -8
- data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +7 -9
- data/lib/contrast/extension/assess/fiber.rb +113 -0
- data/lib/contrast/extension/assess/hash.rb +39 -0
- data/lib/contrast/extension/assess/kernel.rb +110 -0
- data/lib/contrast/extension/assess/regexp.rb +84 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +18 -10
- data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -2
- data/lib/contrast/extension/kernel.rb +54 -0
- data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
- data/lib/contrast/extension/protect/kernel.rb +44 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
- data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
- data/lib/contrast/framework/base_support.rb +32 -0
- data/lib/contrast/framework/manager.rb +59 -8
- data/lib/contrast/framework/platform_version.rb +1 -0
- data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
- data/lib/contrast/framework/rack/patch/support.rb +24 -0
- data/lib/contrast/framework/rack/support.rb +22 -0
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +43 -0
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +103 -0
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
- data/lib/contrast/framework/rails/patch/support.rb +67 -0
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
- data/lib/contrast/framework/rails/support.rb +115 -0
- data/lib/contrast/framework/sinatra/application_helper.rb +51 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
- data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
- data/lib/contrast/framework/sinatra/support.rb +109 -0
- data/lib/contrast/framework/view_technologies_descriptor.rb +1 -0
- data/lib/contrast/logger/application.rb +80 -0
- data/lib/contrast/logger/log.rb +143 -0
- data/lib/contrast/logger/time.rb +50 -0
- data/lib/contrast/tasks/config.rb +54 -0
- data/lib/contrast/tasks/service.rb +3 -13
- data/lib/contrast/utils/assess/sampling_util.rb +4 -9
- data/lib/contrast/utils/assess/tracking_util.rb +7 -1
- data/lib/contrast/utils/boolean_util.rb +2 -2
- data/lib/contrast/utils/cache.rb +0 -11
- data/lib/contrast/utils/class_util.rb +21 -2
- data/lib/contrast/utils/gemfile_reader.rb +7 -5
- data/lib/contrast/utils/hash_digest.rb +2 -11
- data/lib/contrast/utils/heap_dump_util.rb +12 -11
- data/lib/contrast/utils/invalid_configuration_util.rb +4 -4
- data/lib/contrast/utils/inventory_util.rb +2 -2
- data/lib/contrast/utils/io_util.rb +1 -11
- data/lib/contrast/utils/job_servers_running.rb +6 -4
- data/lib/contrast/utils/object_share.rb +1 -28
- data/lib/contrast/utils/os.rb +1 -25
- data/lib/contrast/utils/service_response_util.rb +36 -60
- data/lib/contrast/utils/service_sender_util.rb +84 -23
- data/lib/contrast/utils/sinatra_helper.rb +0 -6
- data/lib/contrast/utils/stack_trace_utils.rb +86 -182
- data/lib/contrast/utils/string_utils.rb +18 -2
- data/lib/contrast/utils/tag_util.rb +11 -1
- data/lib/contrast/utils/thread_tracker.rb +2 -2
- data/lib/contrast/utils/timer.rb +0 -40
- data/resources/assess/policy.json +42 -71
- data/resources/inventory/policy.json +2 -2
- data/resources/protect/policy.json +15 -15
- data/ruby-agent.gemspec +11 -4
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +122 -111
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +0 -63
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +0 -29
- data/ext/cs__assess_regexp_track/extconf.rb +0 -2
- data/lib/contrast/agent/assess/frozen_properties.rb +0 -41
- data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
- data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
- data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -73
- data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -132
- data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
- data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
- data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
- data/lib/contrast/agent/feature_state.rb +0 -376
- data/lib/contrast/agent/logger_manager.rb +0 -116
- data/lib/contrast/agent/protect/rule/csrf.rb +0 -118
- data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -103
- data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
- data/lib/contrast/agent/settings_state.rb +0 -152
- data/lib/contrast/delegators.rb +0 -9
- data/lib/contrast/delegators/application_update.rb +0 -32
- data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
- data/lib/contrast/extensions/framework/rack/request.rb +0 -24
- data/lib/contrast/extensions/framework/rack/response.rb +0 -23
- data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
- data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
- data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -53
- data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
- data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
- data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
- data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
- data/lib/contrast/extensions/ruby_core/assess/fiber.rb +0 -124
- data/lib/contrast/extensions/ruby_core/assess/hash.rb +0 -22
- data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -95
- data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
- data/lib/contrast/extensions/ruby_core/assess/regexp.rb +0 -206
- data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -73
- data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
- data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -52
- data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
- data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -72
- data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -60
- data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -83
- data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -123
- data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -65
- data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -143
- data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
- data/lib/contrast/framework/rails_support.rb +0 -88
- data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
- data/lib/contrast/framework/sinatra_support.rb +0 -94
- data/lib/contrast/utils/comment_range.rb +0 -19
- data/lib/contrast/utils/data_store_util.rb +0 -23
- data/lib/contrast/utils/environment_util.rb +0 -81
- data/lib/contrast/utils/performs_logging.rb +0 -152
- data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
- data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
- data/lib/contrast/utils/random_util.rb +0 -22
- data/resources/csrf/inject.js +0 -44
- data/resources/factory-bot-spec/spec_helper.rb +0 -30
- data/resources/rubocops/kernel/catch_cop.rb +0 -37
- data/resources/rubocops/kernel/require_cop.rb +0 -37
- data/resources/rubocops/kernel/require_relative_cop.rb +0 -33
- data/resources/rubocops/module/autoload_cop.rb +0 -37
- data/resources/rubocops/module/const_defined_cop.rb +0 -37
- data/resources/rubocops/module/const_get_cop.rb +0 -37
- data/resources/rubocops/module/const_set_cop.rb +0 -37
- data/resources/rubocops/module/constants_cop.rb +0 -37
- data/resources/rubocops/module/name_cop.rb +0 -37
- data/resources/rubocops/object/class_cop.rb +0 -37
- data/resources/rubocops/object/freeze_cop.rb +0 -37
- data/resources/rubocops/object/frozen_cop.rb +0 -37
- data/resources/rubocops/object/is_a_cop.rb +0 -37
- data/resources/rubocops/object/method_cop.rb +0 -37
- data/resources/rubocops/object/respond_to_cop.rb +0 -37
- data/resources/rubocops/object/singleton_class_cop.rb +0 -37
- data/resources/rubocops/regexp/spelling_cop.rb +0 -44
- data/resources/rubocops/thread/new_cop.rb +0 -39
- data/resources/ruby-spec/ancestors_spec.rb +0 -70
- data/resources/ruby-spec/modulo_spec.rb +0 -831
- data/resources/ruby-spec/parameters_spec.rb +0 -261
- data/resources/ruby-spec/ruby_spec_spec_helper.rb +0 -35
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/agent/protect/rule/sqli'
|
5
|
+
cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Agent
|
9
|
+
module Protect
|
10
|
+
module Policy
|
11
|
+
# This Module is how we apply the SQL Injection rule. It is called from
|
12
|
+
# our patches of the targeted methods in which the execution of String
|
13
|
+
# based SQL queries occur. It is responsible for deciding if the infilter
|
14
|
+
# methods of the rule should be invoked.
|
15
|
+
class AppliesSqliRule
|
16
|
+
extend Contrast::Agent::Protect::Policy::RuleApplicator
|
17
|
+
|
18
|
+
DATABASE_MYSQL = 'MySQL'
|
19
|
+
DATABASE_SQLITE = 'SQLite3'
|
20
|
+
DATABASE_PG = 'PostgreSQL'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def invoke _method, _exception, properties, _object, args
|
24
|
+
database = properties['database']
|
25
|
+
return unless database
|
26
|
+
|
27
|
+
index = properties[Contrast::Utils::ObjectShare::INDEX]
|
28
|
+
return unless valid_input?(index, args)
|
29
|
+
return if skip_analysis?
|
30
|
+
|
31
|
+
sql = args[index]
|
32
|
+
rule.infilter(Contrast::Agent::REQUEST_TRACKER.current, database, sql)
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def name
|
38
|
+
Contrast::Agent::Protect::Rule::Sqli::NAME
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def valid_input? index, args
|
44
|
+
return false unless args && args.length > index
|
45
|
+
|
46
|
+
sql = args[index]
|
47
|
+
sql && !sql.empty?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/agent/protect/rule/xxe'
|
5
|
+
cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
|
6
|
+
cs__scoped_require 'contrast/utils/object_share'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Agent
|
10
|
+
module Protect
|
11
|
+
module Policy
|
12
|
+
# This Module is how we apply the XXE rule. It is called from our patches
|
13
|
+
# of the targeted methods in which XML parsing and entity resolution
|
14
|
+
# occurs. It is responsible for deciding if the infilter methods of the
|
15
|
+
# rule should be invoked.
|
16
|
+
module AppliesXxeRule
|
17
|
+
extend Contrast::Agent::Protect::Policy::RuleApplicator
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def apply_rule method, _exception, _properties, object, args
|
21
|
+
xml = args[0]
|
22
|
+
xxe_check(method, xml, object)
|
23
|
+
end
|
24
|
+
|
25
|
+
# IO is tricky. If we can't rewind it, we can't fix it back to the
|
26
|
+
# original state. To be safe, we'll skip non-rewindable IO objects.
|
27
|
+
def apply_rule__io method, _exception, _properties, object, args
|
28
|
+
need_rewind = false
|
29
|
+
potential_xml = args[0]
|
30
|
+
return unless potential_xml&.respond_to?(:rewind)
|
31
|
+
|
32
|
+
xml = potential_xml.read
|
33
|
+
need_rewind = true
|
34
|
+
xxe_check(method, xml, object)
|
35
|
+
ensure
|
36
|
+
potential_xml.rewind if need_rewind
|
37
|
+
end
|
38
|
+
|
39
|
+
# Oga's Lexer is a special case b/c the information we need is on the
|
40
|
+
# object itself -- specifically in the @data instance variable
|
41
|
+
def apply_rule__lexer method, _exception, _properties, object, _args
|
42
|
+
return unless valid_data_input?(object)
|
43
|
+
|
44
|
+
data = object.instance_variable_get(DATA_KEY)
|
45
|
+
xxe_check(method, data, object)
|
46
|
+
ensure
|
47
|
+
data.rewind if data&.cs__respond_to?(:rewind)
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def name
|
53
|
+
Contrast::Agent::Protect::Rule::Xxe::NAME
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
DATA_KEY = '@data'.to_sym
|
59
|
+
def valid_data_input? object
|
60
|
+
object.instance_variable_defined?(DATA_KEY) &&
|
61
|
+
object.instance_variable_get(DATA_KEY)
|
62
|
+
end
|
63
|
+
|
64
|
+
NOKOGIRI_MARKER = 'Nokogiri::'
|
65
|
+
PARSER_NOKOGIRI = 'Nokogiri'
|
66
|
+
OX_MARKER = 'Ox' # breaks marker pattern b/c Ox is entire classname
|
67
|
+
PARSER_OX = 'Ox'
|
68
|
+
OGA_MARKER = 'Oga::'
|
69
|
+
PARSER_OGA = 'Oga'
|
70
|
+
# Given an object, determine the XML parser type that it represents.
|
71
|
+
#
|
72
|
+
# @param object[Object] the parsing instance or Module
|
73
|
+
# @return [String] the name of the parser
|
74
|
+
def determine_parser object
|
75
|
+
clazz = object.is_a?(Module) ? object : object.cs__class
|
76
|
+
name = clazz.cs__name
|
77
|
+
|
78
|
+
if name.start_with?(NOKOGIRI_MARKER)
|
79
|
+
PARSER_NOKOGIRI
|
80
|
+
elsif name.start_with?(OX_MARKER)
|
81
|
+
PARSER_OX
|
82
|
+
elsif name.start_with?(OGA_MARKER)
|
83
|
+
PARSER_OGA
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Given an xml, convert it to a String and pass it to the rule for
|
88
|
+
# analysis.
|
89
|
+
#
|
90
|
+
# @param method [Symbol] the name of the method doing this work.
|
91
|
+
# @param xml [Object] the container of the XML to be checked.
|
92
|
+
# @param potential_parser [Object] the entity that may be an XML
|
93
|
+
# parser.
|
94
|
+
# @raise [Contrast::SecurityException] Security exception if an XXE
|
95
|
+
# attack is found and the rule is in block mode.
|
96
|
+
def xxe_check method, xml, potential_parser
|
97
|
+
return if skip_analysis?
|
98
|
+
return unless xml
|
99
|
+
|
100
|
+
parser = determine_parser(potential_parser)
|
101
|
+
return unless parser
|
102
|
+
|
103
|
+
if xml.cs__is_a?(String)
|
104
|
+
rule.infilter(Contrast::Agent::REQUEST_TRACKER.current, parser, xml)
|
105
|
+
elsif xml.cs__respond_to?(:each_line)
|
106
|
+
xml.each_line do |line|
|
107
|
+
rule.infilter(Contrast::Agent::REQUEST_TRACKER.current, parser, line)
|
108
|
+
end
|
109
|
+
elsif xml.cs__respond_to?(:each)
|
110
|
+
xml.each do |chunk|
|
111
|
+
rule.infilter(Contrast::Agent::REQUEST_TRACKER.current, parser, chunk)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
rescue Contrast::SecurityException => e
|
115
|
+
raise e
|
116
|
+
rescue StandardError => e
|
117
|
+
parser ||= Contrast::Utils::ObjectShare::UNKNOWN
|
118
|
+
logger.error(
|
119
|
+
'Error applying xxe',
|
120
|
+
e,
|
121
|
+
module: potential_parser.cs__class.cs__name,
|
122
|
+
method: method, parser: parser)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -4,12 +4,12 @@
|
|
4
4
|
cs__scoped_require 'contrast/agent/patching/policy/policy'
|
5
5
|
|
6
6
|
# classes required by patches in the policy
|
7
|
-
cs__scoped_require 'contrast/
|
8
|
-
cs__scoped_require 'contrast/
|
9
|
-
cs__scoped_require 'contrast/
|
10
|
-
cs__scoped_require 'contrast/
|
11
|
-
cs__scoped_require 'contrast/
|
12
|
-
cs__scoped_require 'contrast/
|
7
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_command_injection_rule'
|
8
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_deserialization_rule'
|
9
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_no_sqli_rule'
|
10
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_path_traversal_rule'
|
11
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_sqli_rule'
|
12
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_xxe_rule'
|
13
13
|
cs__scoped_require 'contrast/agent/protect/policy/trigger_node'
|
14
14
|
|
15
15
|
module Contrast
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/components/interface'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Protect
|
9
|
+
module Policy
|
10
|
+
# This Module is the base of our Protect Applicators. It lays out the
|
11
|
+
# form of the Applicator, which will override specific implementations
|
12
|
+
# in order to properly invoke its Rule.
|
13
|
+
module RuleApplicator
|
14
|
+
include Contrast::Components::Interface
|
15
|
+
|
16
|
+
access_component :analysis, :logging
|
17
|
+
|
18
|
+
def apply_rule method, exception, properties, object, args
|
19
|
+
invoke(method, exception, properties, object, args)
|
20
|
+
rescue Contrast::SecurityException => e
|
21
|
+
raise e
|
22
|
+
rescue StandardError => e
|
23
|
+
logger.error('Error applying protect rule', e, module: object.cs__class.cs__name, method: method, rule: name)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def invoke _method, _exception, _properties, _object, _args
|
29
|
+
raise NotImplementedError, 'This is abstract, override it.'
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
raise NotImplementedError, 'This is abstract, override it.'
|
34
|
+
end
|
35
|
+
|
36
|
+
def rule
|
37
|
+
PROTECT.rule name
|
38
|
+
end
|
39
|
+
|
40
|
+
def skip_analysis?
|
41
|
+
context = Contrast::Agent::REQUEST_TRACKER.current
|
42
|
+
return true unless context&.app_loaded?
|
43
|
+
return true unless rule&.enabled?
|
44
|
+
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -35,11 +35,6 @@ cs__scoped_require 'contrast/agent/protect/rule/path_traversal'
|
|
35
35
|
# The classes required for Command Injection
|
36
36
|
cs__scoped_require 'contrast/agent/protect/rule/cmd_injection'
|
37
37
|
|
38
|
-
# The classes required for CSRF
|
39
|
-
cs__scoped_require 'contrast/agent/protect/rule/csrf'
|
40
|
-
cs__scoped_require 'contrast/agent/protect/rule/csrf/csrf_evaluator'
|
41
|
-
cs__scoped_require 'contrast/agent/protect/rule/csrf/csrf_token_injector'
|
42
|
-
|
43
38
|
# The classes required for XXE
|
44
39
|
cs__scoped_require 'contrast/agent/protect/rule/xxe'
|
45
40
|
cs__scoped_require 'contrast/agent/protect/rule/xxe/entity_wrapper'
|
@@ -14,21 +14,20 @@ module Contrast
|
|
14
14
|
class Base
|
15
15
|
include Contrast::Components::Interface
|
16
16
|
|
17
|
-
access_component :
|
17
|
+
access_component :agent, :analysis, :logging, :scope, :settings
|
18
18
|
|
19
19
|
UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
|
20
20
|
user_input.input_type = :UNKNOWN
|
21
21
|
end.cs__freeze
|
22
22
|
|
23
23
|
BLOCKING_MODES = Set.new(%i[BLOCK BLOCK_AT_PERIMETER]).cs__freeze
|
24
|
-
PREFILTER_MODES = Set.new(%i[BLOCK_AT_PERIMETER]).cs__freeze
|
25
24
|
POSTFILTER_MODES = Set.new(%i[BLOCK PERMIT MONITOR]).cs__freeze
|
26
25
|
STACK_COLLECTION_RESULTS = Set.new(%i[BLOCKED MONITORED]).cs__freeze
|
27
26
|
|
28
27
|
attr_reader :mode
|
29
28
|
|
30
29
|
def initialize default_mode = :NO_ACTION
|
31
|
-
|
30
|
+
PROTECT.rules[name] = self
|
32
31
|
@mode = mode_from_settings || default_mode
|
33
32
|
end
|
34
33
|
|
@@ -41,9 +40,10 @@ module Contrast
|
|
41
40
|
|
42
41
|
def enabled?
|
43
42
|
# 1. it is not enabled because protect is not enabled
|
43
|
+
return false unless AGENT.enabled?
|
44
44
|
return false unless PROTECT.enabled?
|
45
45
|
|
46
|
-
rule_configs =
|
46
|
+
rule_configs = PROTECT.rule_config
|
47
47
|
unless rule_configs.nil?
|
48
48
|
# 2. it is not enabled because it is in the list of disabled protect rules
|
49
49
|
disabled_rules = rule_configs.disabled_rules
|
@@ -59,7 +59,6 @@ module Contrast
|
|
59
59
|
@mode != :NO_ACTION
|
60
60
|
end
|
61
61
|
|
62
|
-
# this rule is excluded if any of the given exclusions have a protection rule that matches this rule name
|
63
62
|
def excluded? exclusions
|
64
63
|
Array(exclusions).any? do |ex|
|
65
64
|
ex.protection_rule?(name)
|
@@ -140,8 +139,8 @@ module Contrast
|
|
140
139
|
end
|
141
140
|
|
142
141
|
def mode_from_settings
|
143
|
-
|
144
|
-
logger.
|
142
|
+
PROTECT.rule_mode(name).tap do |mode|
|
143
|
+
logger.trace('Retrieving rule mode', rule: name, mode: mode)
|
145
144
|
end
|
146
145
|
end
|
147
146
|
|
@@ -155,7 +154,7 @@ module Contrast
|
|
155
154
|
# @return [Boolean] if an exclusion was applicable to this request
|
156
155
|
# for this rule
|
157
156
|
def protect_excluded_by_code?
|
158
|
-
exclusions =
|
157
|
+
exclusions = SETTINGS.code_exclusions
|
159
158
|
return false unless exclusions
|
160
159
|
|
161
160
|
for_rule = exclusions.select { |ex| ex.protection_rule?(name) }
|
@@ -215,7 +214,7 @@ module Contrast
|
|
215
214
|
return unless sample
|
216
215
|
return unless STACK_COLLECTION_RESULTS.include?(result&.response)
|
217
216
|
|
218
|
-
stack = Contrast::Utils::StackTraceUtils.
|
217
|
+
stack = Contrast::Utils::StackTraceUtils.build_protect_stack_array
|
219
218
|
return unless stack
|
220
219
|
|
221
220
|
sample.stack_trace_elements += stack
|
@@ -259,39 +258,22 @@ module Contrast
|
|
259
258
|
end
|
260
259
|
|
261
260
|
def log_rule_matched _context, ia_result, response, _matched_string = nil
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
"An effective attack was detected against #{ name }."
|
269
|
-
end
|
270
|
-
|
271
|
-
logger.debug([response, message].join)
|
261
|
+
logger.debug('A successful attack was detected',
|
262
|
+
rule: name,
|
263
|
+
type: ia_result&.input_type,
|
264
|
+
name: ia_result&.key,
|
265
|
+
input: ia_result&.value,
|
266
|
+
result: response)
|
272
267
|
end
|
273
268
|
|
274
269
|
private
|
275
270
|
|
276
271
|
def log_rule_probed _context, ia_result
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
logger.debug(message)
|
284
|
-
end
|
285
|
-
|
286
|
-
def log_msg ia_result, matched
|
287
|
-
key = ia_result.key ? ia_result.key.to_s + ' ' : ''
|
288
|
-
val = ia_result.value.to_s
|
289
|
-
typ = ia_result.input_type.to_s
|
290
|
-
if matched
|
291
|
-
"The #{ typ } #{ key } had a value that successfully exploited #{ name } - #{ val }."
|
292
|
-
else
|
293
|
-
"The #{ typ } #{ key } had a value that matched a signature for, but did not successfully exploit, #{ name } - #{ val }."
|
294
|
-
end
|
272
|
+
logger.debug('An unsuccessful attack was detected',
|
273
|
+
rule: name,
|
274
|
+
type: ia_result&.input_type,
|
275
|
+
name: ia_result&.key,
|
276
|
+
input: ia_result&.value)
|
295
277
|
end
|
296
278
|
end
|
297
279
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
cs__scoped_require 'contrast/agent/protect/rule/base'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Agent
|
6
8
|
module Protect
|
@@ -56,7 +58,7 @@ module Contrast
|
|
56
58
|
|
57
59
|
# Allows for the InputAnalysis from service to be extracted early
|
58
60
|
def find_attacker_with_results context, potential_attack_string, ia_results, **kwargs
|
59
|
-
logger.
|
61
|
+
logger.trace('Checking vectors for attacks', rule: name, input: potential_attack_string)
|
60
62
|
|
61
63
|
result = nil
|
62
64
|
ia_results.each do |ia_result|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
cs__scoped_require 'contrast/agent/at_exit_hook'
|
5
|
+
cs__scoped_require 'contrast/agent/protect/rule/base_service'
|
4
6
|
cs__scoped_require 'contrast/utils/stack_trace_utils'
|
5
7
|
cs__scoped_require 'contrast/utils/object_share'
|
6
8
|
cs__scoped_require 'contrast/components/interface'
|
@@ -12,7 +14,7 @@ module Contrast
|
|
12
14
|
# The Ruby implementation of the Protect Command Injection rule.
|
13
15
|
class CmdInjection < Contrast::Agent::Protect::Rule::BaseService
|
14
16
|
include Contrast::Components::Interface
|
15
|
-
access_component :
|
17
|
+
access_component :app_context, :logging
|
16
18
|
|
17
19
|
NAME = 'cmd-injection'
|
18
20
|
CHAINED_COMMAND_CHARS = /[;&|<>]/.cs__freeze
|
@@ -27,8 +29,8 @@ module Contrast
|
|
27
29
|
ia_results = gather_ia_results(context)
|
28
30
|
return nil if ia_results.empty?
|
29
31
|
|
30
|
-
if
|
31
|
-
logger.
|
32
|
+
if APP_CONTEXT.in_new_process?
|
33
|
+
logger.trace('Running cmd-injection infilter within new process - creating new context')
|
32
34
|
context = Contrast::Agent::RequestContext.new(context.request.rack_request)
|
33
35
|
Contrast::Agent::REQUEST_TRACKER.update_current_context(context)
|
34
36
|
end
|
@@ -38,18 +40,16 @@ module Contrast
|
|
38
40
|
return nil unless result
|
39
41
|
|
40
42
|
append_to_activity(context, result)
|
41
|
-
if %I[exec `].include?(method)
|
42
|
-
# TODO: RUBY-737
|
43
|
-
# Kernel#exec replaces the current process and does not go through at_exit hooks
|
44
|
-
# Kernel#` runs as a subshell - messages appended here do not seem to be present in the original process?
|
45
|
-
CONTRAST_SERVICE.send_message(context.activity)
|
46
|
-
end
|
47
|
-
|
48
43
|
return unless blocked?
|
49
44
|
|
50
45
|
raise Contrast::SecurityException.new(
|
51
46
|
self,
|
52
47
|
"Command Injection rule triggered. Call to #{ classname }.#{ method } blocked.")
|
48
|
+
ensure
|
49
|
+
# Kernel#exec replaces the current process and does not go through
|
50
|
+
# at_exit hooks. Kernel#` runs as a subshell - messages appended
|
51
|
+
# here do not seem to be present in the original process.
|
52
|
+
Contrast::Agent::AtExitHook.on_exit if %i[exec `].include?(method.to_sym)
|
53
53
|
end
|
54
54
|
|
55
55
|
def build_attack_with_match context, input_analysis_result, result, candidate_string, **kwargs
|
@@ -66,7 +66,7 @@ module Contrast
|
|
66
66
|
# Because results are not necessarily on the context across
|
67
67
|
# processes; extract early and pass into the method
|
68
68
|
def find_attacker_with_results context, potential_attack_string, ia_results, **kwargs
|
69
|
-
logger.
|
69
|
+
logger.trace('Checking vectors for attacks', rule: name, input: potential_attack_string)
|
70
70
|
result = super(context, potential_attack_string, ia_results, **kwargs)
|
71
71
|
if result.nil? && potential_attack_string
|
72
72
|
result = find_probable_attacker(
|
@@ -128,9 +128,6 @@ module Contrast
|
|
128
128
|
result,
|
129
129
|
potential_attack_string,
|
130
130
|
**kwargs)
|
131
|
-
return nil if result.nil?
|
132
|
-
|
133
|
-
log_rule_matched(context, most_likely, mode, potential_attack_string)
|
134
131
|
result
|
135
132
|
end
|
136
133
|
|
@@ -147,7 +144,7 @@ module Contrast
|
|
147
144
|
# @return [Boolean] if the agent should report all command
|
148
145
|
# executions.
|
149
146
|
def report_any_command_execution?
|
150
|
-
|
147
|
+
PROTECT.report_any_command_execution?
|
151
148
|
end
|
152
149
|
end
|
153
150
|
end
|