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
@@ -7,7 +7,6 @@ require 'fileutils'
|
|
7
7
|
require 'contrast/config'
|
8
8
|
require 'contrast/utils/object_share'
|
9
9
|
require 'contrast/components/scope'
|
10
|
-
require 'contrast/utils/exclude_key'
|
11
10
|
|
12
11
|
module Contrast
|
13
12
|
# This is how we read in the local settings for the Agent, both ENV/ CMD line
|
@@ -27,15 +26,17 @@ module Contrast
|
|
27
26
|
MILLISECOND_MARKER = '_ms'
|
28
27
|
CONVERSION = { 'agent.service.enable' => 'agent.start_bundled_service' }.cs__freeze
|
29
28
|
CONFIG_BASE_PATHS = ['', 'config/', '/etc/contrast/ruby/', '/etc/contrast/', '/etc/'].cs__freeze
|
29
|
+
KEYS_TO_REDACT = %i[api_key url service_key user_name].cs__freeze
|
30
|
+
REDACTED = '**REDACTED**'
|
30
31
|
|
31
32
|
def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH
|
32
33
|
@default_name = default_name
|
33
34
|
|
34
35
|
# Load config_kv from file
|
35
|
-
config_kv =
|
36
|
+
config_kv = deep_symbolize_all_keys(load_config)
|
36
37
|
|
37
38
|
# Overlay CLI options - they take precedence over config file
|
38
|
-
cli_options =
|
39
|
+
cli_options = deep_symbolize_all_keys(cli_options)
|
39
40
|
config_kv = deep_merge(cli_options, config_kv) if cli_options
|
40
41
|
|
41
42
|
# Some in-flight rewrites to maintain backwards compatibility
|
@@ -93,7 +94,7 @@ module Contrast
|
|
93
94
|
rescue Psych::Exception => e
|
94
95
|
log_yaml_parse_error(path, e)
|
95
96
|
rescue RuntimeError => e
|
96
|
-
puts
|
97
|
+
puts("WARN: Unable to load configuration. #{ e }; path: #{ path }, pwd: #{ Dir.pwd }")
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
@@ -105,7 +106,7 @@ module Contrast
|
|
105
106
|
def update_prop_keys config
|
106
107
|
CONVERSION.each_pair do |old_method, new_method|
|
107
108
|
# See if the old value was set and needs to be translated
|
108
|
-
deprecated_keys = old_method.split('.')
|
109
|
+
deprecated_keys = old_method.split('.').map(&:to_sym)
|
109
110
|
old_value = config
|
110
111
|
deprecated_keys.each do |key|
|
111
112
|
old_value = old_value[key]
|
@@ -114,7 +115,7 @@ module Contrast
|
|
114
115
|
next if old_value.nil? # have to account for literal false
|
115
116
|
|
116
117
|
log_deprecated_property(old_method, new_method)
|
117
|
-
new_keys = new_method.split('.')
|
118
|
+
new_keys = new_method.split('.').map(&:to_sym)
|
118
119
|
# We changed the seconds values into ms values. Multiply them accordingly
|
119
120
|
old_value = old_value.to_i * 1000 if new_method.end_with?(MILLISECOND_MARKER)
|
120
121
|
new_value = config
|
@@ -147,12 +148,12 @@ module Contrast
|
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
150
|
-
def
|
151
|
+
def deep_symbolize_all_keys hash
|
151
152
|
return if hash.nil?
|
152
153
|
|
153
154
|
new_hash = {}
|
154
155
|
hash.each do |key, value|
|
155
|
-
new_hash[key.
|
156
|
+
new_hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize_all_keys(value) : value
|
156
157
|
end
|
157
158
|
new_hash
|
158
159
|
end
|
@@ -181,7 +182,7 @@ module Contrast
|
|
181
182
|
if logger
|
182
183
|
logger.warn('YAML validator found an error', hash)
|
183
184
|
else
|
184
|
-
puts
|
185
|
+
puts("CONTRAST - WARN: YAML validator found an error. #{ hash.inspect }")
|
185
186
|
end
|
186
187
|
end
|
187
188
|
|
@@ -189,7 +190,7 @@ module Contrast
|
|
189
190
|
if logger
|
190
191
|
logger.warn('Configuration file is not readable by current user', path: path)
|
191
192
|
else
|
192
|
-
puts
|
193
|
+
puts("CONTRAST - WARN: Configuration file is not readable by current user; path: #{ path }")
|
193
194
|
end
|
194
195
|
end
|
195
196
|
|
@@ -197,7 +198,7 @@ module Contrast
|
|
197
198
|
if logger
|
198
199
|
logger.warn('Deprecated property in use', old_method: old_method, new_method: new_method)
|
199
200
|
else
|
200
|
-
puts
|
201
|
+
puts("CONTRAST - WARN: Deprecated property in use; old_method: #{ old_method }, new_method: #{ new_method }")
|
201
202
|
end
|
202
203
|
end
|
203
204
|
|
@@ -219,11 +220,9 @@ module Contrast
|
|
219
220
|
when Contrast::Config::BaseConfiguration
|
220
221
|
# to_hash returns @configuration_map
|
221
222
|
convert.to_hash.each_key do |key|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
# clean_key = key.to_s.tr('-', '_')
|
226
|
-
hash[key] = convert_to_hash(convert.send(key.to_sym), {})
|
223
|
+
# change '-' to '_' for ProtectRulesConfiguration
|
224
|
+
hash[key] = convert_to_hash(convert.send(key.tr('-', '_').to_sym), {})
|
225
|
+
hash[key] = REDACTED if redactable?(key)
|
227
226
|
end
|
228
227
|
hash
|
229
228
|
else
|
@@ -235,7 +234,7 @@ module Contrast
|
|
235
234
|
idx = 0
|
236
235
|
end_idx = new_keys.length - 1
|
237
236
|
while idx < new_keys.length
|
238
|
-
new_key = new_keys[idx]
|
237
|
+
new_key = new_keys[idx].to_sym
|
239
238
|
if idx == end_idx
|
240
239
|
new_value[new_key] = old_value if new_value[new_key].nil?
|
241
240
|
else
|
@@ -246,5 +245,14 @@ module Contrast
|
|
246
245
|
idx += 1
|
247
246
|
end
|
248
247
|
end
|
248
|
+
|
249
|
+
# Check if keys with sensitive data needs to be
|
250
|
+
# redacted.
|
251
|
+
#
|
252
|
+
# @param key [Symbol] key to check
|
253
|
+
# @return[Boolean] true | false
|
254
|
+
def redactable? key
|
255
|
+
KEYS_TO_REDACT.include?(key.to_sym)
|
256
|
+
end
|
249
257
|
end
|
250
258
|
end
|
@@ -53,7 +53,7 @@ module Contrast
|
|
53
53
|
return ret unless Contrast::Agent::Assess::Tracker.tracked?(ret)
|
54
54
|
|
55
55
|
properties.cleanup_tags
|
56
|
-
event_data = Contrast::Agent::Assess::Events::EventData.new
|
56
|
+
event_data = Contrast::Agent::Assess::Events::EventData.new(ARRAY_JOIN_NODE, ret, ary, ret, [separator])
|
57
57
|
properties.build_event(event_data)
|
58
58
|
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
59
59
|
ret
|
@@ -20,7 +20,7 @@ module ERBPropagator
|
|
20
20
|
|
21
21
|
erb_pre_result = preshift.object.src
|
22
22
|
parent_events = []
|
23
|
-
binding_variable_set
|
23
|
+
binding_variable_set(binding_variable_set, used_binding, erb_pre_result, properties, parent_events, ret)
|
24
24
|
properties.build_event(Contrast::Agent::Assess::Events::EventData.new(patcher,
|
25
25
|
ret,
|
26
26
|
preshift.object,
|
@@ -43,7 +43,7 @@ module Contrast
|
|
43
43
|
properties.copy_from(source, ret)
|
44
44
|
|
45
45
|
node = Contrast::Agent::Assess::Policy::Policy.instance.find_propagator_node('Marshal', :load, false)
|
46
|
-
event_data = Contrast::Agent::Assess::Events::EventData.new
|
46
|
+
event_data = Contrast::Agent::Assess::Events::EventData.new(node, ret, self, ret, args)
|
47
47
|
properties.build_event(event_data)
|
48
48
|
rescue StandardError => e
|
49
49
|
logger.error('Unable to run Assess for Marshal.load', e)
|
@@ -13,7 +13,7 @@ module Contrast
|
|
13
13
|
# methods which are too complex to fit into one of the standard
|
14
14
|
# Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
|
15
15
|
# String Class or exposing our methods there.
|
16
|
-
class StringPropagator
|
16
|
+
class StringPropagator
|
17
17
|
extend Contrast::Components::Logger::InstanceMethods
|
18
18
|
extend Contrast::Components::Scope::InstanceMethods
|
19
19
|
|
@@ -43,6 +43,7 @@ module Contrast
|
|
43
43
|
offset = 0
|
44
44
|
inputs.each do |input|
|
45
45
|
properties.copy_from(input, result, offset)
|
46
|
+
add_dynamic_sources_info(input, result)
|
46
47
|
offset += input.length
|
47
48
|
parent_event = Contrast::Agent::Assess::Tracker.properties(input)&.event
|
48
49
|
parent_events << parent_event if parent_event
|
@@ -58,6 +59,24 @@ module Contrast
|
|
58
59
|
rescue StandardError => e
|
59
60
|
logger.error('Unable to track interpolation', e)
|
60
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
# When there is a string interpolation on input coming from tainted database,
|
66
|
+
# the Contrast::Agent::Assess::Properties::Updated.copy_from method won't copy
|
67
|
+
# the dynamic source properties needed in the build findings from TS to display
|
68
|
+
# the column and Table information as database source information.
|
69
|
+
#
|
70
|
+
# @param source [Object] the source object with the required properties.
|
71
|
+
# @param target [Object] the result form the interpolation and the object
|
72
|
+
# that needs to keep the source properties, in order to be reporter on
|
73
|
+
# trigger event.
|
74
|
+
# @return updated_properties [Hash<DynamicSourceInfo>, nil]
|
75
|
+
def add_dynamic_sources_info source, target
|
76
|
+
return unless (dynamic_props = Contrast::Agent::Assess::Tracker.properties(source)&.properties)
|
77
|
+
|
78
|
+
Contrast::Agent::Assess::Tracker.properties(target)&.add_properties(dynamic_props)
|
79
|
+
end
|
61
80
|
end
|
62
81
|
end
|
63
82
|
end
|
@@ -7,19 +7,19 @@ module Contrast
|
|
7
7
|
module BaseSupport
|
8
8
|
# The top level module name used by the framework
|
9
9
|
def detection_class
|
10
|
-
raise
|
10
|
+
raise(NoMethodError('Subclasses of BaseSupport should implement this method'))
|
11
11
|
end
|
12
12
|
|
13
13
|
def version
|
14
|
-
raise
|
14
|
+
raise(NoMethodError('Subclasses of BaseSupport should implement this method'))
|
15
15
|
end
|
16
16
|
|
17
17
|
def application_name
|
18
|
-
raise
|
18
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
19
19
|
end
|
20
20
|
|
21
21
|
def server_type
|
22
|
-
raise
|
22
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
23
23
|
end
|
24
24
|
|
25
25
|
# Find all the predefined routes for this application and append them to the
|
@@ -27,19 +27,19 @@ module Contrast
|
|
27
27
|
# msg should be a Contrast::Api::Dtm::ApplicationUpdate or some other msg
|
28
28
|
# that has a routes array consisting of Contrast::Api::Dtm::RouteCoverage
|
29
29
|
def collect_routes
|
30
|
-
raise
|
30
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
31
31
|
end
|
32
32
|
|
33
33
|
def current_route_coverage
|
34
|
-
raise
|
34
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
35
35
|
end
|
36
36
|
|
37
37
|
def current_route
|
38
|
-
raise
|
38
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
39
39
|
end
|
40
40
|
|
41
41
|
def retrieve_request _env
|
42
|
-
raise
|
42
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
43
43
|
end
|
44
44
|
|
45
45
|
# Some Frameworks require specific patching for their classes to handle
|
@@ -112,7 +112,7 @@ module Contrast
|
|
112
112
|
full_route ||= request.env[::Rack::PATH_INFO]
|
113
113
|
|
114
114
|
new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
|
115
|
-
new_route_coverage.attach_rack_based_data
|
115
|
+
new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
|
116
116
|
end
|
117
117
|
|
118
118
|
# Search object space for grape controllers--any class that subclasses ::Grape::API.
|
@@ -151,7 +151,7 @@ module Contrast
|
|
151
151
|
# Grape controller actually has endpoints and each endpoint
|
152
152
|
# has routes and that's why we need to do it that way
|
153
153
|
controller = controllers.pop
|
154
|
-
return _route_recurse
|
154
|
+
return _route_recurse(method, route, controllers) unless controller
|
155
155
|
|
156
156
|
contr_routes = controller.endpoints&.map(&:routes)&.flatten || []
|
157
157
|
route_pattern = contr_routes&.find do |r|
|
@@ -159,7 +159,7 @@ module Contrast
|
|
159
159
|
end
|
160
160
|
return controller, route_pattern unless route_pattern.nil?
|
161
161
|
|
162
|
-
_route_recurse
|
162
|
+
_route_recurse(method, route, controllers)
|
163
163
|
end
|
164
164
|
|
165
165
|
# Get route and do some cleaning
|
@@ -64,25 +64,25 @@ module Contrast
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def platform_version
|
67
|
-
framework_version = first_framework_result
|
67
|
+
framework_version = first_framework_result(:version, '')
|
68
68
|
|
69
69
|
Contrast::Framework::PlatformVersion.from_string(framework_version)
|
70
70
|
end
|
71
71
|
|
72
72
|
def platform_version_string
|
73
|
-
first_framework_result
|
73
|
+
first_framework_result(:version, '')
|
74
74
|
end
|
75
75
|
|
76
76
|
def server_type
|
77
|
-
first_framework_result
|
77
|
+
first_framework_result(:server_type, 'rack')
|
78
78
|
end
|
79
79
|
|
80
80
|
def app_name
|
81
|
-
first_framework_result
|
81
|
+
first_framework_result(:application_name, 'root')
|
82
82
|
end
|
83
83
|
|
84
84
|
def app_root
|
85
|
-
found = first_framework_result
|
85
|
+
found = first_framework_result(:application_root, nil)
|
86
86
|
found || ::Rack::Directory.new('').root
|
87
87
|
end
|
88
88
|
|
@@ -125,7 +125,7 @@ module Contrast
|
|
125
125
|
# @return [Contrast::Api::Dtm::RouteCoverage] the current route as a Dtm.
|
126
126
|
def get_route_dtm request
|
127
127
|
@_frameworks.lazy.map { |framework_support| framework_support.current_route(request) }.
|
128
|
-
reject(&:nil?).first
|
128
|
+
reject(&:nil?).first # rubocop:disable Style/CollectionCompact
|
129
129
|
end
|
130
130
|
|
131
131
|
# Iterate through current frameworks and return the current request's route. This will be the first non-nil
|
@@ -135,7 +135,7 @@ module Contrast
|
|
135
135
|
# @return [Contrast::Agent::Reporting::RouteCoverage] the current route as a Dtm.
|
136
136
|
def get_route_information request
|
137
137
|
@_frameworks.lazy.map { |framework_support| framework_support.current_route_coverage(request) }.
|
138
|
-
reject(&:nil?).first
|
138
|
+
reject(&:nil?).first # rubocop:disable Style/CollectionCompact
|
139
139
|
end
|
140
140
|
|
141
141
|
# Sometimes the framework we want to instrument is loaded after our agent code. To catch that case, we'll detect
|
@@ -25,7 +25,7 @@ module Contrast
|
|
25
25
|
def instrument
|
26
26
|
@_instrument ||= begin
|
27
27
|
::Rack::Session::Cookie.class_eval do
|
28
|
-
alias_method
|
28
|
+
alias_method(:cs__patched_initialize, :initialize)
|
29
29
|
def initialize app, options = {} # rubocop:disable Style/OptionHash
|
30
30
|
Contrast::Framework::Rack::Patch::SessionCookie.analyze(options)
|
31
31
|
cs__patched_initialize(app, options)
|
@@ -16,8 +16,19 @@ module Contrast
|
|
16
16
|
def send_messages
|
17
17
|
return unless (context = Contrast::Agent::REQUEST_TRACKER.current)
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
if Contrast::Agent::Reporter.enabled?
|
20
|
+
[
|
21
|
+
context.new_observed_route,
|
22
|
+
Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.server_activity),
|
23
|
+
Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity.library_usages),
|
24
|
+
Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity)
|
25
|
+
].each do |event|
|
26
|
+
Contrast::Agent.reporter&.send_event_immediately(event)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
[context.server_activity, context.activity, context.observed_route].each do |msg|
|
30
|
+
Contrast::Agent.messaging_queue&.send_event_immediately(msg)
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
@@ -27,7 +38,7 @@ module Contrast
|
|
27
38
|
# normally pre->in->post filters are applied however, in a streamed response we can run into a case
|
28
39
|
# where it's pre -> in -> post -> more infilters in order to submit anything found during the
|
29
40
|
# infilters after the response has been written we need to explicitly send them
|
30
|
-
alias_method
|
41
|
+
alias_method(:cs__close, :close)
|
31
42
|
def close
|
32
43
|
Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
|
33
44
|
cs__close
|
@@ -49,7 +49,7 @@ module Contrast
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def apply_session_timeout *args
|
52
|
-
return if ::Contrast::ASSESS.rule_disabled?
|
52
|
+
return if ::Contrast::ASSESS.rule_disabled?(CS__SESSION_TIMEOUT_NAME)
|
53
53
|
return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args,
|
54
54
|
comparison_type: :greater_than, safe_default: false)
|
55
55
|
|
@@ -64,7 +64,7 @@ module Contrast
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def apply_secure_cookie_disabled *args
|
67
|
-
return if ::Contrast::ASSESS.rule_disabled?
|
67
|
+
return if ::Contrast::ASSESS.rule_disabled?(CS__SECURE_RULE_NAME)
|
68
68
|
return unless vulnerable_setting?(:secure, true, args)
|
69
69
|
|
70
70
|
rails_session_settings = args[1]
|
@@ -78,7 +78,7 @@ module Contrast
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def apply_httponly_disabled *args
|
81
|
-
return if ::Contrast::ASSESS.rule_disabled?
|
81
|
+
return if ::Contrast::ASSESS.rule_disabled?(CS__HTTPONLY_RULE_NAME)
|
82
82
|
return unless vulnerable_setting?(:httponly, true, args)
|
83
83
|
|
84
84
|
rails_session_settings = args[1]
|
@@ -14,7 +14,7 @@ module Contrast
|
|
14
14
|
def self.instrument
|
15
15
|
@_instrument ||= begin
|
16
16
|
::Rails::Application::Configuration.class_eval do
|
17
|
-
alias_method
|
17
|
+
alias_method(:cs__patched_session_store, :session_store)
|
18
18
|
def session_store *args, **kwargs
|
19
19
|
ret = cs__patched_session_store(*args, **kwargs)
|
20
20
|
Contrast::Framework::Rails::Patch::AssessConfiguration.analyze_session_store(*args, **kwargs)
|
@@ -20,56 +20,24 @@ module Contrast
|
|
20
20
|
# (i.e., where we normally patch) we will miss the configuration
|
21
21
|
# and will never be able to report session misconfiguration rules.
|
22
22
|
Contrast::Framework::Rails::Patch::RailsApplicationConfiguration.instrument
|
23
|
-
require
|
23
|
+
require('contrast/framework/rails/railtie') if ::Rails::VERSION::MAJOR.to_i >= 3
|
24
24
|
end
|
25
25
|
|
26
26
|
# (See BaseSupport#after_load_patches)
|
27
27
|
def after_load_patches
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
patches.merge(special_after_load_patches) if RUBY_VERSION < '2.6.0'
|
42
|
-
patches
|
43
|
-
end
|
44
|
-
|
45
|
-
def special_after_load_patches
|
46
|
-
[
|
47
|
-
# TODO: RUBY-714 remove w/ EOL of 2.5
|
48
|
-
#
|
49
|
-
# @deprecated Everything past here is used for Rewriting and can
|
50
|
-
# be removed once we no longer support 2.5.
|
51
|
-
Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
|
52
|
-
'ActionController::Railties::Helper::ClassMethods',
|
53
|
-
'contrast/framework/rails/rewrite/action_controller_railties_helper_inherited',
|
54
|
-
method_to_instrument: :inherited,
|
55
|
-
instrumenting_module:
|
56
|
-
'Contrast::Framework::Rails::Rewrite::ActionControllerRailtiesHelperInherited'),
|
57
|
-
Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
|
58
|
-
'ActiveRecord::AttributeMethods::Read::ClassMethods',
|
59
|
-
'contrast/framework/rails/rewrite/active_record_attribute_methods_read',
|
60
|
-
instrumenting_module:
|
61
|
-
'Contrast::Framework::Rails::Rewrite::ActiveRecordAttributeMethodsRead'),
|
62
|
-
Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
|
63
|
-
'ActiveRecord::Scoping::Named::ClassMethods',
|
64
|
-
'contrast/framework/rails/rewrite/active_record_named',
|
65
|
-
instrumenting_module: 'Contrast::Framework::Rails::Rewrite::ActiveRecordNamed'),
|
66
|
-
Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
|
67
|
-
'ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods',
|
68
|
-
'contrast/framework/rails/rewrite/active_record_time_zone_inherited',
|
69
|
-
method_to_instrument: :inherited,
|
70
|
-
instrumenting_module:
|
71
|
-
'Contrast::Framework::Rails::Rewrite::ActiveRecordTimeZoneInherited')
|
72
|
-
]
|
28
|
+
Set.new([
|
29
|
+
Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
|
30
|
+
'ActionController::Live::Buffer',
|
31
|
+
'contrast/framework/rails/patch/action_controller_live_buffer',
|
32
|
+
instrumenting_module:
|
33
|
+
'Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer'),
|
34
|
+
Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
|
35
|
+
'Rails::Application::Configuration',
|
36
|
+
'contrast/framework/rails/patch/rails_application_configuration',
|
37
|
+
method_to_instrument: :session_store,
|
38
|
+
instrumenting_module:
|
39
|
+
'Contrast::Framework::Rails::Patch::RailsApplicationConfiguration')
|
40
|
+
])
|
73
41
|
end
|
74
42
|
end
|
75
43
|
end
|
@@ -104,7 +104,7 @@ module Contrast
|
|
104
104
|
end
|
105
105
|
|
106
106
|
new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
|
107
|
-
new_route_coverage.attach_rails_data
|
107
|
+
new_route_coverage.attach_rails_data(route, original_url)
|
108
108
|
rescue StandardError => e
|
109
109
|
logger.warn('Unable to determine the current route of this request', e)
|
110
110
|
nil
|
@@ -153,7 +153,7 @@ module Contrast
|
|
153
153
|
# If the current routing node points to a sub-app (::Rais::Engine), dive deeper.
|
154
154
|
# Have sub-app route the remainder of the url.
|
155
155
|
if engine_route?(route)
|
156
|
-
new_req = retrieve_request
|
156
|
+
new_req = retrieve_request(request.env)
|
157
157
|
new_req.path_info = new_req.path_info.gsub(match.to_s, '')
|
158
158
|
get_full_route(new_req, route.app.app.routes.router, path << match.to_s)
|
159
159
|
else
|
@@ -101,7 +101,7 @@ module Contrast
|
|
101
101
|
full_route ||= request.env[::Rack::PATH_INFO]
|
102
102
|
|
103
103
|
new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
|
104
|
-
new_route_coverage.attach_rack_based_data
|
104
|
+
new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
|
105
105
|
end
|
106
106
|
|
107
107
|
# Search object space for sinatra controllers--any class that subclasses ::Sinatra::Base.
|
@@ -0,0 +1,94 @@
|
|
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/agent/telemetry/events/exceptions/telemetry_exceptions'
|
5
|
+
require 'contrast/agent/telemetry/events/exceptions/obfuscate'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Logger
|
9
|
+
# Our decorator for the Ougai logger allowing for the catching, creating and saving Telemetry exceptions
|
10
|
+
module AliasedLogging
|
11
|
+
ALIASED_WARN = 'warn'.cs__freeze
|
12
|
+
ALIASED_ERROR = 'error'.cs__freeze
|
13
|
+
ALIASED_FATAL = 'fatal'.cs__freeze
|
14
|
+
|
15
|
+
# @param message [String] The message to log. Use default_message if not specified.
|
16
|
+
# @param exception [Exception] The exception or the error
|
17
|
+
# @param data [Object] Any structured data
|
18
|
+
def warn message = nil, exception = nil, data = nil, &block
|
19
|
+
# build Telemetry Exclusion
|
20
|
+
build_exclusion(ALIASED_WARN, message, exception, data)
|
21
|
+
super(message, exception, data, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param message [String] The message to log. Use default_message if not specified.
|
25
|
+
# @param exception [Exception] The exception or the error
|
26
|
+
# @param data [Object] Any structured data
|
27
|
+
def error message = nil, exception = nil, data = nil, &block
|
28
|
+
# build Telemetry Exclusion
|
29
|
+
build_exclusion(ALIASED_ERROR, message, exception, data)
|
30
|
+
super(message, exception, data, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param message [String] The message to log. Use default_message if not specified.
|
34
|
+
# @param exception [Exception] The exception or the error
|
35
|
+
# @param data [Object] Any structured data
|
36
|
+
def fatal message = nil, exception = nil, data = nil, &block
|
37
|
+
# build Telemetry Exclusion
|
38
|
+
build_exclusion(ALIASED_FATAL, message, exception, data)
|
39
|
+
super(message, exception, data, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def build_exclusion _type, _message = nil, _exception = nil, _data = nil
|
45
|
+
# TODO: RUBY-1698
|
46
|
+
nil
|
47
|
+
# start = caller_locations&.find_index { |stack| stack.to_s.include?(type) }
|
48
|
+
# stack_trace = start ? caller_locations(start + 1, 20) : caller_locations(20, 20)
|
49
|
+
# stack_frame_type = Contrast::Agent::Telemetry::TelemetryException::Obfuscate.obfuscate_type(
|
50
|
+
# stack_trace[1].path.delete_prefix(Dir.pwd))
|
51
|
+
# message_exception_type = Contrast::Agent::Telemetry::TelemetryException::Obfuscate.obfuscate_exception_type(
|
52
|
+
# exception ? exception.cs__class.to_s : stack_frame_type.split('/').last)
|
53
|
+
# stack_frame_function = stack_trace[1].label
|
54
|
+
# key = "#{ stack_frame_type }|#{ stack_frame_function }|#{ message }"
|
55
|
+
# if TELEMETRY_EXCEPTIONS[key]
|
56
|
+
# TELEMETRY_EXCEPTIONS.increment(key)
|
57
|
+
# return
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# event_message = create_message(stack_frame_function,
|
61
|
+
# stack_frame_type, message_exception_type,
|
62
|
+
# data, exception,
|
63
|
+
# message)
|
64
|
+
# TELEMETRY_EXCEPTIONS[key] = event_message
|
65
|
+
# rescue StandardError => e
|
66
|
+
# debug('Unable to report exception to telemetry', e)
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_message stack_frame_function, stack_frame_type, message_exception_type, data, exception, message
|
70
|
+
message_for_exception = if exception
|
71
|
+
exception.cs__respond_to?(:message) ? exception.message : exception
|
72
|
+
else
|
73
|
+
message
|
74
|
+
end
|
75
|
+
module_name = message_exception_type ? message_exception_type.split('::')[0] : nil
|
76
|
+
stack_frame = Contrast::Agent::Telemetry::TelemetryException::StackFrame.build(stack_frame_function,
|
77
|
+
stack_frame_type,
|
78
|
+
module_name)
|
79
|
+
message_exception = Contrast::Agent::Telemetry::TelemetryException::MessageException.build(
|
80
|
+
message_exception_type,
|
81
|
+
message_for_exception,
|
82
|
+
module_name,
|
83
|
+
stack_frame)
|
84
|
+
tags = if data
|
85
|
+
data
|
86
|
+
else
|
87
|
+
exception.cs__is_a?(Hash) ? exception : {}
|
88
|
+
end
|
89
|
+
message = Contrast::Agent::Telemetry::TelemetryException::Message.build(tags, [message_exception])
|
90
|
+
Contrast::Agent::Telemetry::TelemetryException::Event.new(message)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|