contrast-agent 6.1.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -1
- data/Rakefile +1 -1
- data/ext/build_funchook.rb +3 -3
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -1
- data/ext/extconf_common.rb +1 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +2 -2
- data/lib/contrast/agent/assess/policy/policy.rb +9 -10
- data/lib/contrast/agent/assess/policy/policy_node.rb +9 -10
- data/lib/contrast/agent/assess/policy/propagation_method.rb +3 -3
- 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 +2 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/split.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +7 -7
- 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 +2 -2
- 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 +5 -5
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +2 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +8 -9
- 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/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 +13 -1
- data/lib/contrast/agent/inventory/database_config.rb +12 -4
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +9 -5
- data/lib/contrast/agent/middleware.rb +6 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
- 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 +9 -9
- data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
- data/lib/contrast/agent/patching/policy/policy.rb +13 -15
- data/lib/contrast/agent/patching/policy/policy_node.rb +19 -21
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +125 -125
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +1 -1
- 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 +30 -18
- data/lib/contrast/agent/protect/rule/base_service.rb +31 -14
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +16 -9
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +3 -3
- 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 +74 -74
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +71 -53
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +3 -3
- data/lib/contrast/agent/protect/rule/no_sqli.rb +15 -16
- data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -2
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -1
- 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 +61 -61
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +29 -29
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +32 -32
- data/lib/contrast/agent/protect/rule/xss.rb +21 -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/rasp_rule_sample.rb +36 -36
- data/lib/contrast/agent/reporting/masker/masker.rb +10 -10
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +2 -2
- data/lib/contrast/agent/reporting/reporter.rb +2 -11
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +8 -10
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +53 -5
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +25 -19
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +129 -17
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +20 -21
- 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 +26 -12
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -22
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +7 -5
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +4 -10
- data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +75 -15
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -19
- data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -22
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -3
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +1 -3
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +9 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +0 -10
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +6 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +61 -3
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +33 -11
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +8 -8
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +64 -32
- data/lib/contrast/agent/reporting/settings/application_settings.rb +8 -23
- data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +28 -34
- data/lib/contrast/agent/reporting/settings/bot_blocker.rb +68 -0
- data/lib/contrast/agent/reporting/settings/code_exclusion.rb +27 -0
- data/lib/contrast/agent/reporting/settings/exclusion_base.rb +33 -0
- data/lib/contrast/agent/reporting/settings/exclusions.rb +39 -57
- data/lib/contrast/agent/reporting/settings/helpers.rb +56 -0
- data/lib/contrast/agent/reporting/settings/input_exclusion.rb +37 -0
- data/lib/contrast/agent/reporting/settings/ip_filter.rb +35 -0
- data/lib/contrast/agent/reporting/settings/keyword.rb +74 -0
- data/lib/contrast/agent/reporting/settings/log_enhancer.rb +65 -0
- data/lib/contrast/agent/reporting/settings/protect.rb +22 -5
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +62 -115
- data/lib/contrast/agent/reporting/settings/reaction.rb +13 -4
- data/lib/contrast/agent/reporting/settings/rule_definition.rb +63 -0
- data/lib/contrast/agent/reporting/settings/sampling.rb +10 -0
- data/lib/contrast/agent/reporting/settings/sanitizer.rb +38 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +11 -3
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +9 -2
- data/lib/contrast/agent/reporting/settings/server_features.rb +10 -2
- data/lib/contrast/agent/reporting/settings/syslog.rb +176 -0
- data/lib/contrast/agent/reporting/settings/url_exclusion.rb +42 -0
- data/lib/contrast/agent/reporting/settings/validator.rb +17 -0
- data/lib/contrast/agent/request.rb +2 -2
- data/lib/contrast/agent/request_context.rb +27 -19
- data/lib/contrast/agent/request_context_extend.rb +10 -23
- data/lib/contrast/agent/request_handler.rb +9 -5
- data/lib/contrast/agent/rule_set.rb +2 -2
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/static_analysis.rb +4 -8
- data/lib/contrast/agent/telemetry/base.rb +9 -5
- data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +2 -2
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +1 -1
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +1 -1
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +16 -18
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +2 -2
- data/lib/contrast/agent/thread_watcher.rb +4 -5
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +1 -3
- data/lib/contrast/api/communication/messaging_queue.rb +1 -1
- 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 +2 -2
- 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/application_update.rb +0 -8
- data/lib/contrast/api/decorators/response_type.rb +4 -17
- data/lib/contrast/api/decorators.rb +0 -1
- data/lib/contrast/components/agent.rb +1 -1
- data/lib/contrast/components/base.rb +1 -1
- data/lib/contrast/components/config.rb +6 -6
- data/lib/contrast/components/contrast_service.rb +4 -1
- data/lib/contrast/components/sampling.rb +1 -1
- data/lib/contrast/components/settings.rb +52 -28
- data/lib/contrast/config/assess_rules_configuration.rb +1 -1
- data/lib/contrast/config/protect_rules_configuration.rb +1 -1
- data/lib/contrast/config/root_configuration.rb +1 -1
- data/lib/contrast/configuration.rb +4 -4
- 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 +1 -1
- data/lib/contrast/extension/extension.rb +2 -2
- data/lib/contrast/framework/base_support.rb +13 -12
- data/lib/contrast/framework/grape/support.rb +9 -9
- data/lib/contrast/framework/manager.rb +7 -9
- data/lib/contrast/framework/manager_extend.rb +2 -1
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +15 -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 +1 -1
- data/lib/contrast/framework/rails/support.rb +11 -4
- data/lib/contrast/framework/sinatra/support.rb +4 -3
- data/lib/contrast/logger/aliased_logging.rb +27 -15
- data/lib/contrast/logger/cef_log.rb +14 -14
- data/lib/contrast/logger/format.rb +1 -1
- data/lib/contrast/logger/log.rb +8 -8
- data/lib/contrast/tasks/config.rb +12 -12
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/tracking_util.rb +4 -4
- data/lib/contrast/utils/class_util.rb +4 -4
- 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/invalid_configuration_util.rb +1 -1
- data/lib/contrast/utils/log_utils.rb +4 -4
- 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 +5 -5
- data/lib/contrast/utils/net_http_base.rb +4 -4
- data/lib/contrast/utils/os.rb +1 -1
- data/lib/contrast/utils/patching/policy/patch_utils.rb +2 -2
- data/lib/contrast/utils/request_utils.rb +2 -2
- data/lib/contrast/utils/response_utils.rb +14 -1
- 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 +15 -9
- data/lib/contrast/utils/telemetry_client.rb +5 -5
- data/lib/contrast/utils/telemetry_hash.rb +37 -13
- data/lib/contrast/utils/telemetry_identifier.rb +10 -2
- data/lib/contrast/utils/thread_tracker.rb +26 -9
- data/lib/contrast/utils/timer.rb +7 -2
- data/lib/contrast.rb +1 -3
- data/resources/assess/policy.json +1 -1
- metadata +28 -14
- data/lib/contrast/api/decorators/library_usage_update.rb +0 -31
@@ -28,6 +28,12 @@ module Contrast
|
|
28
28
|
CONTRAST_NAME = 'Contrast Agent'
|
29
29
|
|
30
30
|
class Interface # :nodoc:
|
31
|
+
SESSION_VARIABLES = 'Invalid configuration. '\
|
32
|
+
"Setting both application.session_id and application.session_metadata is not allowed.\n"
|
33
|
+
API_URL = "Invalid configuration. Missing a required connection value 'url' is not set."
|
34
|
+
API_KEY = "Invalid configuration. Missing a required connection value 'api_key' is not set."
|
35
|
+
API_SERVICE_KEY = "Invalid configuration. Missing a required connection value 'service_tag' is not set."
|
36
|
+
API_USERNAME = "Invalid configuration. Missing a required connection value 'user_name' is not set."
|
31
37
|
def initialize
|
32
38
|
build
|
33
39
|
end
|
@@ -87,12 +93,6 @@ module Contrast
|
|
87
93
|
|
88
94
|
private
|
89
95
|
|
90
|
-
SESSION_VARIABLES = 'Invalid configuration. '\
|
91
|
-
"Setting both application.session_id and application.session_metadata is not allowed.\n"
|
92
|
-
API_URL = "Invalid configuration. Missing a required connection value 'url' is not set."
|
93
|
-
API_KEY = "Invalid configuration. Missing a required connection value 'api_key' is not set."
|
94
|
-
API_SERVICE_KEY = "Invalid configuration. Missing a required connection value 'service_tag' is not set."
|
95
|
-
API_USERNAME = "Invalid configuration. Missing a required connection value 'user_name' is not set."
|
96
96
|
# The config has information about how to construct the logger. If the config is invalid, and you want to know
|
97
97
|
# about it, then you have a circular dependency if you try to log it, so we use basic proto_logger to do this
|
98
98
|
# job.
|
@@ -18,7 +18,10 @@ module Contrast
|
|
18
18
|
DEFAULT_SERVICE_LEVEL = :TRACE
|
19
19
|
# The Rails ActionDispatch regexp for localhost IP + literal localhost
|
20
20
|
# https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb#L32
|
21
|
-
LOCALHOST = Regexp.union
|
21
|
+
LOCALHOST = Regexp.union([
|
22
|
+
/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/,
|
23
|
+
/^localhost$/
|
24
|
+
])
|
22
25
|
|
23
26
|
def use_bundled_service?
|
24
27
|
# Validates the config to decide if it's suitable for starting
|
@@ -25,7 +25,7 @@ module Contrast
|
|
25
25
|
def sampling_control
|
26
26
|
@_sampling_control ||= begin
|
27
27
|
config_settings = ::Contrast::CONFIG.root.assess&.sampling
|
28
|
-
settings = ::Contrast::SETTINGS&.assess_state&.
|
28
|
+
settings = ::Contrast::SETTINGS&.assess_state&.sampling_settings
|
29
29
|
{
|
30
30
|
enabled: enabled?(config_settings, settings),
|
31
31
|
baseline: baseline(config_settings, settings),
|
@@ -99,43 +99,29 @@ module Contrast
|
|
99
99
|
@application_state.exclusion_matchers.select(&:code?)
|
100
100
|
end
|
101
101
|
|
102
|
-
# @param
|
103
|
-
def update_from_server_features
|
104
|
-
if
|
105
|
-
|
106
|
-
return unless server_features
|
107
|
-
|
108
|
-
log_file = server_features.log_file
|
109
|
-
log_level = server_features.log_level
|
110
|
-
Contrast::Logger::Log.instance.update(log_file, log_level) if log_file || log_level
|
111
|
-
@protect_state.enabled = server_features.protect.enabled?
|
112
|
-
@assess_state.enabled = server_features.assess.enabled?
|
113
|
-
@assess_state.sampling_settings = server_features.assess.sampling
|
102
|
+
# @param features_response [Contrast::Api::Settings::ServerFeatures, Contrast::Agent::Reporting::Response]
|
103
|
+
def update_from_server_features features_response
|
104
|
+
if features_response.cs__is_a?(Contrast::Agent::Reporting::Response)
|
105
|
+
update_from_response(features_response)
|
114
106
|
else
|
115
|
-
@protect_state.enabled =
|
116
|
-
@assess_state.enabled =
|
117
|
-
@assess_state.sampling_settings =
|
107
|
+
@protect_state.enabled = features_response.protect_enabled?
|
108
|
+
@assess_state.enabled = features_response.assess_enabled?
|
109
|
+
@assess_state.sampling_settings = features_response.assess.sampling
|
110
|
+
@last_server_update_ms = Contrast::Utils::Timer.now_ms
|
118
111
|
end
|
119
112
|
@last_server_update_ms = Contrast::Utils::Timer.now_ms
|
120
113
|
end
|
121
114
|
|
122
|
-
# @param
|
123
|
-
def update_from_application_settings
|
124
|
-
if
|
125
|
-
|
126
|
-
return unless settings
|
127
|
-
|
128
|
-
@application_state.modes_by_id = settings.protect.protection_rules_to_settings_hash
|
129
|
-
# TODO: RUBY-1438 this needs to be translated
|
130
|
-
# @application_state.exclusion_matchers = new_vals[:exclusion_matchers]
|
131
|
-
update_sensitive_data_policy(settings.sensitive_data_masking)
|
132
|
-
@assess_state.disabled_assess_rules = settings.assess.disabled_rules
|
133
|
-
@assess_state.session_id = settings.assess.session_id if settings.assess.session_id
|
115
|
+
# @param settings_response [Contrast::Api::Settings::ApplicationSettings, Contrast::Agent::Reporting::Response]
|
116
|
+
def update_from_application_settings settings_response
|
117
|
+
if settings_response&.cs__class == Contrast::Agent::Reporting::Response
|
118
|
+
update_from_response(settings_response)
|
134
119
|
else
|
135
|
-
new_vals =
|
120
|
+
new_vals = settings_response.application_state_translation
|
136
121
|
@application_state.modes_by_id = new_vals[:modes_by_id]
|
137
122
|
@application_state.exclusion_matchers = new_vals[:exclusion_matchers]
|
138
123
|
@assess_state.disabled_assess_rules = new_vals[:disabled_assess_rules]
|
124
|
+
@last_app_update_ms = Contrast::Utils::Timer.now_ms
|
139
125
|
end
|
140
126
|
@last_app_update_ms = Contrast::Utils::Timer.now_ms
|
141
127
|
end
|
@@ -184,6 +170,44 @@ module Contrast
|
|
184
170
|
|
185
171
|
private
|
186
172
|
|
173
|
+
# @param response [Contrast::Agent::Reporting::Response]
|
174
|
+
def update_from_response response
|
175
|
+
if (server_features = response.server_features)
|
176
|
+
update_server_features(server_features)
|
177
|
+
end
|
178
|
+
return unless (app_settings = response.application_settings)
|
179
|
+
|
180
|
+
update_application_settings(app_settings)
|
181
|
+
end
|
182
|
+
|
183
|
+
# @param server_features [Contrast::Agent::Reporting::Settings::FeatureSettings]
|
184
|
+
def update_server_features server_features
|
185
|
+
return unless server_features
|
186
|
+
|
187
|
+
log_file = server_features.log_file
|
188
|
+
log_level = server_features.log_level
|
189
|
+
Contrast::Logger::Log.instance.update(log_file, log_level) if log_file || log_level
|
190
|
+
@protect_state.enabled = server_features.protect.enabled?
|
191
|
+
@assess_state.enabled = server_features.assess.enabled?
|
192
|
+
@assess_state.sampling_settings = server_features.assess.sampling
|
193
|
+
@last_server_update_ms = Contrast::Utils::Timer.now_ms
|
194
|
+
end
|
195
|
+
|
196
|
+
# @param app_settings [Contrast::Agent::Reporting::Settings::ApplicationSettings]
|
197
|
+
def update_application_settings app_settings
|
198
|
+
return unless app_settings
|
199
|
+
|
200
|
+
@application_state.modes_by_id = app_settings.protect.protection_rules_to_settings_hash
|
201
|
+
# TODO: RUBY-1438 this needs to be translated
|
202
|
+
# @application_state.exclusion_matchers = new_vals[:exclusion_matchers]
|
203
|
+
update_sensitive_data_policy(app_settings.sensitive_data_masking)
|
204
|
+
@assess_state.disabled_assess_rules = app_settings.assess.disabled_rules
|
205
|
+
if app_settings.assess.session_id && !app_settings.assess.session_id.blank?
|
206
|
+
@assess_state.session_id = app_settings.assess.session_id
|
207
|
+
end
|
208
|
+
@last_app_update_ms = Contrast::Utils::Timer.now_ms
|
209
|
+
end
|
210
|
+
|
187
211
|
# check if settings are empty and return true if so.
|
188
212
|
#
|
189
213
|
# @param settings [String, Boolean, Array, Hash]
|
@@ -11,7 +11,7 @@ module Contrast
|
|
11
11
|
|
12
12
|
attr_accessor :disabled_rules
|
13
13
|
attr_writer :bot_blocker, :cmd_injection, :sql_injection, :nosql_injection, :untrusted_deserialization,
|
14
|
-
:
|
14
|
+
:xxe, :path_traversal, :reflected_xss, :unsafe_file_upload, :rule_base
|
15
15
|
|
16
16
|
BASE_RULE = 'Contrast::Agent::Protect::Rule::Base'.cs__freeze
|
17
17
|
|
@@ -27,7 +27,7 @@ module Contrast
|
|
27
27
|
attr_accessor :enable
|
28
28
|
|
29
29
|
def initialize hsh = {}
|
30
|
-
raise
|
30
|
+
raise(ArgumentError, 'Expected a hash') unless hsh.is_a?(Hash)
|
31
31
|
|
32
32
|
@api = Contrast::Config::ApiConfiguration.new(hsh[:api])
|
33
33
|
@enable = hsh[:enable]
|
@@ -94,7 +94,7 @@ module Contrast
|
|
94
94
|
rescue Psych::Exception => e
|
95
95
|
log_yaml_parse_error(path, e)
|
96
96
|
rescue RuntimeError => e
|
97
|
-
puts
|
97
|
+
puts("WARN: Unable to load configuration. #{ e }; path: #{ path }, pwd: #{ Dir.pwd }")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -182,7 +182,7 @@ module Contrast
|
|
182
182
|
if logger
|
183
183
|
logger.warn('YAML validator found an error', hash)
|
184
184
|
else
|
185
|
-
puts
|
185
|
+
puts("CONTRAST - WARN: YAML validator found an error. #{ hash.inspect }")
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
@@ -190,7 +190,7 @@ module Contrast
|
|
190
190
|
if logger
|
191
191
|
logger.warn('Configuration file is not readable by current user', path: path)
|
192
192
|
else
|
193
|
-
puts
|
193
|
+
puts("CONTRAST - WARN: Configuration file is not readable by current user; path: #{ path }")
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
@@ -198,7 +198,7 @@ module Contrast
|
|
198
198
|
if logger
|
199
199
|
logger.warn('Deprecated property in use', old_method: old_method, new_method: new_method)
|
200
200
|
else
|
201
|
-
puts
|
201
|
+
puts("CONTRAST - WARN: Deprecated property in use; old_method: #{ old_method }, new_method: #{ new_method }")
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
@@ -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)
|
@@ -43,7 +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
|
46
|
+
add_dynamic_sources_info(input, result)
|
47
47
|
offset += input.length
|
48
48
|
parent_event = Contrast::Agent::Assess::Tracker.properties(input)&.event
|
49
49
|
parent_events << parent_event if parent_event
|
@@ -1,45 +1,46 @@
|
|
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/agent/reporting/reporting_events/discovered_route'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Framework
|
6
8
|
# The API for all subclasses to implement to correctly support a given framework
|
7
9
|
module BaseSupport
|
8
10
|
# The top level module name used by the framework
|
9
11
|
def detection_class
|
10
|
-
raise
|
12
|
+
raise(NoMethodError('Subclasses of BaseSupport should implement this method'))
|
11
13
|
end
|
12
14
|
|
13
15
|
def version
|
14
|
-
raise
|
16
|
+
raise(NoMethodError('Subclasses of BaseSupport should implement this method'))
|
15
17
|
end
|
16
18
|
|
17
19
|
def application_name
|
18
|
-
raise
|
20
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
19
21
|
end
|
20
22
|
|
21
23
|
def server_type
|
22
|
-
raise
|
24
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
23
25
|
end
|
24
26
|
|
25
|
-
# Find all the predefined routes for this application
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# that has a routes array consisting of Contrast::Api::Dtm::RouteCoverage
|
27
|
+
# Find all the predefined routes for this application
|
28
|
+
#
|
29
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
29
30
|
def collect_routes
|
30
|
-
raise
|
31
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
31
32
|
end
|
32
33
|
|
33
34
|
def current_route_coverage
|
34
|
-
raise
|
35
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
35
36
|
end
|
36
37
|
|
37
38
|
def current_route
|
38
|
-
raise
|
39
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
39
40
|
end
|
40
41
|
|
41
42
|
def retrieve_request _env
|
42
|
-
raise
|
43
|
+
raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
|
43
44
|
end
|
44
45
|
|
45
46
|
# Some Frameworks require specific patching for their classes to handle
|
@@ -49,7 +49,7 @@ module Contrast
|
|
49
49
|
|
50
50
|
# Find all classes that subclass ::Grape::API, Gather their routes
|
51
51
|
#
|
52
|
-
# @return [Array<Contrast::
|
52
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
53
53
|
def collect_routes
|
54
54
|
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless grape_defined?
|
55
55
|
|
@@ -60,8 +60,8 @@ module Contrast
|
|
60
60
|
c&.endpoints&.each do |endpoint|
|
61
61
|
endpoint&.routes&.map do |r|
|
62
62
|
pattern = r.pattern.pattern
|
63
|
-
|
64
|
-
|
63
|
+
routes << Contrast::Agent::Reporting::DiscoveredRoute.from_grape_controller(c, r.request_method,
|
64
|
+
pattern, r.path)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -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.
|
@@ -140,8 +140,8 @@ module Contrast
|
|
140
140
|
# @param method [::Rack::REQUEST_METHOD] GET, POST, PUT, etc...
|
141
141
|
# @param route [String] the relative route passed from Rack.
|
142
142
|
# @param controllers [Array<::Grape::API>] All Grape controllers found
|
143
|
-
# @return [Array[::Grape::API]
|
144
|
-
#
|
143
|
+
# @return [Array[::Grape::API. Grape::Router::Route], nil] Either the controller that will handle the route
|
144
|
+
# along with the route pattern or nil if no match.
|
145
145
|
def _route_recurse method, route, controllers = grape_controllers
|
146
146
|
# return if there aren't any controllers
|
147
147
|
return unless controllers&.any?
|
@@ -151,15 +151,15 @@ 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|
|
158
|
-
r.pattern.to_regexp.match(route) # ::
|
158
|
+
r.pattern.to_regexp.match(route) # Grape::Router::Route match
|
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
|
@@ -59,30 +59,31 @@ module Contrast
|
|
59
59
|
patches
|
60
60
|
end
|
61
61
|
|
62
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
62
63
|
def find_route_discovery_data
|
63
64
|
routes_for_all_frameworks
|
64
65
|
end
|
65
66
|
|
66
67
|
def platform_version
|
67
|
-
framework_version = first_framework_result
|
68
|
+
framework_version = first_framework_result(:version, '')
|
68
69
|
|
69
70
|
Contrast::Framework::PlatformVersion.from_string(framework_version)
|
70
71
|
end
|
71
72
|
|
72
73
|
def platform_version_string
|
73
|
-
first_framework_result
|
74
|
+
first_framework_result(:version, '')
|
74
75
|
end
|
75
76
|
|
76
77
|
def server_type
|
77
|
-
first_framework_result
|
78
|
+
first_framework_result(:server_type, 'rack')
|
78
79
|
end
|
79
80
|
|
80
81
|
def app_name
|
81
|
-
first_framework_result
|
82
|
+
first_framework_result(:application_name, 'root')
|
82
83
|
end
|
83
84
|
|
84
85
|
def app_root
|
85
|
-
found = first_framework_result
|
86
|
+
found = first_framework_result(:application_root, nil)
|
86
87
|
found || ::Rack::Directory.new('').root
|
87
88
|
end
|
88
89
|
|
@@ -162,13 +163,10 @@ module Contrast
|
|
162
163
|
if Contrast::Agent.reporter
|
163
164
|
report = Contrast::Agent::Reporting::DtmMessage.dtm_to_event(app_update_msg)
|
164
165
|
Contrast::Agent.reporter.send_event(report)
|
165
|
-
|
166
|
-
# This is being reported separately because we extract the data from the same message
|
167
|
-
inventory_report = Contrast::Agent::Reporting::ApplicationInventory.convert(app_update_msg)
|
168
|
-
Contrast::Agent.reporter.send_event(inventory_report)
|
169
166
|
else
|
170
167
|
Contrast::Agent.messaging_queue.send_event_eventually(app_update_msg)
|
171
168
|
end
|
169
|
+
Contrast::Agent.reporter.send_event(Contrast::Agent::Reporting::ApplicationInventory.new)
|
172
170
|
logger.info('Framework detected after initialization. Enabling support.',
|
173
171
|
framework: framework.detection_class,
|
174
172
|
frameworks: @_frameworks)
|
@@ -20,8 +20,9 @@ module Contrast
|
|
20
20
|
Contrast::Utils::ClassUtil.truly_defined?(klass)
|
21
21
|
end
|
22
22
|
|
23
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
23
24
|
def routes_for_all_frameworks
|
24
|
-
data_for_all_frameworks
|
25
|
+
data_for_all_frameworks(:collect_routes)
|
25
26
|
end
|
26
27
|
|
27
28
|
# This returns an array of all data from each framework in a flat, no-nil values array
|
@@ -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,20 @@ 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
|
+
context.observed_library_usage,
|
23
|
+
Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.server_activity),
|
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
|
+
Contrast::Agent.reporter.send_event_immediately(context.observed_library_usage)
|
30
|
+
[context.server_activity, context.activity, context.observed_route].each do |msg|
|
31
|
+
Contrast::Agent.messaging_queue&.send_event_immediately(msg)
|
32
|
+
end
|
21
33
|
end
|
22
34
|
end
|
23
35
|
|
@@ -27,7 +39,7 @@ module Contrast
|
|
27
39
|
# normally pre->in->post filters are applied however, in a streamed response we can run into a case
|
28
40
|
# where it's pre -> in -> post -> more infilters in order to submit anything found during the
|
29
41
|
# infilters after the response has been written we need to explicitly send them
|
30
|
-
alias_method
|
42
|
+
alias_method(:cs__close, :close)
|
31
43
|
def close
|
32
44
|
Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
|
33
45
|
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,7 +20,7 @@ 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)
|
@@ -44,6 +44,7 @@ module Contrast
|
|
44
44
|
'rails'
|
45
45
|
end
|
46
46
|
|
47
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
47
48
|
def collect_routes
|
48
49
|
find_all_routes(::Rails.application, [])
|
49
50
|
end
|
@@ -104,7 +105,7 @@ module Contrast
|
|
104
105
|
end
|
105
106
|
|
106
107
|
new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
|
107
|
-
new_route_coverage.attach_rails_data
|
108
|
+
new_route_coverage.attach_rails_data(route, original_url)
|
108
109
|
rescue StandardError => e
|
109
110
|
logger.warn('Unable to determine the current route of this request', e)
|
110
111
|
nil
|
@@ -138,7 +139,8 @@ module Contrast
|
|
138
139
|
route.app.is_a?(::ActionDispatch::Routing::Mapper::Constraints) && route.app.app < ::Rails::Engine
|
139
140
|
end
|
140
141
|
|
141
|
-
# Recursively get final route traversing engines as required.
|
142
|
+
# Recursively get final route traversing engines as required. Because this can only be called once, we store
|
143
|
+
# this match for the duration of our request context.
|
142
144
|
#
|
143
145
|
# @param request [::Rack::Request] the rack request as will be handed to rails controller.
|
144
146
|
# @param top_router [::ActionDispatch::Journey::Router] the current router relative to the previous.
|
@@ -153,7 +155,7 @@ module Contrast
|
|
153
155
|
# If the current routing node points to a sub-app (::Rais::Engine), dive deeper.
|
154
156
|
# Have sub-app route the remainder of the url.
|
155
157
|
if engine_route?(route)
|
156
|
-
new_req = retrieve_request
|
158
|
+
new_req = retrieve_request(request.env)
|
157
159
|
new_req.path_info = new_req.path_info.gsub(match.to_s, '')
|
158
160
|
get_full_route(new_req, route.app.app.routes.router, path << match.to_s)
|
159
161
|
else
|
@@ -162,12 +164,17 @@ module Contrast
|
|
162
164
|
end
|
163
165
|
|
164
166
|
# Rails engine routes need to be detected by inspecting Engine class route set
|
167
|
+
#
|
168
|
+
# @param app [Rails::Application]
|
169
|
+
# @param route_list [Array<Contrast::Agent::Reporting::DiscoveredRoute>] the list of discovered routes to
|
170
|
+
# which to append and return
|
171
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
165
172
|
def find_all_routes app, route_list
|
166
173
|
return route_list unless app.cs__respond_to?(:routes) && app.routes.cs__respond_to?(:routes)
|
167
174
|
|
168
175
|
app.routes.routes.each do |route|
|
169
176
|
if route.cs__respond_to?(:app) && route.app.cs__class == ActionDispatch::Routing::RouteSet::Dispatcher
|
170
|
-
route_list << Contrast::
|
177
|
+
route_list << Contrast::Agent::Reporting::DiscoveredRoute.from_action_dispatch_journey(route)
|
171
178
|
elsif route.app.app.cs__respond_to?(:routes)
|
172
179
|
route_list += find_all_routes(route.app.app, [])
|
173
180
|
end
|
@@ -47,7 +47,7 @@ module Contrast
|
|
47
47
|
|
48
48
|
# Find all classes that subclass ::Sinatra::Base. Gather their routes.
|
49
49
|
#
|
50
|
-
# @return [Array<Contrast::
|
50
|
+
# @return [Array<Contrast::Agent::Reporting::DiscoveredRoute>]
|
51
51
|
def collect_routes
|
52
52
|
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless defined?(::Sinatra) && defined?(::Sinatra::Base)
|
53
53
|
|
@@ -56,7 +56,8 @@ module Contrast
|
|
56
56
|
controller.routes.each_pair do |method, route_triplets|
|
57
57
|
# Sinatra stores its routes as a triplet: [Mustermann::Sinatra, [], Proc]
|
58
58
|
route_triplets.map(&:first).each do |route_pattern|
|
59
|
-
routes << Contrast::
|
59
|
+
routes << Contrast::Agent::Reporting::DiscoveredRoute.from_sinatra_route(controller, method,
|
60
|
+
route_pattern)
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -101,7 +102,7 @@ module Contrast
|
|
101
102
|
full_route ||= request.env[::Rack::PATH_INFO]
|
102
103
|
|
103
104
|
new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
|
104
|
-
new_route_coverage.attach_rack_based_data
|
105
|
+
new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
|
105
106
|
end
|
106
107
|
|
107
108
|
# Search object space for sinatra controllers--any class that subclasses ::Sinatra::Base.
|