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
@@ -35,7 +35,6 @@ class Contrast::Agent::Protect::Rule::DefaultScanner # rubocop:disable Style/Cla
|
|
35
35
|
@_token_boundaries ||= scan_token_boundaries(query)
|
36
36
|
end
|
37
37
|
|
38
|
-
CANARY = "select * from tbl where bar='bar';#' and pwd='sec3r3t'; # CANARY"
|
39
38
|
def scan_token_boundaries query
|
40
39
|
boundaries = []
|
41
40
|
return boundaries unless query && !query.empty?
|
@@ -268,24 +267,12 @@ class Contrast::Agent::Protect::Rule::DefaultScanner # rubocop:disable Style/Cla
|
|
268
267
|
true
|
269
268
|
end
|
270
269
|
|
271
|
-
# Does this language let the user redefine the escape character
|
272
|
-
# We assume no by default
|
273
|
-
def redefines_escape_char?
|
274
|
-
false
|
275
|
-
end
|
276
|
-
|
277
270
|
# Is the character provided an escape character?
|
278
271
|
# By default, we'll assume
|
279
272
|
def escape_char? char
|
280
273
|
char == Contrast::Utils::ObjectShare::BACK_SLASH
|
281
274
|
end
|
282
275
|
|
283
|
-
# Does this language support string escape sequences?
|
284
|
-
# We assume no by default
|
285
|
-
def support_string_escape_sequence?
|
286
|
-
false
|
287
|
-
end
|
288
|
-
|
289
276
|
# Is this the start of a string escape sequence?
|
290
277
|
# Since escape sequences aren't supported, the answer is always false
|
291
278
|
def escape_sequence_start? _char
|
@@ -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_service'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Agent
|
6
8
|
module Protect
|
@@ -16,8 +18,6 @@ module Contrast
|
|
16
18
|
|
17
19
|
def postfilter context
|
18
20
|
return unless enabled? && POSTFILTER_MODES.include?(mode)
|
19
|
-
|
20
|
-
logger.debug("#{ name } postfilter...")
|
21
21
|
return if normal_request?(context)
|
22
22
|
|
23
23
|
# The only way to be here in postfilter with a result is if the rule mode was MONITOR
|
@@ -1,9 +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
|
-
|
5
|
-
|
6
|
-
# https://www.owasp.org/index.php/Testing_for_NoSQL_injection
|
4
|
+
cs__scoped_require 'contrast/agent/protect/rule/base_service'
|
5
|
+
|
7
6
|
module Contrast
|
8
7
|
module Agent
|
9
8
|
module Protect
|
@@ -70,7 +69,8 @@ module Contrast
|
|
70
69
|
begin
|
71
70
|
potential_attack_string = JSON.generate(potential_attack_string).to_s
|
72
71
|
rescue JSON::GeneratorError
|
73
|
-
logger.
|
72
|
+
logger.trace('Error in JSON::generate', input: potential_attack_string)
|
73
|
+
nil
|
74
74
|
end
|
75
75
|
end
|
76
76
|
super(context, potential_attack_string, **kwargs)
|
@@ -1,8 +1,9 @@
|
|
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/
|
4
|
+
cs__scoped_require 'contrast/agent/protect/rule/base_service'
|
5
5
|
cs__scoped_require 'contrast/components/interface'
|
6
|
+
cs__scoped_require 'contrast/utils/stack_trace_utils'
|
6
7
|
|
7
8
|
module Contrast
|
8
9
|
module Agent
|
@@ -12,7 +13,7 @@ module Contrast
|
|
12
13
|
# Protect rule.
|
13
14
|
class PathTraversal < Contrast::Agent::Protect::Rule::BaseService
|
14
15
|
include Contrast::Components::Interface
|
15
|
-
access_component :
|
16
|
+
access_component :agent, :analysis
|
16
17
|
|
17
18
|
NAME = 'path-traversal'
|
18
19
|
SYSTEM_PATHS = %w[
|
@@ -28,8 +29,6 @@ module Contrast
|
|
28
29
|
/windows/repair/
|
29
30
|
].cs__freeze
|
30
31
|
|
31
|
-
KNOWN_SECURITY_BYPASS_MARKERS = ['::$DATA', '::$Index', '', '\x00'].cs__freeze
|
32
|
-
|
33
32
|
def name
|
34
33
|
NAME
|
35
34
|
end
|
@@ -70,11 +69,6 @@ module Contrast
|
|
70
69
|
private
|
71
70
|
|
72
71
|
# Build a subclass of the RaspRuleSample if the sample matches
|
73
|
-
# TODO: SPEED-? delete me when implemented in Speedracer.
|
74
|
-
# this implementation duplicates logic that is moving to Speedracer
|
75
|
-
# the reason it is still here is Speedracer doesn't yet have a method to correlate
|
76
|
-
# and (update) attack results that are generated because the evaluation results
|
77
|
-
# from REP, it can only forward the attack results are generated by the agent.
|
78
72
|
def build_rep_sample context, path
|
79
73
|
sample = build_base_sample(context, nil)
|
80
74
|
sample.path_traversal_semantic = Contrast::Api::Dtm::PathTraversalSemanticAnalysisDetails.new
|
@@ -104,7 +98,7 @@ module Contrast
|
|
104
98
|
end
|
105
99
|
|
106
100
|
def custom_code_access_sysfile_enabled?
|
107
|
-
|
101
|
+
PROTECT.report_custom_code_sysfile_access?
|
108
102
|
end
|
109
103
|
|
110
104
|
def custom_code_accessing_system_file? input
|
@@ -121,6 +115,8 @@ module Contrast
|
|
121
115
|
false
|
122
116
|
end
|
123
117
|
|
118
|
+
# TODO: RUBY-318
|
119
|
+
# KNOWN_SECURITY_BYPASS_MARKERS = ['::$DATA', '::$Index', '', '\x00'].cs__freeze
|
124
120
|
def contains_known_attack_signatures? input
|
125
121
|
utf8 = Contrast::Utils::StringUtils.force_utf8(input)
|
126
122
|
_ = CGI.unescape(utf8)
|
@@ -1,7 +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/
|
4
|
+
cs__scoped_require 'contrast/agent/protect/rule/base_service'
|
5
|
+
cs__scoped_require 'contrast/agent/protect/policy/applies_sqli_rule'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Agent
|
@@ -83,11 +84,11 @@ module Contrast
|
|
83
84
|
|
84
85
|
def select_scanner database
|
85
86
|
@sql_scanners ||= {
|
86
|
-
Contrast::
|
87
|
+
Contrast::Agent::Protect::Policy::AppliesSqliRule::DATABASE_MYSQL =>
|
87
88
|
Contrast::Agent::Protect::Rule::Sqli::MysqlSqlScanner.new,
|
88
|
-
Contrast::
|
89
|
+
Contrast::Agent::Protect::Policy::AppliesSqliRule::DATABASE_PG =>
|
89
90
|
Contrast::Agent::Protect::Rule::Sqli::PostgresSqlScanner.new,
|
90
|
-
Contrast::
|
91
|
+
Contrast::Agent::Protect::Policy::AppliesSqliRule::DATABASE_SQLITE =>
|
91
92
|
Contrast::Agent::Protect::Rule::Sqli::SqliteSqlScanner.new
|
92
93
|
}.cs__freeze
|
93
94
|
|
@@ -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_service'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Agent
|
6
8
|
module Protect
|
@@ -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_service'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Agent
|
6
8
|
module Protect
|
@@ -1,6 +1,7 @@
|
|
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'
|
4
5
|
cs__scoped_require 'contrast/utils/timer'
|
5
6
|
|
6
7
|
module Contrast
|
@@ -11,7 +12,6 @@ module Contrast
|
|
11
12
|
# of unsafe external entity resolution.
|
12
13
|
class Xxe < Contrast::Agent::Protect::Rule::Base
|
13
14
|
NAME = 'xxe'
|
14
|
-
EXPLOIT_CHARACTERS = Contrast::Utils::ObjectShare::EMPTY_ARRAY
|
15
15
|
BLOCK_MESSAGE = 'XXE rule triggered. Response blocked.'
|
16
16
|
EXTERNAL_ENTITY_PATTERN = /<!ENTITY\s+[a-zA-Z0-f]+\s+(?:SYSTEM|PUBLIC)\s+(.*?)>/.cs__freeze
|
17
17
|
|
@@ -19,6 +19,14 @@ module Contrast
|
|
19
19
|
NAME
|
20
20
|
end
|
21
21
|
|
22
|
+
# Given an xml, evaluate it for an XXE attack.
|
23
|
+
#
|
24
|
+
# @param context [Contrast::Agent::RequestContext] the context of the
|
25
|
+
# request in which this input is evaluated.
|
26
|
+
# @param framework [Object] the name of the Parser being used.
|
27
|
+
# @param xml [Object] the container of the XML to be checked.
|
28
|
+
# @raise [Contrast::SecurityException] Security exception if an XXE
|
29
|
+
# attack is found and the rule is in block mode.
|
22
30
|
def infilter context, framework, xml
|
23
31
|
result = find_attacker(context, xml, framework: framework)
|
24
32
|
return nil unless result
|
@@ -31,12 +39,10 @@ module Contrast
|
|
31
39
|
|
32
40
|
protected
|
33
41
|
|
34
|
-
def find_attacker context, xml, **
|
42
|
+
def find_attacker context, xml, **_kwargs
|
35
43
|
return nil unless xml
|
36
44
|
return nil if protect_excluded_by_code?
|
37
45
|
|
38
|
-
logger.debug("checking: #{ name } in '#{ kwargs[:framework] }'")
|
39
|
-
|
40
46
|
xxe_details, last_idx = build_details(xml)
|
41
47
|
return nil unless xxe_details
|
42
48
|
|
@@ -12,24 +12,19 @@ module Contrast
|
|
12
12
|
access_component :agent, :app_context, :logging
|
13
13
|
|
14
14
|
initializer 'Contrast Ruby Agent Initializer' do |app|
|
15
|
-
if defined?(Rails) && defined?(Rails.logger)
|
16
|
-
Rails.logger.debug('In railtie ::')
|
17
|
-
Rails.logger.debug(app.middleware.inspect)
|
18
|
-
end
|
15
|
+
Rails.logger.debug("In railtie ::#{ app.middleware.inspect }") if defined?(Rails) && defined?(Rails.logger)
|
19
16
|
|
20
|
-
# TODO: RUBY-564 This logic is not specific to Rails and should be used more broadly
|
21
|
-
# with all web frameworks. Move this check to be a part of our new initialization
|
22
|
-
# routine.
|
23
17
|
if APP_CONTEXT.instrument_middleware_stack?
|
24
18
|
AGENT.insert_middleware(app)
|
25
19
|
else
|
26
20
|
Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.')
|
27
|
-
logger.debug(
|
21
|
+
logger.debug('Disabling Contrast for process', p_id: Process.pid)
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
31
25
|
rake_tasks do
|
32
26
|
load 'contrast/tasks/service.rb'
|
27
|
+
load 'contrast/tasks/config.rb'
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
@@ -25,20 +25,20 @@ module Contrast
|
|
25
25
|
return nil unless application_settings&.reactions&.any?
|
26
26
|
|
27
27
|
application_settings.reactions.each do |reaction|
|
28
|
-
logger.debug(nil, "Received the following reaction: #{ reaction.operation }")
|
29
|
-
|
30
28
|
# the enums are all uppercase, we need to downcase them before attempting to log
|
31
29
|
level = reaction.log_level.nil? ? :error : reaction.log_level.downcase
|
32
30
|
|
33
|
-
logger.with_level(
|
31
|
+
logger.with_level(level, reaction.message) if reaction.message
|
34
32
|
|
35
33
|
case reaction.operation
|
36
34
|
when :DISABLE
|
37
35
|
Contrast::Agent::DisableReaction.run reaction, level
|
38
|
-
when :NOOP
|
36
|
+
when :NOOP
|
39
37
|
# NOOP
|
40
38
|
else
|
41
|
-
logger.warn(
|
39
|
+
logger.warn(
|
40
|
+
'ReactionProcessor received a reaction with an unknown operation',
|
41
|
+
operation: reaction.operation)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -6,7 +6,6 @@ cs__scoped_require 'timeout'
|
|
6
6
|
|
7
7
|
cs__scoped_require 'contrast/utils/object_share'
|
8
8
|
cs__scoped_require 'contrast/utils/string_utils'
|
9
|
-
cs__scoped_require 'contrast/utils/comment_range'
|
10
9
|
cs__scoped_require 'contrast/utils/hash_digest'
|
11
10
|
cs__scoped_require 'contrast/components/interface'
|
12
11
|
|
@@ -18,7 +17,7 @@ module Contrast
|
|
18
17
|
# order to avoid repeatedly creating Strings & thrashing GC.
|
19
18
|
class Request
|
20
19
|
include Contrast::Components::Interface
|
21
|
-
access_component :logging, :scope
|
20
|
+
access_component :agent, :logging, :scope
|
22
21
|
|
23
22
|
extend Forwardable
|
24
23
|
|
@@ -108,7 +107,7 @@ module Contrast
|
|
108
107
|
def request_method
|
109
108
|
rack_request.get_header(Rack::REQUEST_METHOD)
|
110
109
|
rescue StandardError => e
|
111
|
-
logger.warn(
|
110
|
+
logger.warn('Unable to extract request method', e)
|
112
111
|
UNKNOWN_REQUEST_METHOD
|
113
112
|
end
|
114
113
|
|
@@ -160,10 +159,6 @@ module Contrast
|
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
163
|
-
def header_value key
|
164
|
-
normalized_request_headers[Contrast::Utils::StringUtils.normalized_key(key)]
|
165
|
-
end
|
166
|
-
|
167
162
|
# Return a flattened hash of params with realized paths for keys, in
|
168
163
|
# addition to a separate, valueless, entry for each nest key.
|
169
164
|
# See RUBY-621 for more details.
|
@@ -209,15 +204,15 @@ module Contrast
|
|
209
204
|
body = @rack_request.body
|
210
205
|
if defined?(Rack::Multipart)
|
211
206
|
if defined?(Rack::Multipart::UploadedFile) && body.is_a?(Rack::Multipart::UploadedFile)
|
212
|
-
logger.
|
207
|
+
logger.trace("not parsing uploaded file body :: #{ body.original_filename }::#{ body.content_type }")
|
213
208
|
@_request_body = nil
|
214
209
|
else
|
215
|
-
logger.
|
216
|
-
@_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body)
|
210
|
+
logger.trace("parsing body from request :: #{ body.cs__class.cs__name }")
|
211
|
+
@_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body))
|
217
212
|
end
|
218
213
|
else
|
219
|
-
logger.
|
220
|
-
@_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body)
|
214
|
+
logger.trace('Rack before 1.3.x does not support Rack::Multipart')
|
215
|
+
@_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body))
|
221
216
|
end
|
222
217
|
|
223
218
|
true
|
@@ -336,7 +331,7 @@ module Contrast
|
|
336
331
|
end
|
337
332
|
|
338
333
|
def omit_body?
|
339
|
-
return true if
|
334
|
+
return true if AGENT.omit_body?
|
340
335
|
return false if document_type == :XML
|
341
336
|
return false if document_type == :JSON
|
342
337
|
|
@@ -352,10 +347,8 @@ module Contrast
|
|
352
347
|
address.host = Contrast::Utils::StringUtils.force_utf8(Socket.gethostname)
|
353
348
|
address.ip = Contrast::Utils::StringUtils.force_utf8(Resolv.getaddress(address.host))
|
354
349
|
end
|
355
|
-
rescue Timeout::Error
|
356
|
-
logger.warn(nil, "Timeout resolving host or ip in #{ address }")
|
357
350
|
rescue StandardError => e
|
358
|
-
logger.warn(
|
351
|
+
logger.warn('Unable to resolve host or ip', e, address: address)
|
359
352
|
end
|
360
353
|
address
|
361
354
|
end
|
@@ -444,8 +437,8 @@ module Contrast
|
|
444
437
|
body.rewind if can_rewind
|
445
438
|
body.read
|
446
439
|
rescue StandardError => e
|
447
|
-
logger.error(
|
448
|
-
logger.
|
440
|
+
logger.error('Error in attempt to read body', message: e.message)
|
441
|
+
logger.trace('With Stack', e)
|
449
442
|
body.to_s
|
450
443
|
ensure
|
451
444
|
# be a good citizen and rewind
|
@@ -4,7 +4,6 @@
|
|
4
4
|
cs__scoped_require 'contrast/utils/timer'
|
5
5
|
cs__scoped_require 'contrast/agent/request'
|
6
6
|
cs__scoped_require 'contrast/agent/response'
|
7
|
-
cs__scoped_require 'contrast/utils/comment_range'
|
8
7
|
cs__scoped_require 'contrast/utils/inventory_util'
|
9
8
|
cs__scoped_require 'contrast/components/interface'
|
10
9
|
|
@@ -15,7 +14,7 @@ module Contrast
|
|
15
14
|
# in a standardized and normalized format which the Agent understands.
|
16
15
|
class RequestContext
|
17
16
|
include Contrast::Components::Interface
|
18
|
-
access_component :
|
17
|
+
access_component :agent, :analysis, :logging, :settings, :scope
|
19
18
|
|
20
19
|
EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
|
21
20
|
|
@@ -46,6 +45,7 @@ module Contrast
|
|
46
45
|
# build analyzer
|
47
46
|
@do_not_track = false
|
48
47
|
@speedracer_input_analysis = EMPTY_INPUT_ANALYSIS_PB
|
48
|
+
speedracer_input_analysis.request = request
|
49
49
|
|
50
50
|
# flag to indicate whether the app is fully loaded
|
51
51
|
@app_loaded = !!app_loaded
|
@@ -67,10 +67,6 @@ module Contrast
|
|
67
67
|
@app_loaded
|
68
68
|
end
|
69
69
|
|
70
|
-
def analyze?
|
71
|
-
@sample_request || @sample_response
|
72
|
-
end
|
73
|
-
|
74
70
|
def analyze_request?
|
75
71
|
@sample_request
|
76
72
|
end
|
@@ -94,10 +90,8 @@ module Contrast
|
|
94
90
|
# For TS routes
|
95
91
|
@observed_route.signature = route.route
|
96
92
|
@observed_route.verb = route.verb
|
97
|
-
@observed_route.session_id =
|
98
|
-
|
99
|
-
# TODO: SPEED-273: deprecate when SR handles this. ContrastUI API currently does not allow empty url, so we have to provide a default
|
100
|
-
@observed_route.url = route.url.empty? ? Contrast::Utils::ObjectShare::SLASH : route.url
|
93
|
+
@observed_route.session_id = SETTINGS.session_id
|
94
|
+
@observed_route.url = route.url if route.url
|
101
95
|
end
|
102
96
|
|
103
97
|
# Collect the results for the given rule with the given action
|
@@ -115,25 +109,28 @@ module Contrast
|
|
115
109
|
end
|
116
110
|
|
117
111
|
def service_extract_request
|
112
|
+
return false unless AGENT.enabled?
|
113
|
+
return false unless PROTECT.enabled?
|
118
114
|
return false if @do_not_track
|
119
115
|
|
120
|
-
service_response =
|
116
|
+
service_response = Contrast::Utils::ServiceSenderUtil.send_event_immediately(@activity.http_request)
|
121
117
|
return false unless service_response
|
122
118
|
|
123
119
|
handle_protect_state(service_response)
|
124
120
|
ia = service_response.input_analysis
|
125
121
|
if ia
|
126
|
-
logger.
|
127
|
-
logger.
|
122
|
+
logger.trace("Analysis from Contrast Service: evaluations=#{ ia.results.length }")
|
123
|
+
logger.trace('Results', input_analysis: ia.inspect)
|
128
124
|
@speedracer_input_analysis = ia
|
125
|
+
speedracer_input_analysis.request = request
|
129
126
|
else
|
130
|
-
logger.
|
127
|
+
logger.trace('Analysis from Contrast Service was empty.')
|
131
128
|
false
|
132
129
|
end
|
133
130
|
rescue Contrast::SecurityException
|
134
131
|
raise
|
135
132
|
rescue StandardError => e
|
136
|
-
logger.warn(
|
133
|
+
logger.warn('Unable to extract Contrast Service information from request', e)
|
137
134
|
false
|
138
135
|
end
|
139
136
|
|
@@ -154,7 +151,7 @@ module Contrast
|
|
154
151
|
build_attack_results(agent_settings)
|
155
152
|
|
156
153
|
msg = agent_settings.protect_state.security_message
|
157
|
-
logger.warn(
|
154
|
+
logger.warn('Contrast Service said to block this request')
|
158
155
|
raise Contrast::SecurityException.new(nil, (msg || 'Blocking suspicious behavior'))
|
159
156
|
end
|
160
157
|
|
@@ -165,7 +162,7 @@ module Contrast
|
|
165
162
|
@response = Contrast::Agent::Response.new(rack_response)
|
166
163
|
activity.http_response = @response.dtm if @sample_response
|
167
164
|
rescue StandardError => e
|
168
|
-
logger.error(
|
165
|
+
logger.error('Unable to extract information after request', e)
|
169
166
|
end
|
170
167
|
|
171
168
|
def add_property key, value
|
@@ -195,7 +192,7 @@ module Contrast
|
|
195
192
|
rule = PROTECT.rule(rule_id)
|
196
193
|
next unless rule
|
197
194
|
|
198
|
-
logger.debug(
|
195
|
+
logger.debug('Building attack result from Contrast Service input analysis result', result: ia_result.inspect)
|
199
196
|
|
200
197
|
attack_result = if rule.mode == :BLOCK
|
201
198
|
# special case for rules (like reflected xss)
|
@@ -216,7 +213,7 @@ module Contrast
|
|
216
213
|
end
|
217
214
|
|
218
215
|
attack_results_by_rule.each_pair do |_, attack_result|
|
219
|
-
logger.
|
216
|
+
logger.info('Blocking attack result', rule: attack_result.rule_id)
|
220
217
|
activity.results << attack_result
|
221
218
|
end
|
222
219
|
end
|