contrast-agent 6.1.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_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 +12 -1
- 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 +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/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/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 +5 -5
- 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 +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +6 -6
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +7 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +15 -15
- data/lib/contrast/agent/reporting/settings/application_settings.rb +1 -1
- data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +3 -3
- data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
- data/lib/contrast/agent/reporting/settings/protect.rb +20 -5
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +5 -5
- data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +2 -2
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +2 -2
- data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
- data/lib/contrast/agent/request.rb +2 -2
- data/lib/contrast/agent/request_context.rb +23 -19
- data/lib/contrast/agent/request_context_extend.rb +10 -23
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/rule_set.rb +2 -2
- data/lib/contrast/agent/scope.rb +1 -1
- 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/version.rb +1 -1
- 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/response_type.rb +4 -17
- 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 +8 -8
- data/lib/contrast/framework/grape/support.rb +3 -3
- data/lib/contrast/framework/manager.rb +5 -5
- 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 +1 -1
- 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 +29 -22
- 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/sha256_builder.rb +4 -4
- data/lib/contrast/utils/stack_trace_utils.rb +31 -13
- data/lib/contrast/utils/telemetry.rb +6 -9
- data/lib/contrast/utils/telemetry_client.rb +5 -5
- data/lib/contrast/utils/telemetry_hash.rb +1 -1
- data/lib/contrast/utils/telemetry_identifier.rb +2 -2
- data/lib/contrast/utils/timer.rb +1 -1
- data/resources/assess/policy.json +1 -1
- metadata +15 -13
@@ -18,7 +18,7 @@ module Contrast
|
|
18
18
|
|
19
19
|
# All of the feature server_features
|
20
20
|
#
|
21
|
-
# @return
|
21
|
+
# @return [Contrast::Agent::Reporting::Settings::FeatureSettings, nil]
|
22
22
|
attr_accessor :server_features
|
23
23
|
|
24
24
|
class << self
|
@@ -92,7 +92,7 @@ module Contrast
|
|
92
92
|
sensitive_data = response_data[:settings][:sensitive_data_masking_policy]
|
93
93
|
res.application_settings.sensitive_data_masking.mask_http_body = sensitive_data[:mask_http_body]
|
94
94
|
res.application_settings.sensitive_data_masking.mask_attack_vector = sensitive_data[:mask_attack_vector]
|
95
|
-
res.application_settings.sensitive_data_masking.build_rules_form_settings
|
95
|
+
res.application_settings.sensitive_data_masking.build_rules_form_settings(sensitive_data[:rules])
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -78,17 +78,17 @@ module Contrast
|
|
78
78
|
def handle_error response
|
79
79
|
case response&.code
|
80
80
|
when ERROR_CODES[:message_not_sent]
|
81
|
-
handle_response_errors
|
81
|
+
handle_response_errors(response, UNSUCCESSFULLY_RECEIVED_MSG, mode.running)
|
82
82
|
when ERROR_CODES[:access_forbidden]
|
83
|
-
handle_response_errors
|
83
|
+
handle_response_errors(response, FORBIDDEN_MSG, mode.running)
|
84
84
|
when ERROR_CODES[:access_forbidden_no_action]
|
85
|
-
handle_response_errors
|
85
|
+
handle_response_errors(response, FORBIDDEN_NO_ACTION_MSG, mode.running)
|
86
86
|
when ERROR_CODES[:application_do_not_exist]
|
87
|
-
handle_response_errors
|
87
|
+
handle_response_errors(response, APP_NON_EXISTENT_MSG, mode.disabled)
|
88
88
|
when ERROR_CODES[:unprocessable_entity]
|
89
|
-
handle_response_errors
|
89
|
+
handle_response_errors(response, UNPROCESSABLE_ENTITY_MSG, mode.disabled)
|
90
90
|
when ERROR_CODES[:too_many_requests]
|
91
|
-
handle_response_errors
|
91
|
+
handle_response_errors(response, RETRY_AFTER_MSG, mode.resending)
|
92
92
|
else
|
93
93
|
logger.debug('Response Error code could not be processed')
|
94
94
|
end
|
@@ -102,7 +102,7 @@ module Contrast
|
|
102
102
|
# @param error_message [String, nil] Error message if any received.
|
103
103
|
def suspend_reporting message, timeout, error_message
|
104
104
|
@_timeout = timeout || Contrast::Agent::Reporting::ResponseHandler::TIMEOUT
|
105
|
-
log_debug_msg
|
105
|
+
log_debug_msg(message, timeout: @_timeout, error_message: error_message || 'none')
|
106
106
|
@_sleep = true
|
107
107
|
end
|
108
108
|
|
@@ -95,16 +95,16 @@ module Contrast
|
|
95
95
|
def handle_response_errors response, message, mode
|
96
96
|
# Set the current mode status.
|
97
97
|
@_mode.status = mode
|
98
|
-
ready_after, error_message, auth_error = extract_response_info
|
98
|
+
ready_after, error_message, auth_error = extract_response_info(response)
|
99
99
|
# log, suspend, disable:
|
100
100
|
if mode == @_mode.running
|
101
|
-
log_debug_msg
|
101
|
+
log_debug_msg(message,
|
102
102
|
response: response.__id__,
|
103
103
|
request: Contrast::Agent::REQUEST_TRACKER.current&.request&.type,
|
104
104
|
error_message: error_message || 'none',
|
105
|
-
auth_error: auth_error || 'none'
|
105
|
+
auth_error: auth_error || 'none')
|
106
106
|
end
|
107
|
-
suspend_reporting
|
107
|
+
suspend_reporting(message, ready_after, error_message) if mode == @_mode.resending
|
108
108
|
return unless mode == @_mode.disabled
|
109
109
|
|
110
110
|
stop_reporting(message, application: Contrast::APP_CONTEXT.app_name, error_message: error_message)
|
@@ -142,8 +142,8 @@ module Contrast
|
|
142
142
|
def update_agent_settings response
|
143
143
|
return unless response
|
144
144
|
|
145
|
-
Contrast::SETTINGS.update_from_server_features(response) if response.server_features
|
146
|
-
Contrast::SETTINGS.update_from_application_settings(response) if response.application_settings
|
145
|
+
::Contrast::SETTINGS.update_from_server_features(response) if response.server_features
|
146
|
+
::Contrast::SETTINGS.update_from_application_settings(response) if response.application_settings
|
147
147
|
end
|
148
148
|
|
149
149
|
# Process the given Reactions from the application settings based on what
|
@@ -152,7 +152,7 @@ module Contrast
|
|
152
152
|
#
|
153
153
|
# @param response [Contrast::Agent::Reporting::Response]
|
154
154
|
def update_reaction response
|
155
|
-
return unless response.application_settings
|
155
|
+
return unless response.application_settings&.reactions&.any?
|
156
156
|
|
157
157
|
response.application_settings.reactions.each do |reaction|
|
158
158
|
# The enums are all uppercase, we need to downcase them before attempting to log.
|
@@ -223,11 +223,11 @@ module Contrast
|
|
223
223
|
# @return res [Contrast::Agent::Reporting::Response]
|
224
224
|
def build_application_settings response_data
|
225
225
|
res = Contrast::Agent::Reporting::Response.application_response
|
226
|
-
extract_assess
|
227
|
-
extract_protect
|
228
|
-
extract_exclusions
|
229
|
-
extract_reactions
|
230
|
-
extract_sensitive_data_policy
|
226
|
+
extract_assess(response_data, res)
|
227
|
+
extract_protect(response_data, res)
|
228
|
+
extract_exclusions(response_data, res)
|
229
|
+
extract_reactions(response_data, res)
|
230
|
+
extract_sensitive_data_policy(response_data, res)
|
231
231
|
res
|
232
232
|
end
|
233
233
|
|
@@ -235,9 +235,9 @@ module Contrast
|
|
235
235
|
# @return res [Contrast::Agent::Reporting::Response]
|
236
236
|
def build_feature_settings response_data
|
237
237
|
res = Contrast::Agent::Reporting::Response.server_response
|
238
|
-
extract_assess_server_features
|
239
|
-
extract_protect_server_features
|
240
|
-
extract_protect_lists
|
238
|
+
extract_assess_server_features(response_data, res)
|
239
|
+
extract_protect_server_features(response_data, res)
|
240
|
+
extract_protect_lists(response_data, res)
|
241
241
|
res.server_features.log_level = response_data[:logLevel]
|
242
242
|
res.server_features.log_file = response_data[:logFile]
|
243
243
|
res.server_features.telemetry = response_data[:telemetry]
|
@@ -61,7 +61,7 @@ module Contrast
|
|
61
61
|
# operation [String] What to do in response to this reaction.[NOOP, DISABLE] }
|
62
62
|
# @return [Array<Contrast::Agent::Reporting::Settings::Reaction>]
|
63
63
|
def reactions= reactions
|
64
|
-
return unless reactions.is_a?
|
64
|
+
return unless reactions.is_a?(Array)
|
65
65
|
|
66
66
|
@_reactions = []
|
67
67
|
reactions.each do |r|
|
@@ -12,7 +12,7 @@ module Contrast
|
|
12
12
|
class Assess
|
13
13
|
# Assess rules to disable for this application.
|
14
14
|
#
|
15
|
-
# @return disabled_rules [Array<
|
15
|
+
# @return disabled_rules [Array<String>] Array with string rule_ids
|
16
16
|
def disabled_rules
|
17
17
|
@_disabled_rules ||= []
|
18
18
|
end
|
@@ -20,15 +20,15 @@ module Contrast
|
|
20
20
|
# @param disabled_rules [Array] with AssessRuleID strings
|
21
21
|
# @return disabled_rules [Array<AssessRuleID>] Array with string rule_ids
|
22
22
|
def disabled_rules= disabled_rules
|
23
|
-
@_disabled_rules = disabled_rules if disabled_rules.is_a?
|
23
|
+
@_disabled_rules = disabled_rules if disabled_rules.is_a?(Array)
|
24
24
|
end
|
25
25
|
|
26
26
|
# The id of a session on TeamServer under which this session of this application should report
|
27
27
|
# Overrides that set by application.session_id (should match if provided).
|
28
28
|
#
|
29
|
-
# @return session_id [String]
|
29
|
+
# @return session_id [String, nil]
|
30
30
|
def session_id
|
31
|
-
@_session_id
|
31
|
+
@_session_id
|
32
32
|
end
|
33
33
|
|
34
34
|
# Set the session_id
|
@@ -36,7 +36,7 @@ module Contrast
|
|
36
36
|
# @param session_id [String]
|
37
37
|
# @return session_id [String]
|
38
38
|
def session_id= session_id
|
39
|
-
@_session_id = session_id if session_id.is_a?
|
39
|
+
@_session_id = session_id if session_id.is_a?(String) && !session_id.blank?
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -47,7 +47,7 @@ module Contrast
|
|
47
47
|
# }
|
48
48
|
# @return [Contrast::Agent::Reporting::Settings::Sampling]
|
49
49
|
def sampling= sampling
|
50
|
-
@_sampling = Contrast::Agent::Reporting::Settings::Sampling.new(sampling) if sampling.is_a?
|
50
|
+
@_sampling = Contrast::Agent::Reporting::Settings::Sampling.new(sampling) if sampling.is_a?(Hash)
|
51
51
|
end
|
52
52
|
|
53
53
|
# The sanitizers defined by the user for use by the agent on this server for this organization.
|
@@ -72,7 +72,7 @@ module Contrast
|
|
72
72
|
# tags [Array[String]]
|
73
73
|
# uuid [String]
|
74
74
|
def sanitizers= sanitizers
|
75
|
-
@_sanitizers = sanitizers if sanitizers.is_a?
|
75
|
+
@_sanitizers = sanitizers if sanitizers.is_a?(Array)
|
76
76
|
end
|
77
77
|
|
78
78
|
# The validators defined by the user for use by the agent on this server for this organization.
|
@@ -99,7 +99,7 @@ module Contrast
|
|
99
99
|
# uuid [String]
|
100
100
|
# }
|
101
101
|
def validators= validators
|
102
|
-
@_validators = validators if validators.is_a?
|
102
|
+
@_validators = validators if validators.is_a?(Array)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -36,7 +36,7 @@ module Contrast
|
|
36
36
|
# denylist [String] The call, if in the stack, should result in the agent not taking action.
|
37
37
|
# }
|
38
38
|
def code_exclusions= code_exclusions
|
39
|
-
@_code_exclusions = code_exclusions if code_exclusions.is_a?
|
39
|
+
@_code_exclusions = code_exclusions if code_exclusions.is_a?(Array)
|
40
40
|
end
|
41
41
|
|
42
42
|
# Cases where rules should be excluded if violated from a given input.
|
@@ -75,7 +75,7 @@ module Contrast
|
|
75
75
|
# type [String] The type of the input [COOKIE, PARAMETER, HEADER, BODY, QUERYSTRING]
|
76
76
|
# }
|
77
77
|
def input_exclusions= input_exclusions
|
78
|
-
@_input_exclusions = input_exclusions if input_exclusions.is_a?
|
78
|
+
@_input_exclusions = input_exclusions if input_exclusions.is_a?(Array)
|
79
79
|
end
|
80
80
|
|
81
81
|
# A case where rules should be excluded if violated during a call to a given URL.
|
@@ -114,7 +114,7 @@ module Contrast
|
|
114
114
|
# type [String] The type of the input [COOKIE, PARAMETER, HEADER, BODY, QUERYSTRING]
|
115
115
|
# }
|
116
116
|
def url_exclusions= url_exclusions
|
117
|
-
@_url_exclusions = url_exclusions if url_exclusions.is_a?
|
117
|
+
@_url_exclusions = url_exclusions if url_exclusions.is_a?(Array)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|
@@ -11,7 +11,7 @@ module Contrast
|
|
11
11
|
# Application level settings for the Protect featureset
|
12
12
|
class Protect
|
13
13
|
# block at perimeter needs to be check against the blockAtEntry boolean value
|
14
|
-
PROTECT_RULES_MODE = %w[OFF BLOCKING
|
14
|
+
PROTECT_RULES_MODE = %w[OFF MONITORING BLOCKING].cs__freeze
|
15
15
|
# The settings for each protect rule for this application
|
16
16
|
#
|
17
17
|
# @return protection_rules [Array<protectRule>] protectRule: {
|
@@ -33,7 +33,7 @@ module Contrast
|
|
33
33
|
# id [String] The id of a rule in Contrast.
|
34
34
|
# mode [String] The mode that this rule should run in. [OFF, MONITORING, BLOCKING] }
|
35
35
|
def protection_rules= protection_rules
|
36
|
-
@_protection_rules = protection_rules if protection_rules.is_a?
|
36
|
+
@_protection_rules = protection_rules if protection_rules.is_a?(Array)
|
37
37
|
end
|
38
38
|
|
39
39
|
# The virtual patches to apply for this application
|
@@ -66,7 +66,7 @@ module Contrast
|
|
66
66
|
# urls [Array] The urls that must be present in the request to result in the request being blocked.
|
67
67
|
# uuids [String] The UUID of the Virtual Patch }
|
68
68
|
def virtual_patches= virtual_patches
|
69
|
-
@_virtual_patches = virtual_patches if virtual_patches.is_a?
|
69
|
+
@_virtual_patches = virtual_patches if virtual_patches.is_a?(Array)
|
70
70
|
end
|
71
71
|
|
72
72
|
# Converts settings into Agent Settings understandable hash {RULE_ID => MODE}
|
@@ -77,8 +77,23 @@ module Contrast
|
|
77
77
|
|
78
78
|
modes_by_id = {}
|
79
79
|
protection_rules.each do |rule|
|
80
|
-
|
81
|
-
|
80
|
+
setting_mode = rule[:mode]
|
81
|
+
next unless PROTECT_RULES_MODE.include?(setting_mode)
|
82
|
+
|
83
|
+
api_mode = case setting_mode
|
84
|
+
when PROTECT_RULES_MODE[1]
|
85
|
+
::Contrast::Api::Settings::ProtectionRule::Mode::MONITORED
|
86
|
+
when PROTECT_RULES_MODE[2]
|
87
|
+
if rule[:blockAtEntry]
|
88
|
+
::Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
|
89
|
+
else
|
90
|
+
::Contrast::Api::Settings::ProtectionRule::Mode::BLOCKED
|
91
|
+
end
|
92
|
+
else
|
93
|
+
::Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
|
94
|
+
end
|
95
|
+
|
96
|
+
modes_by_id[rule[:id]] = api_mode
|
82
97
|
end
|
83
98
|
modes_by_id
|
84
99
|
end
|
@@ -66,7 +66,7 @@ module Contrast
|
|
66
66
|
# name [String] The user defined name of the filter.
|
67
67
|
# uuid [String] The identifier of the filter as defined by TeamServer.
|
68
68
|
def ip_allowlist= allowlist
|
69
|
-
@_ip_allowlist = allowlist if allowlist.is_a?
|
69
|
+
@_ip_allowlist = allowlist if allowlist.is_a?(Array)
|
70
70
|
end
|
71
71
|
|
72
72
|
# The IP addresses for which to disable protection.
|
@@ -94,7 +94,7 @@ module Contrast
|
|
94
94
|
# name [String] The user defined name of the filter.
|
95
95
|
# uuid [String] The identifier of the filter as defined by TeamServer.
|
96
96
|
def ip_denylist= denylist
|
97
|
-
@_ip_denylist = denylist if denylist.is_a?
|
97
|
+
@_ip_denylist = denylist if denylist.is_a?(Array)
|
98
98
|
end
|
99
99
|
|
100
100
|
# All of the apis to add new logging calls to the application at runtime.
|
@@ -134,7 +134,7 @@ module Contrast
|
|
134
134
|
# type [String] The type of log message to tenerate. Audit as 0, Security as 2.
|
135
135
|
# [ AUDIT, ERROR, SECURITY ]
|
136
136
|
def log_enchancers= log_enchancers
|
137
|
-
@_log_enchancers = log_enchancers if log_enchancers.is_a?
|
137
|
+
@_log_enchancers = log_enchancers if log_enchancers.is_a?(Array)
|
138
138
|
end
|
139
139
|
|
140
140
|
# The keywords and patterns required for the input analysis of each rule with that capability.
|
@@ -191,7 +191,7 @@ module Contrast
|
|
191
191
|
# value [String] }
|
192
192
|
# }
|
193
193
|
def rule_definition_list= list
|
194
|
-
@_rule_definition_list = list if list.is_a?
|
194
|
+
@_rule_definition_list = list if list.is_a?(Array)
|
195
195
|
end
|
196
196
|
|
197
197
|
# Controls for the syslogging feature in the agent.
|
@@ -234,7 +234,7 @@ module Contrast
|
|
234
234
|
# syslogSeverityProbed [String]
|
235
235
|
# syslogSeveritySuspicous [String]
|
236
236
|
def syslog= log
|
237
|
-
@_syslog = log if log.is_a?
|
237
|
+
@_syslog = log if log.is_a?(Hash)
|
238
238
|
end
|
239
239
|
end
|
240
240
|
end
|
@@ -19,9 +19,9 @@ module Contrast
|
|
19
19
|
# @param message [String] A message to log when receiving this reaction.
|
20
20
|
# @param operation [String] What to do in response to this reaction.[NOOP, DISABLE]
|
21
21
|
def initialize level, operation, message
|
22
|
-
@level = level if LEVELS.include?
|
23
|
-
@operation = operation if OPERATIONS.include?
|
24
|
-
@message = message if message.is_a?
|
22
|
+
@level = level if LEVELS.include?(level)
|
23
|
+
@operation = operation if OPERATIONS.include?(operation)
|
24
|
+
@message = message if message.is_a?(String)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -58,7 +58,7 @@ module Contrast
|
|
58
58
|
# @param rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>]
|
59
59
|
# @return rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>, []]
|
60
60
|
def rules= rules
|
61
|
-
@_rules = rules if rules_array?
|
61
|
+
@_rules = rules if rules_array?(rules)
|
62
62
|
end
|
63
63
|
|
64
64
|
# Build rules from hash
|
@@ -99,7 +99,7 @@ module Contrast
|
|
99
99
|
# @param item [Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule]
|
100
100
|
# @return itself [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>]
|
101
101
|
def << item
|
102
|
-
return itself unless item.instance_of?
|
102
|
+
return itself unless item.instance_of?(Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule)
|
103
103
|
|
104
104
|
super
|
105
105
|
end
|
@@ -37,7 +37,7 @@ module Contrast
|
|
37
37
|
# @param words_array [Array<String>]
|
38
38
|
# @return keywords [Array<String>] set of keywords
|
39
39
|
def keywords= words_array
|
40
|
-
@_keywords = words_array if string_array?
|
40
|
+
@_keywords = words_array if string_array?(words_array)
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
@@ -49,7 +49,7 @@ module Contrast
|
|
49
49
|
def string_array? array
|
50
50
|
return false unless array.is_a?(Array) && array.any?
|
51
51
|
|
52
|
-
array.all?
|
52
|
+
array.all?(String)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -27,7 +27,7 @@ module Contrast
|
|
27
27
|
# @param log_level [String]
|
28
28
|
# @return log_level [String] [ ERROR, WARN, INFO, DEBUG, TRACE ]
|
29
29
|
def log_level= log_level
|
30
|
-
@_log_level = log_level if log_level.is_a?
|
30
|
+
@_log_level = log_level if log_level.is_a?(String)
|
31
31
|
end
|
32
32
|
|
33
33
|
# Where to log the agent's log file, if set by the user. Overridden by agent.logger.path
|
@@ -43,7 +43,7 @@ module Contrast
|
|
43
43
|
# @param log_file [String] path
|
44
44
|
# @return log_file [String] path
|
45
45
|
def log_file= log_file
|
46
|
-
@_log_file = log_file if log_file.is_a?
|
46
|
+
@_log_file = log_file if log_file.is_a?(String)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Controls for the reporting of telemetry events from the agent to TeamServer.
|
@@ -34,6 +34,8 @@ module Contrast
|
|
34
34
|
LAST_REST_TOKEN = %r{/\d+$}.cs__freeze
|
35
35
|
INNER_NUMBER_MARKER = '/{n}/'
|
36
36
|
LAST_NUMBER_MARKER = '/{n}'
|
37
|
+
STATIC_SUFFIXES = /\.(?:js|css|jpeg|jpg|gif|png|ico|woff|svg|pdf|eot|ttf|jar)$/i.cs__freeze
|
38
|
+
MEDIA_TYPE_MARKERS = %w[image/ text/css text/javascript].cs__freeze
|
37
39
|
|
38
40
|
attr_reader :rack_request
|
39
41
|
attr_accessor :route, :observed_route, :new_observed_route
|
@@ -181,8 +183,6 @@ module Contrast
|
|
181
183
|
@_hash_id ||= Contrast::Utils::HashDigest.generate_request_hash(self)
|
182
184
|
end
|
183
185
|
|
184
|
-
STATIC_SUFFIXES = /\.(?:js|css|jpeg|jpg|gif|png|ico|woff|svg|pdf|eot|ttf|jar)$/i.cs__freeze
|
185
|
-
MEDIA_TYPE_MARKERS = %w[image/ text/css text/javascript].cs__freeze
|
186
186
|
# Utility method for checking if a request is for a static resource.
|
187
187
|
# @return [Boolean] true, if the request is for a well-known static
|
188
188
|
# type as determined by the request suffix or the accept header.
|
@@ -1,6 +1,7 @@
|
|
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/api/dtm.pb'
|
4
5
|
require 'contrast/utils/timer'
|
5
6
|
require 'contrast/agent/request'
|
6
7
|
require 'contrast/agent/response'
|
@@ -16,20 +17,6 @@ module Contrast
|
|
16
17
|
module Agent
|
17
18
|
# This class acts to encapsulate information about the currently executed request, making it available to the Agent
|
18
19
|
# for the duration of the request in a standardized and normalized format which the Agent understands.
|
19
|
-
#
|
20
|
-
# @attr_reader timer [Contrast::Utils::Timer] when the context was created
|
21
|
-
# @attr_reader logging_hash [Hash] context used to log the request
|
22
|
-
# @attr_reader speedracer_input_analysis [Contrast::Api::Settings::InputAnalysis] the protect input analysis of
|
23
|
-
# sources on this request
|
24
|
-
# @attr_reader request [Contrast::Agent::Request] our wrapper around the Rack::Request for this context
|
25
|
-
# @attr_reader response [Contrast::Agent::Response] our wrapper aroudn the Rack::Response or Array for this context,
|
26
|
-
# only available after the application has finished its processing
|
27
|
-
# @attr_reader activity [Contrast::Api::Dtm::Activity] the application activity found in this request
|
28
|
-
# @attr_reader server_activity [Contrast::Api::Dtm::ServerActivity] the server activity found in this request
|
29
|
-
# @attr_reader route [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
|
30
|
-
# @attr_reader observed_route [Contrast::Api::Dtm::ObservedRoute] the route, used for coverage, of this request
|
31
|
-
# @attr_reader new_observed_route [Contrast::Agent::Reporting::ObservedRoute] the route, used for coverage, of this
|
32
|
-
# request
|
33
20
|
class RequestContext
|
34
21
|
include Contrast::Components::Logger::InstanceMethods
|
35
22
|
include Contrast::Components::Scope::InstanceMethods
|
@@ -37,10 +24,28 @@ module Contrast
|
|
37
24
|
include Contrast::Agent::RequestContextExtend
|
38
25
|
|
39
26
|
EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
|
40
|
-
INPUT_ANALYSIS = Contrast::Agent::Reporting::InputAnalysis.new
|
41
27
|
|
42
|
-
|
43
|
-
|
28
|
+
# @return [Contrast::Api::Dtm::Activity] the application activity found in this request
|
29
|
+
attr_reader :activity
|
30
|
+
# @return [Hash] context used to log the request
|
31
|
+
attr_reader :logging_hash
|
32
|
+
# @return [Contrast::Agent::Reporting::ObservedRoute] the route, used for coverage, of this request
|
33
|
+
attr_reader :new_observed_route
|
34
|
+
# @return [Contrast::Api::Dtm::ObservedRoute] the route, used for coverage, of this request
|
35
|
+
attr_reader :observed_route
|
36
|
+
# @return [Contrast::Agent::Request] our wrapper around the Rack::Request for this context
|
37
|
+
attr_reader :request
|
38
|
+
# @return [Contrast::Agent::Response] our wrapper around the Rack::Response or Array for this context,
|
39
|
+
# only available after the application has finished its processing
|
40
|
+
attr_reader :response
|
41
|
+
# @return [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
|
42
|
+
attr_reader :route
|
43
|
+
# @return [Contrast::Api::Dtm::ServerActivity] the server activity found in this request
|
44
|
+
attr_reader :server_activity
|
45
|
+
# @return [Contrast::Api::Settings::InputAnalysis] the protect input analysis of sources on this request
|
46
|
+
attr_reader :speedracer_input_analysis
|
47
|
+
# @return [Contrast::Utils::Timer] when the context was created
|
48
|
+
attr_reader :timer
|
44
49
|
|
45
50
|
def initialize rack_request, app_loaded: true
|
46
51
|
with_contrast_scope do
|
@@ -61,8 +66,7 @@ module Contrast
|
|
61
66
|
@speedracer_input_analysis = EMPTY_INPUT_ANALYSIS_PB
|
62
67
|
speedracer_input_analysis.request = request
|
63
68
|
|
64
|
-
|
65
|
-
agent_input_analysis.request = request
|
69
|
+
# TODO: RUBY-1627
|
66
70
|
|
67
71
|
# flag to indicate whether the app is fully loaded
|
68
72
|
@app_loaded = !!app_loaded
|
@@ -82,9 +82,10 @@ module Contrast
|
|
82
82
|
handle_protect_state(service_response)
|
83
83
|
ia = service_response.input_analysis
|
84
84
|
if ia
|
85
|
-
service_extract_logging
|
85
|
+
service_extract_logging(ia)
|
86
|
+
# TODO: RUBY-1629
|
86
87
|
# using Agent analysis
|
87
|
-
initialize_agent_input_analysis request
|
88
|
+
# initialize_agent_input_analysis request
|
88
89
|
|
89
90
|
@speedracer_input_analysis = ia
|
90
91
|
speedracer_input_analysis.request = request
|
@@ -93,7 +94,7 @@ module Contrast
|
|
93
94
|
false
|
94
95
|
end
|
95
96
|
rescue Contrast::SecurityException => e
|
96
|
-
raise
|
97
|
+
raise(e)
|
97
98
|
rescue StandardError => e
|
98
99
|
logger.warn('Unable to extract Contrast Service information from request', e)
|
99
100
|
false
|
@@ -115,7 +116,7 @@ module Contrast
|
|
115
116
|
# If Contrast Service has NOT handled the input analysis, handle them here
|
116
117
|
build_attack_results(agent_settings)
|
117
118
|
logger.debug('Contrast Service said to block this request')
|
118
|
-
raise
|
119
|
+
raise(Contrast::SecurityException.new(nil, (state.security_message || 'Blocking suspicious behavior')))
|
119
120
|
end
|
120
121
|
|
121
122
|
# append anything we've learned to the request seen message this is the sum-total of all inventory information
|
@@ -147,7 +148,7 @@ module Contrast
|
|
147
148
|
|
148
149
|
# This here is for things we don't have implemented
|
149
150
|
def log_to_cef
|
150
|
-
activity.results.each { |attack_result| logging_logic
|
151
|
+
activity.results.each { |attack_result| logging_logic(attack_result, attack_result.rule_id.downcase) }
|
151
152
|
end
|
152
153
|
|
153
154
|
# @param input_analysis [Contrast::Api::Settings::InputAnalysis]
|
@@ -172,7 +173,7 @@ module Contrast
|
|
172
173
|
next unless rule
|
173
174
|
|
174
175
|
logger.debug(BUILD_ATTACK_LOGGER_MESSAGE, result: ia_result.inspect) if logger.debug?
|
175
|
-
results_by_rule[rule_id] = attack_result
|
176
|
+
results_by_rule[rule_id] = attack_result(rule, rule_id, ia_result, results_by_rule)
|
176
177
|
end
|
177
178
|
|
178
179
|
results_by_rule.each_pair do |_, attack_result|
|
@@ -199,20 +200,6 @@ module Contrast
|
|
199
200
|
end
|
200
201
|
end
|
201
202
|
|
202
|
-
# Sets request to be used with agent and service input analysis.
|
203
|
-
#
|
204
|
-
# @param request [Contrast::Agent::Request] our wrapper around the Rack::Request
|
205
|
-
# for this context
|
206
|
-
def initialize_agent_input_analysis request
|
207
|
-
# using Agent analysis
|
208
|
-
ia = Contrast::Agent::Protect::InputAnalyzer.analyse request
|
209
|
-
if ia
|
210
|
-
@agent_input_analysis = ia
|
211
|
-
else
|
212
|
-
logger.trace('Analysis from Agent was empty.')
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
203
|
def logging_logic result, rule_id
|
217
204
|
rules = %w[bot_blocker virtual_patch ip_denylist]
|
218
205
|
return unless rules.include?(rule_id)
|
@@ -221,14 +208,14 @@ module Contrast
|
|
221
208
|
outcome = Contrast::Api::Dtm::AttackResult::ResponseType.get_name_by_tag(result.response)
|
222
209
|
case rule_id
|
223
210
|
when /bot_blocker/i
|
224
|
-
blocker_to_json = Contrast::Api::Dtm::BotBlockerDetails.to_controlled_hash
|
211
|
+
blocker_to_json = Contrast::Api::Dtm::BotBlockerDetails.to_controlled_hash(rule_details)
|
225
212
|
cef_logger.bot_blocking_message(blocker_to_json, outcome)
|
226
213
|
when /virtual_patch/i
|
227
|
-
virtual_patch_to_json = Contrast::Api::Dtm::VirtualPatchDetails.to_controlled_hash
|
214
|
+
virtual_patch_to_json = Contrast::Api::Dtm::VirtualPatchDetails.to_controlled_hash(rule_details)
|
228
215
|
cef_logger.virtual_patch_message(virtual_patch_to_json, outcome)
|
229
216
|
when /ip_denylist/i
|
230
217
|
sender_ip = extract_sender_ip
|
231
|
-
ip_denylist_to_json = Contrast::Api::Dtm::IpDenylistDetails.to_controlled_hash
|
218
|
+
ip_denylist_to_json = Contrast::Api::Dtm::IpDenylistDetails.to_controlled_hash(rule_details)
|
232
219
|
return unless sender_ip
|
233
220
|
return unless sender_ip.include?(ip_denylist_to_json[:ip])
|
234
221
|
|
@@ -54,7 +54,7 @@ module Contrast
|
|
54
54
|
return unless reporter
|
55
55
|
|
56
56
|
# Mask Sensitive Data
|
57
|
-
Contrast::Agent::Reporting::Masker.mask
|
57
|
+
Contrast::Agent::Reporting::Masker.mask(context.activity)
|
58
58
|
|
59
59
|
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage(context.activity)
|
60
60
|
[
|
@@ -23,7 +23,7 @@ module Contrast
|
|
23
23
|
end
|
24
24
|
rescue Contrast::SecurityException => e
|
25
25
|
logger.warn('RASP threw security exception in prefilter', e)
|
26
|
-
raise
|
26
|
+
raise(e)
|
27
27
|
rescue StandardError => e
|
28
28
|
logger.error('Unexpected exception during prefilter', e)
|
29
29
|
end
|
@@ -39,7 +39,7 @@ module Contrast
|
|
39
39
|
end
|
40
40
|
rescue Contrast::SecurityException => e
|
41
41
|
logger.warn('RASP threw security exception in postfilter', e)
|
42
|
-
raise
|
42
|
+
raise(e)
|
43
43
|
rescue StandardError => e
|
44
44
|
logger.error('Unexpected exception during postfilter', e)
|
45
45
|
end
|
data/lib/contrast/agent/scope.rb
CHANGED
@@ -142,7 +142,7 @@ module Contrast
|
|
142
142
|
# @param scope_sym [Symbol] scope to check.
|
143
143
|
# @return [Boolean] true | false
|
144
144
|
def valid_scope? scope_sym
|
145
|
-
Contrast::Agent::Scope::SCOPE_LIST.include?
|
145
|
+
Contrast::Agent::Scope::SCOPE_LIST.include?(scope_sym)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|