contrast-agent 5.3.0 → 6.1.1
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/Rakefile +1 -1
- data/ext/build_funchook.rb +3 -3
- data/ext/cs__assess_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +24 -6
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
- data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +1 -1
- data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
- data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
- data/ext/cs__assess_string/cs__assess_string.c +21 -1
- data/ext/cs__assess_test/cs__assess_test.h +9 -0
- data/ext/cs__assess_test/cs__assess_tests.c +22 -0
- data/ext/cs__assess_test/extconf.rb +5 -0
- data/ext/cs__common/cs__common.c +113 -11
- data/ext/cs__common/cs__common.h +29 -5
- data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +146 -97
- data/ext/cs__tests/cs__tests.c +12 -0
- data/ext/cs__tests/cs__tests.h +3 -0
- data/ext/cs__tests/extconf.rb +5 -0
- data/ext/extconf_common.rb +1 -1
- data/lib/contrast/agent/assess/contrast_object.rb +16 -16
- data/lib/contrast/agent/assess/events/source_event.rb +17 -19
- data/lib/contrast/agent/assess/finalizers/hash.rb +4 -2
- data/lib/contrast/agent/assess/policy/policy.rb +9 -10
- data/lib/contrast/agent/assess/policy/policy_node.rb +58 -36
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +48 -14
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +119 -0
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
- data/lib/contrast/agent/assess/policy/propagator/split.rb +17 -21
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
- data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +11 -17
- data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +2 -2
- data/lib/contrast/agent/assess/property/tagged.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
- data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
- data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
- data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
- data/lib/contrast/agent/assess/tag.rb +13 -14
- data/lib/contrast/agent/at_exit_hook.rb +12 -1
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
- data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/inventory/database_config.rb +10 -3
- data/lib/contrast/agent/middleware.rb +10 -5
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
- data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
- data/lib/contrast/agent/patching/policy/patch.rb +20 -19
- data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
- data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
- data/lib/contrast/agent/patching/policy/policy.rb +13 -15
- data/lib/contrast/agent/patching/policy/policy_node.rb +32 -21
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +132 -75
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
- data/lib/contrast/agent/protect/rule/base.rb +53 -9
- data/lib/contrast/agent/protect/rule/base_service.rb +31 -12
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +23 -3
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
- data/lib/contrast/agent/protect/rule/default_scanner.rb +2 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +72 -46
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -2
- data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +2 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
- data/lib/contrast/agent/protect/rule/xss.rb +17 -0
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
- data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
- data/lib/contrast/agent/reporting/masker/masker.rb +243 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
- data/lib/contrast/agent/reporting/report.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +29 -22
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +13 -5
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
- data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +44 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
- data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +8 -11
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
- data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
- data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +29 -13
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +163 -122
- data/lib/contrast/agent/reporting/settings/application_settings.rb +10 -1
- data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +7 -35
- data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
- data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
- data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
- data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
- data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
- data/lib/contrast/agent/request.rb +5 -5
- data/lib/contrast/agent/request_context.rb +25 -21
- data/lib/contrast/agent/request_context_extend.rb +12 -25
- data/lib/contrast/agent/request_handler.rb +7 -3
- data/lib/contrast/agent/response.rb +2 -0
- data/lib/contrast/agent/rule_set.rb +2 -2
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +6 -48
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/telemetry/base.rb +155 -0
- data/lib/contrast/agent/telemetry/events/event.rb +35 -0
- data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +59 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
- data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
- data/lib/contrast/agent/thread_watcher.rb +52 -68
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +8 -0
- data/lib/contrast/agent.rb +4 -3
- data/lib/contrast/api/communication/messaging_queue.rb +29 -12
- data/lib/contrast/api/communication/response_processor.rb +7 -10
- 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 +1 -1
- data/lib/contrast/api/communication/speedracer.rb +3 -3
- data/lib/contrast/api/decorators/activity.rb +33 -0
- data/lib/contrast/api/decorators/address.rb +1 -1
- data/lib/contrast/api/decorators/agent_startup.rb +10 -9
- data/lib/contrast/api/decorators/application_settings.rb +1 -1
- data/lib/contrast/api/decorators/application_startup.rb +4 -4
- data/lib/contrast/api/decorators/http_request.rb +1 -1
- data/lib/contrast/api/decorators/response_type.rb +17 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/agent.rb +1 -1
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/base.rb +1 -1
- data/lib/contrast/components/config.rb +19 -28
- data/lib/contrast/components/contrast_service.rb +13 -1
- data/lib/contrast/components/protect.rb +2 -2
- data/lib/contrast/components/sampling.rb +8 -12
- data/lib/contrast/components/settings.rb +151 -19
- data/lib/contrast/config/agent_configuration.rb +34 -41
- data/lib/contrast/config/api_configuration.rb +16 -75
- data/lib/contrast/config/api_proxy_configuration.rb +9 -48
- data/lib/contrast/config/application_configuration.rb +24 -95
- data/lib/contrast/config/assess_configuration.rb +21 -76
- data/lib/contrast/config/assess_rules_configuration.rb +13 -38
- data/lib/contrast/config/base_configuration.rb +11 -76
- data/lib/contrast/config/certification_configuration.rb +15 -68
- data/lib/contrast/config/exception_configuration.rb +15 -59
- data/lib/contrast/config/heap_dump_configuration.rb +19 -73
- data/lib/contrast/config/inventory_configuration.rb +11 -55
- data/lib/contrast/config/logger_configuration.rb +8 -41
- data/lib/contrast/config/protect_configuration.rb +23 -10
- data/lib/contrast/config/protect_rule_configuration.rb +23 -37
- data/lib/contrast/config/protect_rules_configuration.rb +39 -43
- data/lib/contrast/config/request_audit_configuration.rb +16 -55
- data/lib/contrast/config/root_configuration.rb +71 -14
- data/lib/contrast/config/ruby_configuration.rb +14 -47
- data/lib/contrast/config/sampling_configuration.rb +12 -65
- data/lib/contrast/config/server_configuration.rb +13 -45
- data/lib/contrast/config/service_configuration.rb +18 -54
- data/lib/contrast/configuration.rb +25 -17
- data/lib/contrast/extension/assess/array.rb +1 -1
- data/lib/contrast/extension/assess/erb.rb +1 -1
- data/lib/contrast/extension/assess/marshal.rb +1 -1
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/extension.rb +2 -2
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/base_support.rb +8 -8
- data/lib/contrast/framework/grape/support.rb +3 -3
- data/lib/contrast/framework/manager.rb +7 -7
- data/lib/contrast/framework/manager_extend.rb +1 -1
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +14 -46
- data/lib/contrast/framework/rails/support.rb +2 -2
- data/lib/contrast/framework/sinatra/support.rb +1 -1
- data/lib/contrast/logger/aliased_logging.rb +94 -0
- data/lib/contrast/logger/application.rb +1 -5
- data/lib/contrast/logger/cef_log.rb +15 -15
- data/lib/contrast/logger/format.rb +1 -1
- data/lib/contrast/logger/log.rb +8 -8
- data/lib/contrast/tasks/config.rb +100 -4
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/object_store.rb +36 -0
- data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
- data/lib/contrast/utils/assess/tracking_util.rb +4 -4
- data/lib/contrast/utils/class_util.rb +9 -22
- data/lib/contrast/utils/findings.rb +3 -3
- data/lib/contrast/utils/hash_digest.rb +6 -7
- data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
- data/lib/contrast/utils/log_utils.rb +7 -5
- data/lib/contrast/utils/lru_cache.rb +1 -1
- data/lib/contrast/utils/metrics_hash.rb +1 -1
- data/lib/contrast/utils/middleware_utils.rb +15 -14
- data/lib/contrast/utils/net_http_base.rb +5 -5
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +1 -6
- data/lib/contrast/utils/patching/policy/patch_utils.rb +6 -7
- data/lib/contrast/utils/request_utils.rb +2 -2
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/sha256_builder.rb +4 -4
- data/lib/contrast/utils/stack_trace_utils.rb +31 -13
- data/lib/contrast/utils/telemetry.rb +22 -7
- data/lib/contrast/utils/telemetry_client.rb +28 -16
- data/lib/contrast/utils/telemetry_hash.rb +41 -0
- data/lib/contrast/utils/telemetry_identifier.rb +18 -3
- data/lib/contrast/utils/timer.rb +1 -1
- data/lib/contrast.rb +9 -0
- data/resources/assess/policy.json +99 -1
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +10 -9
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +99 -29
- data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
- data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
- data/lib/contrast/agent/telemetry.rb +0 -137
- data/lib/contrast/agent/telemetry_event.rb +0 -33
- data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -1,8 +1,6 @@
|
|
1
1
|
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require 'contrast/utils/exclude_key'
|
5
|
-
|
6
4
|
module Contrast
|
7
5
|
module Logger
|
8
6
|
# Our decorator for the Ougai logger allowing for the logging of the
|
@@ -19,7 +17,7 @@ module Contrast
|
|
19
17
|
env_key = env_key.to_s
|
20
18
|
next unless ENV_KEYS.include?(env_key) ||
|
21
19
|
(env_key.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) &&
|
22
|
-
!env_key.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER
|
20
|
+
!env_key.start_with?("#{ Contrast::Components::Config::CONTRAST_ENV_MARKER }API"))
|
23
21
|
|
24
22
|
info('Environment settings', key: env_key, value: env_value)
|
25
23
|
end
|
@@ -31,8 +29,6 @@ module Contrast
|
|
31
29
|
loggable = ::Contrast::CONFIG.loggable
|
32
30
|
info('Current configuration', configuration: loggable)
|
33
31
|
env_keys = ENV.keys.select do |env_key|
|
34
|
-
next if Contrast::Utils::ExcludeKey.excludable? env_key.to_s
|
35
|
-
|
36
32
|
env_key&.to_s&.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER)
|
37
33
|
end
|
38
34
|
env_items = env_keys.map { |env_key| Contrast::Utils::EnvConfigurationItem.new(env_key, nil) }
|
@@ -30,7 +30,7 @@ module Contrast
|
|
30
30
|
else
|
31
31
|
cs__error(*args, **kwargs)
|
32
32
|
end
|
33
|
-
args.each { |arg| raise
|
33
|
+
args.each { |arg| raise(arg) if arg && arg.cs__class < Exception }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -69,11 +69,11 @@ module Contrast
|
|
69
69
|
if @_cef_logger
|
70
70
|
@_cef_logger.error('Unable to process update to LoggerManager.', e)
|
71
71
|
else
|
72
|
-
puts
|
73
|
-
raise
|
72
|
+
puts('Unable to process update to LoggerManager.')
|
73
|
+
raise(e) if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
|
74
74
|
|
75
|
-
puts
|
76
|
-
puts
|
75
|
+
puts(e.message)
|
76
|
+
puts(e.backtrace.join("\n"))
|
77
77
|
end
|
78
78
|
# rubocop:enable Rails/Output
|
79
79
|
end
|
@@ -99,28 +99,28 @@ module Contrast
|
|
99
99
|
|
100
100
|
def virtual_patch_message patch, outcome
|
101
101
|
message = "Virtual Patch #{ patch.fetch(:name, '') } - #{ patch[:uuid] } was triggered by this request."
|
102
|
-
log
|
102
|
+
log([message, patch, outcome], ::Logger::Severity::DEBUG)
|
103
103
|
end
|
104
104
|
|
105
105
|
def bot_blocking_message matching_bot, outcome
|
106
106
|
message = "User agent #{ matching_bot[:user_agent] } matched the disallowed value #{ matching_bot[:bot] }"
|
107
|
-
log
|
107
|
+
log([message, matching_bot, outcome], ::Logger::Severity::DEBUG)
|
108
108
|
end
|
109
109
|
|
110
110
|
def ip_denylisted_message remote_ip, block_entry, outcome
|
111
111
|
message = "IP Address #{ remote_ip } matched the disallowed value" \
|
112
112
|
"#{ block_entry[:ip] } in the IP Blacklist #{ block_entry[:uuid] }"
|
113
|
-
log
|
113
|
+
log([message, block_entry, outcome], ::Logger::Severity::DEBUG)
|
114
114
|
end
|
115
115
|
|
116
116
|
def successful_attack rule_id, outcome, input_type = nil, input_value = nil
|
117
117
|
if input_type.present? && input_value.present?
|
118
118
|
successful_attack_with_input = "#{ input_type } had a value that successfully exploited" \
|
119
119
|
"#{ rule_id } - #{ input_value }"
|
120
|
-
log
|
120
|
+
log([successful_attack_with_input, rule_id, outcome], ::Logger::Severity::WARN)
|
121
121
|
else
|
122
122
|
successful_attack_wo_input = "An effective attack was detected against #{ rule_id }"
|
123
|
-
log
|
123
|
+
log([successful_attack_wo_input, rule_id, outcome], ::Logger::Severity::WARN)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -128,10 +128,10 @@ module Contrast
|
|
128
128
|
if input_type.present? && input_value.present?
|
129
129
|
ineffective_attack_with_input = "#{ input_type } had a value that matched a signature for, " \
|
130
130
|
"but did not successfully exploit #{ rule_id } - #{ input_value }"
|
131
|
-
log
|
131
|
+
log([ineffective_attack_with_input, rule_id, outcome], ::Logger::Severity::WARN)
|
132
132
|
else
|
133
133
|
ineffective_attack_wo_input = "An unsuccessful attack was detected against #{ rule_id }"
|
134
|
-
log
|
134
|
+
log([ineffective_attack_wo_input, rule_id, outcome], ::Logger::Severity::WARN)
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
@@ -140,10 +140,10 @@ module Contrast
|
|
140
140
|
if input_type.present? && input_value.present?
|
141
141
|
suspicious_attack_with = "#{ input_type } included a potential attack value that was detected" \
|
142
142
|
"as suspicious using #{ rule_id } - #{ input_value }"
|
143
|
-
log
|
143
|
+
log([suspicious_attack_with, rule_id, outcome], ::Logger::WARN)
|
144
144
|
elsif input_value.present?
|
145
|
-
suspicious_attack_without =
|
146
|
-
log
|
145
|
+
suspicious_attack_without = "Suspicious activity indicates a potential attack using #{ rule_id }"
|
146
|
+
log([suspicious_attack_without, rule_id, outcome], ::Logger::WARN)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
@@ -10,6 +10,7 @@ module Contrast
|
|
10
10
|
# Our format for the Ougai logger allowing for custom log format that
|
11
11
|
# extends the behavior of the default Ougai logger
|
12
12
|
class Format < Ougai::Formatters::Bunyan
|
13
|
+
NO_REQUEST_HASH = { request_id: -1 }.cs__freeze
|
13
14
|
LOG_TRACKER = Contrast::Utils::ThreadTracker.new
|
14
15
|
# Our override of the _call method to add in the extra data that we want,
|
15
16
|
# based on
|
@@ -49,7 +50,6 @@ module Contrast
|
|
49
50
|
hash
|
50
51
|
end
|
51
52
|
|
52
|
-
NO_REQUEST_HASH = { request_id: -1 }.cs__freeze
|
53
53
|
def request_hash
|
54
54
|
@request_tracker_defined ||= defined?(Contrast::Agent) && defined?(Contrast::Agent::REQUEST_TRACKER)
|
55
55
|
return NO_REQUEST_HASH unless @request_tracker_defined
|
data/lib/contrast/logger/log.rb
CHANGED
@@ -44,8 +44,8 @@ module Contrast
|
|
44
44
|
untimed_func_symbol = "untimed_#{ meth_spec.method_name }".to_sym
|
45
45
|
send_to = class_method ? meth_spec.clazz.cs__singleton_class : meth_spec.clazz
|
46
46
|
meth_spec.clazz.class_eval do
|
47
|
-
include
|
48
|
-
extend
|
47
|
+
include(Contrast::Components::Logger::InstanceMethods)
|
48
|
+
extend(Contrast::Components::Logger::InstanceMethods)
|
49
49
|
|
50
50
|
send_to.send(:alias_method, untimed_func_symbol, meth_spec.method_name)
|
51
51
|
meth_spec.aliased = true
|
@@ -73,7 +73,7 @@ module Contrast
|
|
73
73
|
next if meth_spec.aliased
|
74
74
|
|
75
75
|
is_class_method = meth_spec.clazz.singleton_methods(false).include?(meth_spec.method_name)
|
76
|
-
trace_time_class_method
|
76
|
+
trace_time_class_method(meth_spec, is_class_method)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -96,7 +96,7 @@ module Contrast
|
|
96
96
|
else
|
97
97
|
cs__error(*args, **kwargs)
|
98
98
|
end
|
99
|
-
args.each { |arg| raise
|
99
|
+
args.each { |arg| raise(arg) if arg && arg.cs__class < Exception }
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -142,11 +142,11 @@ module Contrast
|
|
142
142
|
if logger
|
143
143
|
logger.error('Unable to process update to LoggerManager.', e)
|
144
144
|
else
|
145
|
-
puts
|
146
|
-
raise
|
145
|
+
puts('Unable to process update to LoggerManager.')
|
146
|
+
raise(e) if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
|
147
147
|
|
148
|
-
puts
|
149
|
-
puts
|
148
|
+
puts(e.message)
|
149
|
+
puts(e.backtrace.join("\n"))
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -2,10 +2,12 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'yaml'
|
5
|
+
require 'contrast/configuration'
|
6
|
+
require 'contrast/agent/reporting/reporter'
|
5
7
|
|
6
8
|
module Contrast
|
7
9
|
# A Rake task to generate a contrast_security.yaml file with some basic settings
|
8
|
-
module Config
|
10
|
+
module Config # rubocop:disable Metrics/ModuleLength
|
9
11
|
extend Rake::DSL
|
10
12
|
DEFAULT_CONFIG = {
|
11
13
|
'api' => {
|
@@ -29,6 +31,9 @@ module Contrast
|
|
29
31
|
}
|
30
32
|
}.cs__freeze
|
31
33
|
|
34
|
+
SKIP_LOG = %w[service_key api_key].cs__freeze
|
35
|
+
REQUIRED = %i[url api_key service_key user_name].cs__freeze
|
36
|
+
|
32
37
|
namespace :contrast do
|
33
38
|
namespace :config do
|
34
39
|
desc 'Create a contrast_security.yaml in the applications root directory'
|
@@ -38,9 +43,7 @@ module Contrast
|
|
38
43
|
if File.exist?(target_path)
|
39
44
|
puts 'WARNING: contrast_security.yaml already exists'
|
40
45
|
else
|
41
|
-
File.
|
42
|
-
f.write(YAML.dump(DEFAULT_CONFIG))
|
43
|
-
end
|
46
|
+
File.write(target_path, YAML.dump(DEFAULT_CONFIG))
|
44
47
|
|
45
48
|
puts "Created contrast_security.yaml at #{ target_path }"
|
46
49
|
puts 'Open the file and enter your Contrast Security api keys or set them via environment variables'
|
@@ -49,5 +52,98 @@ module Contrast
|
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|
55
|
+
|
56
|
+
namespace :contrast do
|
57
|
+
namespace :config do
|
58
|
+
desc 'Validate the provided Contrast configuration and confirm connectivity'
|
59
|
+
task validate: :environment do
|
60
|
+
puts 'Validating Agent Configuration...'
|
61
|
+
Contrast::Config.validate_config
|
62
|
+
puts '...done!'
|
63
|
+
puts 'Validating Contrast Reporter Headers...'
|
64
|
+
reporter = Contrast::Config.validate_headers
|
65
|
+
puts '...done!'
|
66
|
+
puts 'Testing Reporter Client Connection...'
|
67
|
+
Contrast::Config.test_connection(reporter) if reporter
|
68
|
+
puts '...done!'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.validate_config
|
73
|
+
config = Contrast::Configuration.new
|
74
|
+
abort('Unable to Build Config') unless config
|
75
|
+
missing = []
|
76
|
+
api_hash = config.root.api.to_hash
|
77
|
+
api_hash.each_key do |key|
|
78
|
+
value = mask_keys(api_hash, key)
|
79
|
+
if value.is_a?(Contrast::Config::ApiProxyConfiguration)
|
80
|
+
Contrast::Config.validate_proxy(value)
|
81
|
+
elsif value.is_a?(Contrast::Config::CertificationConfiguration)
|
82
|
+
Contrast::Config.validate_cert(value)
|
83
|
+
next
|
84
|
+
elsif value.is_a?(Contrast::Config::RequestAuditConfiguration)
|
85
|
+
Contrast::Config.validate_audit(value)
|
86
|
+
next
|
87
|
+
elsif value.nil? && REQUIRED.includes?(key.to_sym)
|
88
|
+
missing << key
|
89
|
+
end
|
90
|
+
end
|
91
|
+
abort("Missing required API configuration values: #{ missing.join(', ') }") unless missing.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.validate_proxy config
|
95
|
+
puts("Proxy Enabled: #{ config.enable }")
|
96
|
+
return unless config.enable
|
97
|
+
|
98
|
+
puts("Proxy URL: #{ config.url }")
|
99
|
+
abort('Proxy Enabled but no Proxy URL given') unless config.url
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.validate_cert config
|
103
|
+
puts("Certification Enabled: #{ config.enable }")
|
104
|
+
return unless config.enable
|
105
|
+
|
106
|
+
puts("CA File: #{ config.ca_file }")
|
107
|
+
abort('CA file path not provided') unless config.ca_file
|
108
|
+
puts("Cert File: #{ config.cert_file }")
|
109
|
+
abort('Cert file path not provided') unless config.cert_file
|
110
|
+
puts("Key File: #{ config.key_file }")
|
111
|
+
abort('Key file path not provided') unless config.key_file
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.validate_audit config
|
115
|
+
puts("Request Audit Enabled: #{ config.enable }")
|
116
|
+
return unless config.enable
|
117
|
+
|
118
|
+
config.each do |k, v|
|
119
|
+
puts("#{ k }::#{ v }")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.validate_headers
|
124
|
+
missing = []
|
125
|
+
reporter = Contrast::Agent::Reporter.new
|
126
|
+
reporter_headers = reporter.client.headers.to_hash
|
127
|
+
reporter_headers.each_key do |key|
|
128
|
+
value = mask_keys(reporter_headers, key)
|
129
|
+
missing << key if value.nil?
|
130
|
+
end
|
131
|
+
abort("Missing required header values: #{ missing.join(', ') }") unless missing.empty?
|
132
|
+
reporter
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.test_connection reporter
|
136
|
+
connection = reporter.connection
|
137
|
+
abort('Failed to Initialize Connection please check error logs for details') unless connection
|
138
|
+
abort('Failed to Start Client please check error logs for details') unless reporter.client.startup!(connection)
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.mask_keys hash, key
|
142
|
+
value = hash[key]
|
143
|
+
redacted_value = Contrast::Configuration::REDACTED if SKIP_LOG.include?(key.to_s)
|
144
|
+
puts("#{ key }::#{ redacted_value || value }") unless value.is_a?(Contrast::Config::BaseConfiguration)
|
145
|
+
value
|
146
|
+
end
|
147
|
+
end
|
52
148
|
end
|
53
149
|
end
|
@@ -11,7 +11,7 @@ module Contrast
|
|
11
11
|
extend Rake::DSL
|
12
12
|
# Start the service if it is not already running
|
13
13
|
def self.start_service
|
14
|
-
puts
|
14
|
+
puts('Starting Contrast Service')
|
15
15
|
service_log = ::Contrast::CONTRAST_SERVICE.logger_path
|
16
16
|
if File.writable?(service_log)
|
17
17
|
spawn('contrast_service', out: File::NULL, err: service_log)
|
@@ -23,7 +23,7 @@ module Contrast
|
|
23
23
|
sleep(0.05) until Contrast::Utils::OS.running?
|
24
24
|
end
|
25
25
|
watcher.join(1)
|
26
|
-
puts
|
26
|
+
puts(Contrast::Utils::OS.running? ? 'Contrast Service started successfully.' : 'Contrast Service did not start.')
|
27
27
|
end
|
28
28
|
|
29
29
|
# Stop the service if it is running
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Contrast
|
5
|
+
module Utils
|
6
|
+
module Assess
|
7
|
+
# keep track of object properties and events data
|
8
|
+
class ObjectStore
|
9
|
+
def initialize capacity = 500
|
10
|
+
@capacity = capacity
|
11
|
+
@cache = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def get
|
15
|
+
@cache
|
16
|
+
end
|
17
|
+
|
18
|
+
def [] key
|
19
|
+
@cache[key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete key
|
23
|
+
@cache.delete(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
# We would keep object ids with capacity.
|
27
|
+
# If a reference is kept to an object only by it's id,
|
28
|
+
# It would be CG-ted safely.
|
29
|
+
def []= key, value
|
30
|
+
@cache[key] = value
|
31
|
+
@cache.shift if @cache.length > @capacity
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -10,6 +10,7 @@ module Contrast
|
|
10
10
|
APPEND_ACTION = 'APPEND'
|
11
11
|
CENTER_ACTION = 'CENTER'
|
12
12
|
INSERT_ACTION = 'INSERT'
|
13
|
+
BUFFER_ACTION = 'BUFFER'
|
13
14
|
KEEP_ACTION = 'KEEP'
|
14
15
|
NEXT_ACTION = 'NEXT'
|
15
16
|
NOOP_ACTION = 'NOOP'
|
@@ -30,6 +31,7 @@ module Contrast
|
|
30
31
|
INSERT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Insert,
|
31
32
|
KEEP_ACTION => Contrast::Agent::Assess::Policy::Propagator::Keep,
|
32
33
|
NEXT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Next,
|
34
|
+
BUFFER_ACTION => Contrast::Agent::Assess::Policy::Propagator::Buffer,
|
33
35
|
NOOP_ACTION => nil,
|
34
36
|
PREPEND_ACTION => Contrast::Agent::Assess::Policy::Propagator::Prepend,
|
35
37
|
REPLACE_ACTION => Contrast::Agent::Assess::Policy::Propagator::Replace,
|
@@ -94,6 +96,10 @@ module Contrast
|
|
94
96
|
def can_propagate? propagation_node, preshift, target
|
95
97
|
return false unless appropriate_target?(propagation_node, target)
|
96
98
|
return true if Contrast::Utils::Assess::TrackingUtil.tracked?(target)
|
99
|
+
if propagation_node.use_original_object?
|
100
|
+
# return true since we don't have preshift while using the original object.
|
101
|
+
return true
|
102
|
+
end
|
97
103
|
return false unless preshift
|
98
104
|
|
99
105
|
propagation_node.sources.each do |source|
|
@@ -50,9 +50,9 @@ module Contrast
|
|
50
50
|
|
51
51
|
idx += 1
|
52
52
|
if Contrast::Utils::DuckUtils.iterable_hash?(obj)
|
53
|
-
handle_hash
|
53
|
+
handle_hash(obj, idx)
|
54
54
|
elsif Contrast::Utils::DuckUtils.iterable_enumerable?(obj)
|
55
|
-
handle_enumerable
|
55
|
+
handle_enumerable(obj, idx)
|
56
56
|
else
|
57
57
|
Contrast::Agent::Assess::Tracker.tracked?(obj)
|
58
58
|
end
|
@@ -79,9 +79,9 @@ module Contrast
|
|
79
79
|
|
80
80
|
idx += 1
|
81
81
|
if Contrast::Utils::DuckUtils.iterable_hash?(obj)
|
82
|
-
handle_hash
|
82
|
+
handle_hash(obj, idx)
|
83
83
|
elsif Contrast::Utils::DuckUtils.iterable_enumerable?(obj)
|
84
|
-
handle_enumerable
|
84
|
+
handle_enumerable(obj, idx)
|
85
85
|
else
|
86
86
|
Contrast::Agent::Assess::Tracker.trackable?(obj)
|
87
87
|
end
|
@@ -33,7 +33,7 @@ module Contrast
|
|
33
33
|
# need to check
|
34
34
|
# @return [Boolean] if this method specifically was prepended
|
35
35
|
def prepended_method? mod, method_policy
|
36
|
-
target_module = determine_target_class
|
36
|
+
target_module = determine_target_class(mod, method_policy.instance_method)
|
37
37
|
ancestors = target_module.ancestors
|
38
38
|
return false unless prepended?(target_module, ancestors)
|
39
39
|
|
@@ -50,8 +50,8 @@ module Contrast
|
|
50
50
|
# After implementing the LRU Cache, we firstly need to check if already had that object cached and if we have
|
51
51
|
# it - we can return it directly; otherwise we'll calculate and store the result before returning.
|
52
52
|
#
|
53
|
-
#
|
54
|
-
#
|
53
|
+
# Combining of the caches have close performance, but keeping the two with current implementation has
|
54
|
+
# a slight advantage in performance. For now we can keep the things the way they are.
|
55
55
|
#
|
56
56
|
# @param object [Object, nil] the entity to convert to a String
|
57
57
|
# @return [String, Object] the human readable form of the String, as defined by
|
@@ -60,13 +60,13 @@ module Contrast
|
|
60
60
|
# Only treat object like a string if it actually is a string+ some subclasses of String override string
|
61
61
|
# methods we depend on
|
62
62
|
if object.cs__class == String
|
63
|
-
return @string_cache[object] if @string_cache.key?
|
63
|
+
return @string_cache[object] if @string_cache.key?(object)
|
64
64
|
|
65
65
|
@string_cache[object] = to_cached_string(object) || object.dup
|
66
66
|
else
|
67
|
-
return @lru_cache[object.__id__] if @lru_cache.key?
|
67
|
+
return @lru_cache[object.__id__] if @lru_cache.key?(object.__id__)
|
68
68
|
|
69
|
-
@lru_cache[object.__id__] = convert_object
|
69
|
+
@lru_cache[object.__id__] = convert_object(object)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -86,28 +86,15 @@ module Contrast
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
# The method const_defined? can
|
90
|
-
#
|
91
|
-
# truly truly defined, meaning it existed before this method was invoked, not as a result of it.
|
89
|
+
# The method Module.const_defined? can raise an exception if the constant is poorly named. As such, we need to
|
90
|
+
# handle the case where that exception is raised.
|
92
91
|
#
|
93
|
-
# TODO: RUBY-1326
|
94
|
-
# This is required to handle a bug in Ruby prior to 2.7.0. When we drop support for 2.6.X, we should remove
|
95
|
-
# this code. https://bugs.ruby-lang.org/issues/10741
|
96
92
|
# @param name [String] the name of the constant to look up
|
97
93
|
# @return [Boolean]
|
98
94
|
def truly_defined? name
|
99
95
|
return false unless name
|
100
96
|
|
101
|
-
|
102
|
-
previous_module = Module
|
103
|
-
segments.each do |segment|
|
104
|
-
return false if previous_module.cs__autoload?(segment)
|
105
|
-
return false unless previous_module.cs__const_defined?(segment)
|
106
|
-
|
107
|
-
previous_module = previous_module.cs__const_get(segment)
|
108
|
-
end
|
109
|
-
|
110
|
-
true
|
97
|
+
Module.cs__const_defined?(name)
|
111
98
|
rescue NameError # account for nonsense / poorly formatted constants
|
112
99
|
false
|
113
100
|
end
|
@@ -34,7 +34,7 @@ module Contrast
|
|
34
34
|
# @param ret [Object] the Return of the invoked method
|
35
35
|
# @param args [Array<Object>] the Arguments with which the method was invoked
|
36
36
|
def collect_finding trigger_node, source, object, ret, *args
|
37
|
-
push
|
37
|
+
push(trigger_node, source, object, ret, args)
|
38
38
|
logger.trace('Finding collected', node_id: trigger_node.id,
|
39
39
|
source_id: source.__id__,
|
40
40
|
rule: trigger_node.rule_id)
|
@@ -52,11 +52,11 @@ module Contrast
|
|
52
52
|
|
53
53
|
while @_collection.any?
|
54
54
|
finding = @_collection.pop
|
55
|
-
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding
|
55
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(finding[:trigger_node],
|
56
56
|
finding[:source],
|
57
57
|
finding[:object],
|
58
58
|
finding[:ret],
|
59
|
-
finding[:args]
|
59
|
+
finding[:args])
|
60
60
|
end
|
61
61
|
true
|
62
62
|
end
|
@@ -15,8 +15,8 @@ module Contrast
|
|
15
15
|
class HashDigest < Digest::Class
|
16
16
|
include Digest::Instance
|
17
17
|
extend Contrast::Utils::HashDigestExtend
|
18
|
-
|
19
18
|
CONTENT_LENGTH_HEADER = 'Content-Length'
|
19
|
+
CHARS = %w[a b c d e f g].cs__freeze
|
20
20
|
CRYPTO_RULES = %w[crypto-bad-ciphers crypto-bad-mac].cs__freeze
|
21
21
|
CONFIG_PATH_KEY = 'path'
|
22
22
|
CONFIG_SESSION_ID_KEY = 'sessionId'
|
@@ -24,6 +24,11 @@ module Contrast
|
|
24
24
|
CLASS_CONSTANT_NAME_KEY = 'name'
|
25
25
|
CLASS_LINE_NO_KEY = 'lineNo'
|
26
26
|
|
27
|
+
def initialize
|
28
|
+
super
|
29
|
+
@crc32 = 0
|
30
|
+
end
|
31
|
+
|
27
32
|
# Update to CRC checksum the finding route and verb if finding route
|
28
33
|
# [Contrast::Api::Dtm::RouteCoverage] is available else update the passed
|
29
34
|
# request or Contrast::REQUEST_TRACKER.current.request uri and used request
|
@@ -77,7 +82,6 @@ module Contrast
|
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
80
|
-
CHARS = %w[a b c d e f g].cs__freeze
|
81
85
|
# This method converts and integer value for length into a string value
|
82
86
|
# that we can hash on, based on the logarithmic value of the length, and
|
83
87
|
# updates the current hash with that value.
|
@@ -86,11 +90,6 @@ module Contrast
|
|
86
90
|
update(CHARS[Math.log10(chr.to_s.length).to_i] || CHARS[-1])
|
87
91
|
end
|
88
92
|
|
89
|
-
def initialize
|
90
|
-
super
|
91
|
-
@crc32 = 0
|
92
|
-
end
|
93
|
-
|
94
93
|
# Converts given string to CRC checksum. CRC32 checksum ensures that If error
|
95
94
|
# of a single bit occurs, the CRC checksum will fail, regardless of any other
|
96
95
|
# property of the transmitted data, including its length. Called several times
|
@@ -13,7 +13,7 @@ module Contrast
|
|
13
13
|
delay = control[:delay]
|
14
14
|
clean = control[:clean]
|
15
15
|
|
16
|
-
logger.info
|
16
|
+
logger.info(<<~WARNING)
|
17
17
|
*****************************************************
|
18
18
|
******** HEAP DUMP HAS BEEN ENABLED ********
|
19
19
|
*** APPLICATION PROCESS WILL EXIT UPON COMPLETION ***
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/object_share'
|
5
|
+
require 'contrast/agent/reporting/input_analysis/input_type'
|
6
|
+
require 'contrast/agent/reporting/input_analysis/score_level'
|
7
|
+
require 'contrast/agent/protect/input_analyzer/input_analyzer'
|
8
|
+
|
9
|
+
module Contrast
|
10
|
+
module Agent
|
11
|
+
module Protect
|
12
|
+
module Rule
|
13
|
+
# This module will include all the similar information for all input classifications
|
14
|
+
# between different rules
|
15
|
+
module InputClassificationBase
|
16
|
+
include Contrast::Agent::Reporting::InputType
|
17
|
+
include Contrast::Agent::Reporting::ScoreLevel
|
18
|
+
|
19
|
+
# Input Classification stage is done to determine if an user input is
|
20
|
+
# WORTHWATCHING or to be ignored.
|
21
|
+
#
|
22
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
23
|
+
# @param value [String, Array<String>] the value of the input.
|
24
|
+
# @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
|
25
|
+
# agent analysis from the current
|
26
|
+
# Request.
|
27
|
+
# @return ia [Contrast::Agent::Reporting::InputAnalysis] with updated results.
|
28
|
+
def classify input_type, value, input_analysis # rubocop:disable Lint/UnusedMethodArgument
|
29
|
+
return false unless input_analysis.request
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
# Creates new isntance of InputAnalysisResult with basic info.
|
35
|
+
#
|
36
|
+
# @param rule_id [String] The name of the Protect Rule.
|
37
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
38
|
+
# @param value [String, Array<String>] the value of the input.
|
39
|
+
# @param path [String] the path of the current request context.
|
40
|
+
#
|
41
|
+
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
42
|
+
def new_ia_result rule_id, input_type, path, value = nil
|
43
|
+
res = Contrast::Agent::Reporting::InputAnalysisResult.new
|
44
|
+
res.rule_id = rule_id
|
45
|
+
res.input_type = input_type
|
46
|
+
res.path = path
|
47
|
+
res.value = value
|
48
|
+
res
|
49
|
+
end
|
50
|
+
|
51
|
+
# This methods checks if input is value that matches a key in the input.
|
52
|
+
#
|
53
|
+
# @param request [Contrast::Agent::Request] the current request context.
|
54
|
+
# @param result [Contrast::Agent::Reporting::InputAnalysisResult] result to be updated.
|
55
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
56
|
+
# @param value [String, Array<String>] the value of the input.
|
57
|
+
#
|
58
|
+
# @return result [Contrast::Agent::Reporting::InputAnalysisResult] updated with key result.
|
59
|
+
def add_needed_key request, result, input_type, value
|
60
|
+
case input_type
|
61
|
+
when COOKIE_VALUE
|
62
|
+
result.key = request.cookies.key(value)
|
63
|
+
when PARAMETER_VALUE
|
64
|
+
result.key = request.parameters.key(value)
|
65
|
+
else
|
66
|
+
result.key
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -50,10 +50,10 @@ module Contrast
|
|
50
50
|
new_preflight_message.data = "#{ rule_id },#{ hash_code }"
|
51
51
|
new_preflight.messages << new_preflight_message
|
52
52
|
|
53
|
-
ruby_finding = Contrast::Agent::Reporting::Finding.new
|
53
|
+
ruby_finding = Contrast::Agent::Reporting::Finding.new(rule_id)
|
54
54
|
ruby_finding.hash_code = hash_code
|
55
55
|
set_new_finding_properties(ruby_finding, user_provided_options, call_location)
|
56
|
-
Contrast::Agent.reporter&.
|
56
|
+
Contrast::Agent.reporter&.send_event(new_preflight)
|
57
57
|
Contrast::Agent::Reporting::ReportingStorage[hash_code] = ruby_finding
|
58
58
|
end
|
59
59
|
|