contrast-agent 6.8.0 → 6.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +11 -11
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +1 -1
- data/lib/contrast/agent/assess.rb +0 -1
- data/lib/contrast/agent/excluder.rb +1 -1
- data/lib/contrast/agent/middleware.rb +12 -4
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +76 -83
- data/lib/contrast/agent/protect/input_analyzer/worth_watching_analyzer.rb +121 -0
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +2 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +6 -3
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +3 -0
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +12 -0
- data/lib/contrast/agent/protect/rule/base.rb +21 -7
- data/lib/contrast/agent/protect/rule/base_service.rb +6 -0
- data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +1 -1
- data/lib/contrast/agent/protect/rule/bot_blocker.rb +9 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +8 -7
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +8 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +0 -5
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +0 -5
- data/lib/contrast/agent/protect/rule/deserialization.rb +2 -2
- data/lib/contrast/agent/protect/rule/no_sqli.rb +24 -2
- data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +1 -1
- data/lib/contrast/agent/protect/rule/path_traversal.rb +12 -3
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +0 -1
- data/lib/contrast/agent/protect/rule/sqli.rb +10 -13
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +6 -2
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +20 -0
- data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +9 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +2 -2
- data/lib/contrast/agent/protect/rule.rb +0 -3
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +1 -1
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +0 -1
- data/lib/contrast/agent/reporting/details/details.rb +0 -1
- data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +12 -0
- data/lib/contrast/agent/reporting/report.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +42 -7
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +5 -6
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +24 -7
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +20 -5
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +5 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +10 -1
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -1
- data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +10 -0
- data/lib/contrast/agent/reporting/reporting_events/application_settings.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +239 -93
- data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +10 -23
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +10 -9
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +12 -0
- data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +8 -0
- data/lib/contrast/agent/reporting/reporting_events/server_settings.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
- data/lib/contrast/agent/reporting/reporting_utilities/ng_response_extractor.rb +137 -0
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +52 -2
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +8 -4
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +105 -58
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +9 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +143 -49
- data/lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb +46 -0
- data/lib/contrast/agent/reporting/reporting_workers/reporter_heartbeat.rb +51 -0
- data/lib/contrast/agent/reporting/reporting_workers/reporting_workers.rb +14 -0
- data/lib/contrast/agent/reporting/reporting_workers/server_settings_worker.rb +46 -0
- data/lib/contrast/agent/reporting/settings/assess.rb +14 -1
- data/lib/contrast/agent/reporting/settings/assess_rule.rb +18 -0
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +14 -2
- data/lib/contrast/agent/reporting/settings/helpers.rb +9 -0
- data/lib/contrast/agent/reporting/settings/protect.rb +17 -12
- data/lib/contrast/agent/reporting/settings/protect_rule.rb +18 -0
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +40 -3
- data/lib/contrast/agent/reporting/settings/rule_definition.rb +3 -0
- data/lib/contrast/agent/reporting/settings/security_logger.rb +77 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +1 -1
- data/lib/contrast/agent/reporting/settings/server_features.rb +9 -0
- data/lib/contrast/agent/reporting/settings/syslog.rb +34 -5
- data/lib/contrast/agent/reporting/settings/virtual_patch.rb +56 -0
- data/lib/contrast/agent/reporting/settings/virtual_patch_condition.rb +47 -0
- data/lib/contrast/agent/request.rb +1 -0
- data/lib/contrast/agent/request_context_extend.rb +20 -0
- data/lib/contrast/agent/request_handler.rb +5 -10
- data/lib/contrast/agent/telemetry/base.rb +11 -10
- data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +108 -103
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +1 -1
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +46 -6
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +18 -0
- data/lib/contrast/agent_lib/api/init.rb +1 -7
- data/lib/contrast/agent_lib/api/input_tracing.rb +2 -4
- data/lib/contrast/agent_lib/interface.rb +1 -16
- data/lib/contrast/agent_lib/interface_base.rb +52 -39
- data/lib/contrast/agent_lib/return_types/eval_result.rb +2 -2
- data/lib/contrast/api/communication/connection_status.rb +15 -0
- data/lib/contrast/components/agent.rb +34 -0
- data/lib/contrast/components/api.rb +23 -0
- data/lib/contrast/components/app_context.rb +23 -3
- data/lib/contrast/components/assess.rb +60 -8
- data/lib/contrast/components/assess_rules.rb +18 -0
- data/lib/contrast/components/base.rb +40 -0
- data/lib/contrast/components/config/sources.rb +95 -0
- data/lib/contrast/components/config.rb +18 -1
- data/lib/contrast/components/heap_dump.rb +10 -0
- data/lib/contrast/components/inventory.rb +15 -2
- data/lib/contrast/components/logger.rb +18 -0
- data/lib/contrast/components/polling.rb +39 -0
- data/lib/contrast/components/protect.rb +48 -1
- data/lib/contrast/components/ruby_component.rb +15 -0
- data/lib/contrast/components/sampling.rb +70 -13
- data/lib/contrast/components/security_logger.rb +13 -0
- data/lib/contrast/components/settings.rb +120 -10
- data/lib/contrast/config/certification_configuration.rb +14 -0
- data/lib/contrast/config/config.rb +46 -0
- data/lib/contrast/config/diagnostics.rb +114 -0
- data/lib/contrast/config/diagnostics_tools.rb +98 -0
- data/lib/contrast/config/effective_config.rb +65 -0
- data/lib/contrast/config/effective_config_value.rb +32 -0
- data/lib/contrast/config/exception_configuration.rb +12 -0
- data/lib/contrast/config/protect_rule_configuration.rb +2 -2
- data/lib/contrast/config/protect_rules_configuration.rb +7 -6
- data/lib/contrast/config/request_audit_configuration.rb +13 -0
- data/lib/contrast/config/server_configuration.rb +41 -2
- data/lib/contrast/configuration.rb +28 -2
- data/lib/contrast/extension/assess/array.rb +3 -3
- data/lib/contrast/extension/assess/erb.rb +1 -1
- data/lib/contrast/extension/assess/regexp.rb +2 -2
- data/lib/contrast/logger/aliased_logging.rb +48 -15
- data/lib/contrast/utils/assess/event_limit_utils.rb +31 -9
- data/lib/contrast/utils/assess/trigger_method_utils.rb +5 -4
- data/lib/contrast/utils/hash_digest.rb +2 -2
- data/lib/contrast/utils/input_classification_base.rb +21 -5
- data/lib/contrast/utils/reporting/application_activity_batch_utils.rb +81 -0
- data/lib/contrast/utils/routes_sent.rb +60 -0
- data/lib/contrast/utils/telemetry.rb +1 -1
- data/lib/contrast/utils/telemetry_client.rb +2 -3
- data/lib/contrast/utils/timer.rb +16 -0
- data/lib/contrast.rb +3 -1
- data/resources/protect/policy.json +8 -0
- data/ruby-agent.gemspec +6 -2
- metadata +43 -24
- data/lib/contrast/agent/assess/contrast_event.rb +0 -157
- data/lib/contrast/agent/assess/events/event_factory.rb +0 -34
- data/lib/contrast/agent/assess/events/source_event.rb +0 -46
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +0 -96
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -83
- data/lib/contrast/agent/reporting/details/http_method_tempering_details.rb +0 -27
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +0 -53
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +0 -36
- data/lib/contrast/agent_lib/api/method_tempering.rb +0 -29
@@ -17,6 +17,10 @@ module Contrast
|
|
17
17
|
# Application level settings for the Protect featureset.
|
18
18
|
# Used for the FeatureSet TS response
|
19
19
|
class ProtectServerFeature
|
20
|
+
PROTECT_RULES_KEYS = %i[
|
21
|
+
cmd_injection method_tampering nosql_injection path_traversal redos reflected_xss sql_injection
|
22
|
+
ssrf unsafe_file_upload untrusted_deserialization xxe
|
23
|
+
].cs__freeze
|
20
24
|
# Indicate if the protect feature set is enabled for this server or not.
|
21
25
|
#
|
22
26
|
# @return enabled [Boolean]
|
@@ -32,6 +36,21 @@ module Contrast
|
|
32
36
|
@_enabled = enabled
|
33
37
|
end
|
34
38
|
|
39
|
+
# When false, the agent should not track observations.
|
40
|
+
# when true, the agent should track observed usage of protect URLs
|
41
|
+
# { enable: true }
|
42
|
+
#
|
43
|
+
# @return observability [Boolean]
|
44
|
+
def observability
|
45
|
+
@_observability
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param enable [Boolean]
|
49
|
+
# @return observability [Boolean]
|
50
|
+
def observability= enable
|
51
|
+
@_observability = enable
|
52
|
+
end
|
53
|
+
|
35
54
|
# Indicate if the bot protection feature set is enabled for this server or not.
|
36
55
|
#
|
37
56
|
# @return bot_blocker [Contrast::Agent::Reporting::Settings::BotBlocker]
|
@@ -142,13 +161,30 @@ module Contrast
|
|
142
161
|
# value [String] }
|
143
162
|
# }
|
144
163
|
# @return rule_definition_list [Array<Contrast::Agent::Reporting::Settings::RuleDefinition>]
|
145
|
-
def
|
164
|
+
def ng_rule_definition_list list
|
146
165
|
Contrast::Agent::Reporting::Settings::Helpers.array_to_iv(
|
147
166
|
Contrast::Agent::Reporting::Settings::RuleDefinition,
|
148
167
|
rule_definition_list,
|
149
168
|
list)
|
150
169
|
end
|
151
170
|
|
171
|
+
# Transforms ServerSettings hash rules to definition_list
|
172
|
+
#
|
173
|
+
# @param rules [Hash]
|
174
|
+
def rules_to_definition_list rules
|
175
|
+
return unless rules&.cs__is_a?(Hash)
|
176
|
+
|
177
|
+
definition_list = []
|
178
|
+
rules.slice(*PROTECT_RULES_KEYS).each_pair do |key, rule|
|
179
|
+
new_entry = Contrast::Agent::Reporting::Settings::RuleDefinition.new
|
180
|
+
new_entry.name = Contrast::Agent::Reporting::Settings::Helpers.to_rule_id(key)
|
181
|
+
new_entry.patterns = rule[:patterns]
|
182
|
+
new_entry.keywords = rule[:keywords]
|
183
|
+
definition_list << new_entry
|
184
|
+
end
|
185
|
+
@_rule_definition_list = definition_list
|
186
|
+
end
|
187
|
+
|
152
188
|
# Controls for the syslogging feature in the agent.
|
153
189
|
#
|
154
190
|
# @return syslog [Contrast::Agent::Reporting::Settings::Syslog]
|
@@ -175,13 +211,14 @@ module Contrast
|
|
175
211
|
{
|
176
212
|
botBlockers: bot_blocker.bots.map(&:to_controlled_hash),
|
177
213
|
enabled: enabled?,
|
214
|
+
observability: observability, # used with ServerSettings only
|
178
215
|
logEnhancers: log_enhancers.map(&:to_controlled_hash),
|
179
216
|
ipDenylist: ip_denylist.map(&:to_controlled_hash),
|
180
217
|
ipAllowlist: ip_allowlist.map(&:to_controlled_hash),
|
181
|
-
syslog: syslog.to_controlled_hash,
|
218
|
+
syslog: syslog.settings_blank? ? nil : syslog.to_controlled_hash, # used with ServerSettings only
|
182
219
|
ruleDefinitionList: rule_definition_list.map(&:to_controlled_hash),
|
183
220
|
'bot-blocker': bot_blocker.to_controlled_hash
|
184
|
-
}
|
221
|
+
}.compact
|
185
222
|
end
|
186
223
|
end
|
187
224
|
end
|
@@ -12,6 +12,9 @@ module Contrast
|
|
12
12
|
class RuleDefinition
|
13
13
|
ATTRIBUTES = %i[name keywords patterns].cs__freeze
|
14
14
|
|
15
|
+
# For the ServerSettings this name is not used instead it is used as key to the keywords and patterns
|
16
|
+
# arrays. It is used in the agent startup message.
|
17
|
+
#
|
15
18
|
# @return name [String] Name of the rule
|
16
19
|
attr_accessor :name
|
17
20
|
|
@@ -0,0 +1,77 @@
|
|
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/reporting/settings/syslog'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Reporting
|
9
|
+
module Settings
|
10
|
+
# this class will hold the security logger settings.
|
11
|
+
class SecurityLogger
|
12
|
+
def initialize
|
13
|
+
@blank = true
|
14
|
+
end
|
15
|
+
|
16
|
+
# check to see if object is being used
|
17
|
+
#
|
18
|
+
# @return [Boolean]
|
19
|
+
def settings_blank?
|
20
|
+
@blank
|
21
|
+
end
|
22
|
+
|
23
|
+
# Set the state of settings
|
24
|
+
#
|
25
|
+
# @return [Boolean]
|
26
|
+
def not_blank!
|
27
|
+
@blank = false
|
28
|
+
end
|
29
|
+
|
30
|
+
# The level at which the agent should log. Overridden by agent.logger.level
|
31
|
+
# if set in a local configuration
|
32
|
+
#
|
33
|
+
# @return log_level [String] [ ERROR, WARN, INFO, DEBUG, TRACE ]
|
34
|
+
def log_level
|
35
|
+
@_log_level ||= Contrast::Utils::ObjectShare::EMPTY_STRING
|
36
|
+
end
|
37
|
+
|
38
|
+
# set the log level
|
39
|
+
#
|
40
|
+
# @param log_level [String]
|
41
|
+
# @return log_level [String] [ ERROR, WARN, INFO, DEBUG, TRACE ]
|
42
|
+
def log_level= log_level
|
43
|
+
@_log_level = log_level if log_level.is_a?(String)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Where to log the agent's log file, if set by the user. Overridden by agent.logger.path
|
47
|
+
# if set in a local configuration.
|
48
|
+
#
|
49
|
+
# @return log_file [String] path
|
50
|
+
def log_file
|
51
|
+
@_log_file ||= Contrast::Utils::ObjectShare::EMPTY_STRING
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set the log file
|
55
|
+
#
|
56
|
+
# @param log_file [String] path
|
57
|
+
# @return log_file [String] path
|
58
|
+
def log_file= log_file
|
59
|
+
@_log_file = log_file if log_file.is_a?(String)
|
60
|
+
end
|
61
|
+
|
62
|
+
def syslog
|
63
|
+
@_syslog ||= Contrast::Agent::Reporting::Settings::Syslog.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_controlled_hash
|
67
|
+
{
|
68
|
+
level: log_level,
|
69
|
+
path: log_file,
|
70
|
+
syslog: syslog.to_controlled_hash
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -63,7 +63,7 @@ module Contrast
|
|
63
63
|
|
64
64
|
# Build rules from hash
|
65
65
|
#
|
66
|
-
# @param settings_rules [Hash] Response settings under Settings/sensitive_data_masking_policy/rules
|
66
|
+
# @param settings_rules [Array<Hash>] Response settings under Settings/sensitive_data_masking_policy/rules
|
67
67
|
# @return rules [Array<Contrast::Agent::Reporting::Settings::SensitiveDataMaskingRule>, nil
|
68
68
|
def build_rules_form_settings settings_rules
|
69
69
|
return if settings_rules.nil? || settings_rules.empty?
|
@@ -4,6 +4,7 @@
|
|
4
4
|
require 'contrast/utils/object_share'
|
5
5
|
require 'contrast/agent/reporting/settings/assess_server_feature'
|
6
6
|
require 'contrast/agent/reporting/settings/protect_server_feature'
|
7
|
+
require 'contrast/agent/reporting/settings/security_logger'
|
7
8
|
|
8
9
|
module Contrast
|
9
10
|
module Agent
|
@@ -46,6 +47,13 @@ module Contrast
|
|
46
47
|
@_log_file = log_file if log_file.is_a?(String)
|
47
48
|
end
|
48
49
|
|
50
|
+
# Class holding security logger settings:
|
51
|
+
#
|
52
|
+
# @return [Contrast::Agent::Reporting::Settings::SecurityLogger]
|
53
|
+
def security_logger
|
54
|
+
@_security_logger ||= Contrast::Agent::Reporting::Settings::SecurityLogger.new
|
55
|
+
end
|
56
|
+
|
49
57
|
# Controls for the reporting of telemetry events from the agent to TeamServer.
|
50
58
|
# This is NOT for the agent telemetry feature collecting metrics sent to other services.
|
51
59
|
#
|
@@ -74,6 +82,7 @@ module Contrast
|
|
74
82
|
|
75
83
|
def to_controlled_hash
|
76
84
|
{
|
85
|
+
security_logger: security_logger.settings_blank? ? nil : security_logger.to_controlled_hash,
|
77
86
|
assessment: @_assess ? assess.to_controlled_hash : {},
|
78
87
|
defend: @_protect ? protect.to_controlled_hash : {},
|
79
88
|
telemetry: telemetry
|
@@ -14,15 +14,24 @@ module Contrast
|
|
14
14
|
# severity_blocked, severity_blocked_perimeter, severity_exploited, severity_probed,
|
15
15
|
# severity_probed_perimeter
|
16
16
|
SEVERITIES = %w[ALERT CRITICAL ERROR WARNING NOTICE INFO DEBUG].cs__freeze
|
17
|
-
|
17
|
+
# Order and elements matter, the same setter must be called against same response field.
|
18
|
+
SYSLOG_METHODS_NG = %i[
|
18
19
|
enable= ip= port= facility= protocol= connection_type= severity_exploited= severity_blocked=
|
19
20
|
severity_probed= severity_probed_suspicious= severity_blocked_perimeter= severity_probed_perimeter=
|
20
21
|
].cs__freeze
|
21
|
-
|
22
|
+
SYSLOG_RESPONSE_KEYS_NG = %i[
|
22
23
|
syslogEnabled syslogIpAddress syslogPortNumber syslogFacilityCode syslogProtocol
|
23
24
|
syslogConnectionType syslogSeverityExploited syslogSeverityBlocked syslogSeverityProbed
|
24
25
|
syslogSeveritySuspicious syslogSeverityBlockedPerimeter syslogSeverityProbedPerimeter
|
25
26
|
].cs__freeze
|
27
|
+
SYSLOG_METHODS = %i[
|
28
|
+
enable= ip= port= facility= connection_type= severity_blocked= severity_blocked_perimeter=
|
29
|
+
severity_exploited= severity_probed= severity_probed_perimeter=
|
30
|
+
].cs__freeze
|
31
|
+
SYSLOG_RESPONSE_KEYS = %i[
|
32
|
+
enable ip facility connection_type severity_blocked severity_blocked_perimeter severity_exploited
|
33
|
+
severity_probed severity_probed_perimeter
|
34
|
+
].cs__freeze
|
26
35
|
|
27
36
|
# @return enable [Boolean]
|
28
37
|
attr_accessor :enable
|
@@ -40,6 +49,21 @@ module Contrast
|
|
40
49
|
@ip = Contrast::Utils::ObjectShare::EMPTY_STRING
|
41
50
|
@port = 0
|
42
51
|
@facility = 0
|
52
|
+
@blank = true
|
53
|
+
end
|
54
|
+
|
55
|
+
# check to see if object is being used
|
56
|
+
#
|
57
|
+
# @return [Boolean]
|
58
|
+
def settings_blank?
|
59
|
+
@blank
|
60
|
+
end
|
61
|
+
|
62
|
+
# Set the state of settings
|
63
|
+
#
|
64
|
+
# @return [Boolean]
|
65
|
+
def not_blank!
|
66
|
+
@blank = false
|
43
67
|
end
|
44
68
|
|
45
69
|
# @return connection_type [String] one of UNENCRYPTED, ENCRYPTED
|
@@ -134,10 +158,15 @@ module Contrast
|
|
134
158
|
end
|
135
159
|
|
136
160
|
# @param settings_array [Array] Settings retrieved from response
|
137
|
-
|
138
|
-
|
139
|
-
|
161
|
+
# @param ng_ [Boolean]
|
162
|
+
def assign_array settings_array, ng_: true
|
163
|
+
methods = ng_ ? SYSLOG_METHODS_NG : SYSLOG_METHODS
|
164
|
+
response_keys = ng_ ? SYSLOG_RESPONSE_KEYS_NG : SYSLOG_RESPONSE_KEYS
|
165
|
+
|
166
|
+
methods.each_with_index do |method, index|
|
167
|
+
send(method, settings_array[response_keys[index]])
|
140
168
|
end
|
169
|
+
not_blank!
|
141
170
|
end
|
142
171
|
|
143
172
|
def to_controlled_hash
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/object_share'
|
5
|
+
require 'contrast/agent/reporting/settings/virtual_patch_condition'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Agent
|
9
|
+
module Reporting
|
10
|
+
module Settings
|
11
|
+
# The settings for each virtual patch in the agent.
|
12
|
+
class VirtualPatch
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :name
|
15
|
+
# @return [String]
|
16
|
+
attr_reader :key
|
17
|
+
# @return [String]
|
18
|
+
attr_reader :uuid
|
19
|
+
|
20
|
+
def initialize hash
|
21
|
+
@name = hash[:name]
|
22
|
+
@key = hash[:key]
|
23
|
+
@uuid = hash[:uuid]
|
24
|
+
|
25
|
+
hash[:headers]&.each do |header_json|
|
26
|
+
headers << Contrast::Agent::Reporting::Settings::VirtualPatchCondition.new(header_json)
|
27
|
+
end
|
28
|
+
|
29
|
+
hash[:parameters]&.each do |header_json|
|
30
|
+
parameters << Contrast::Agent::Reporting::Settings::VirtualPatchCondition.new(header_json)
|
31
|
+
end
|
32
|
+
|
33
|
+
hash[:urls]&.each do |header_json|
|
34
|
+
urls << Contrast::Agent::Reporting::Settings::VirtualPatchCondition.new(header_json)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Array<Contrast::Agent::Reporting::Settings::VirtualPatchCondition>]
|
39
|
+
def headers
|
40
|
+
@_headers ||= []
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Array<Contrast::Agent::Reporting::Settings::VirtualPatchCondition>]
|
44
|
+
def parameters
|
45
|
+
@_parameters ||= []
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Array<Contrast::Agent::Reporting::Settings::VirtualPatchCondition>]
|
49
|
+
def urls
|
50
|
+
@_urls ||= []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/object_share'
|
5
|
+
require 'contrast/agent/reporting/settings/protect_rule'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Agent
|
9
|
+
module Reporting
|
10
|
+
module Settings
|
11
|
+
# The settings for each virtual patch condition in the agent.
|
12
|
+
class VirtualPatchCondition
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :name
|
15
|
+
# @return [String]
|
16
|
+
attr_reader :value
|
17
|
+
# @return [String]
|
18
|
+
attr_reader :input_type
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :evaluation
|
21
|
+
|
22
|
+
def initialize hash
|
23
|
+
@name = hash[:name]
|
24
|
+
@value = hash[:value]
|
25
|
+
@input_type = hash[:input_type]
|
26
|
+
@evaluation = hash[:evaluation]
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Array<Contrast::Agent::Reporting::Settings::VirtualPatchCondition>]
|
30
|
+
def headers
|
31
|
+
@_headers ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Array<Contrast::Agent::Reporting::Settings::VirtualPatchCondition>]
|
35
|
+
def parameters
|
36
|
+
@_parameters ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Array<Contrast::Agent::Reporting::Settings::VirtualPatchCondition>]
|
40
|
+
def urls
|
41
|
+
@_urls ||= []
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -76,6 +76,7 @@ module Contrast
|
|
76
76
|
@_normalized_uri ||= begin
|
77
77
|
path = rack_request.path_info || rack_request.path.to_s
|
78
78
|
path = '/' if path.empty?
|
79
|
+
|
79
80
|
uri = path.split(Contrast::Utils::ObjectShare::SEMICOLON)[0] # remove ;jsessionid
|
80
81
|
uri = uri.split(Contrast::Utils::ObjectShare::QUESTION_MARK)[0] # remove ?query_string=
|
81
82
|
uri.gsub(INNER_REST_TOKEN, INNER_NUMBER_MARKER) # replace interior tokens
|
@@ -50,6 +50,10 @@ module Contrast
|
|
50
50
|
return false if @do_not_track
|
51
51
|
|
52
52
|
if (ia = Contrast::Agent::Protect::InputAnalyzer.analyse(request))
|
53
|
+
# Handle prefilter
|
54
|
+
Contrast::Agent::Protect::InputAnalyzer.input_classification(ia, prefilter: true)
|
55
|
+
# Reflected xss infilter
|
56
|
+
Contrast::Agent::Protect::InputAnalyzer.input_classification_for('reflected-xss', ia)
|
53
57
|
@agent_input_analysis = ia
|
54
58
|
else
|
55
59
|
logger.trace('Analysis from Agent was empty.')
|
@@ -60,6 +64,22 @@ module Contrast
|
|
60
64
|
logger.warn('Unable to extract protect information from request', e)
|
61
65
|
end
|
62
66
|
|
67
|
+
# Builds IA only for postfilter rules. If rules during infilter were not triggered there will be
|
68
|
+
# no IA for them later to use it in postfilter.
|
69
|
+
#
|
70
|
+
# @raise [Contrast::SecurityException]
|
71
|
+
def protect_postfilter_ia
|
72
|
+
return false unless ::Contrast::AGENT.enabled?
|
73
|
+
return false unless ::Contrast::PROTECT.enabled?
|
74
|
+
|
75
|
+
# Handle postfilter
|
76
|
+
Contrast::Agent::Protect::InputAnalyzer.input_classification(@agent_input_analysis, postfilter: true)
|
77
|
+
rescue Contrast::SecurityException => e
|
78
|
+
raise(e)
|
79
|
+
rescue StandardError => e
|
80
|
+
logger.warn('Unable to extract protect information from request - postfilter', e)
|
81
|
+
end
|
82
|
+
|
63
83
|
# append anything we've learned to the request seen message this is the sum-total of all inventory information
|
64
84
|
# that has been accumulated since the last request
|
65
85
|
def extract_after rack_response
|
@@ -21,18 +21,13 @@ module Contrast
|
|
21
21
|
@ruleset = ::Contrast::AGENT.ruleset
|
22
22
|
end
|
23
23
|
|
24
|
-
# reports events[Contrast::Agent::Reporting::
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
def report_activity
|
24
|
+
# reports events[Contrast::Agent::Reporting::ObservedRoute] to TS
|
25
|
+
# Other ReportingEvents are handled through batching in the middleware
|
26
|
+
#
|
27
|
+
def report_observed_route
|
29
28
|
return unless (reporter = Contrast::Agent.reporter)
|
30
29
|
|
31
|
-
reporter.send_event(context.observed_route)
|
32
|
-
# Mask Sensitive Data
|
33
|
-
Contrast::Agent::Reporting::Masker.mask(context.activity)
|
34
|
-
event = context.activity
|
35
|
-
reporter.send_event(event)
|
30
|
+
reporter.send_event(context.observed_route) if Contrast::ROUTES_SENT.sendable?(context.observed_route)
|
36
31
|
end
|
37
32
|
|
38
33
|
# If the response is streaming, we should only perform filtering on our stream safe rules
|
@@ -48,7 +48,8 @@ module Contrast
|
|
48
48
|
@_client = Contrast::Utils::TelemetryClient.new
|
49
49
|
ip_opt_out_telemetry = @_client.initialize_connection(URL)
|
50
50
|
if ip_opt_out_telemetry.nil?
|
51
|
-
logger.warn("Connection was not established properly!!! \n
|
51
|
+
logger.warn("[Telemetry] Connection was not established properly!!! \n
|
52
|
+
Telemetry reporting will be disabled!")
|
52
53
|
return false
|
53
54
|
end
|
54
55
|
|
@@ -66,30 +67,30 @@ module Contrast
|
|
66
67
|
|
67
68
|
def attempt_to_start?
|
68
69
|
unless cs__class.enabled?
|
69
|
-
logger.
|
70
|
+
logger.info('[Telemetry] Telemetry service is disabled!')
|
70
71
|
return false
|
71
72
|
end
|
72
73
|
|
73
|
-
logger.debug('Attempting to start telemetry thread') unless running?
|
74
|
+
logger.debug('[Telemetry] Attempting to start telemetry thread') unless running?
|
74
75
|
true
|
75
76
|
end
|
76
77
|
|
77
78
|
def start_thread!
|
78
79
|
return if running?
|
79
80
|
|
80
|
-
logger.debug('Starting background telemetry thread.')
|
81
|
+
logger.debug('[Telemetry] Starting background telemetry thread.')
|
81
82
|
@_thread = create_thread
|
82
83
|
end
|
83
84
|
|
84
85
|
def send_event event
|
85
86
|
if ::Contrast::AGENT.disabled?
|
86
|
-
logger.warn('Attempted to queue event with Agent disabled', caller: caller, event: event)
|
87
|
+
logger.warn('[Telemetry] Attempted to queue event with Agent disabled', caller: caller, event: event)
|
87
88
|
return
|
88
89
|
end
|
89
90
|
|
90
91
|
return unless cs__class.enabled?
|
91
92
|
|
92
|
-
logger.debug('Enqueued event for sending', event_type: event.cs__class)
|
93
|
+
logger.debug('[Telemetry] Enqueued event for sending', event_type: event.cs__class)
|
93
94
|
queue << event if event
|
94
95
|
end
|
95
96
|
|
@@ -120,7 +121,7 @@ module Contrast
|
|
120
121
|
# It is recommended that implementations send a single payload of general metrics every 3 hours, starting from
|
121
122
|
# implementation startup. This returns a thread configured to do so.
|
122
123
|
#
|
123
|
-
# @return [Contrast::Agent::Thread
|
124
|
+
# @return [::Thread] Contrast::Agent::Thread
|
124
125
|
def create_thread
|
125
126
|
Contrast::Agent::Thread.new do
|
126
127
|
loop do
|
@@ -132,16 +133,16 @@ module Contrast
|
|
132
133
|
until queue.empty?
|
133
134
|
event = queue.pop
|
134
135
|
begin
|
135
|
-
logger.debug('This is the current processed event', event)
|
136
|
+
logger.debug('[Telemetry] This is the current processed event', event)
|
136
137
|
sleep_time = request_with_response(event)
|
137
138
|
if sleep_time
|
138
139
|
sleep(sleep_time)
|
139
|
-
logger.debug('Retrying to process event', event)
|
140
|
+
logger.debug('[Telemetry] Retrying to process event', event)
|
140
141
|
retry_sleep_time = request_with_response(event)
|
141
142
|
sleep(retry_sleep_time) unless retry_sleep_time.nil?
|
142
143
|
end
|
143
144
|
rescue StandardError => e
|
144
|
-
logger.error('Could not send message to service from telemetry queue.', e)
|
145
|
+
logger.error('[Telemetry] Could not send message to service from telemetry queue.', e)
|
145
146
|
stop!
|
146
147
|
end
|
147
148
|
end
|