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
@@ -0,0 +1,114 @@
|
|
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 'json'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'contrast/utils/timer'
|
7
|
+
require 'contrast/utils/log_utils'
|
8
|
+
require 'contrast/components/logger'
|
9
|
+
require 'contrast/utils/object_share'
|
10
|
+
require 'contrast/config/config'
|
11
|
+
require 'contrast/config/effective_config'
|
12
|
+
require 'contrast/config/effective_config_value'
|
13
|
+
|
14
|
+
module Contrast
|
15
|
+
module Agent
|
16
|
+
module DiagnosticsConfig
|
17
|
+
# This class is responsible for logging to file the effective Agent configurations after startup.
|
18
|
+
class Diagnostics
|
19
|
+
include Contrast::Components::Logger::InstanceMethods
|
20
|
+
include Contrast::Utils::LogUtils
|
21
|
+
|
22
|
+
# @return [String] path to write the file.
|
23
|
+
attr_reader :path
|
24
|
+
|
25
|
+
DEFAULT_PATH = File.join(Dir.pwd).cs__freeze
|
26
|
+
ERROR_MESSAGE = '[Configuration Diagnostics] Could not write effective Agent configuration to file'
|
27
|
+
FILE_NAME = 'contrast_connection.json'
|
28
|
+
WRITE = 'w+'
|
29
|
+
|
30
|
+
# @param path [String] path to write to file.
|
31
|
+
def initialize path
|
32
|
+
@path = path if path && !path.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
# Write current settings to file.
|
36
|
+
#
|
37
|
+
# @param reset [Boolean] should we reset the config we have
|
38
|
+
# @return [Boolean]
|
39
|
+
def write_to_file reset: true
|
40
|
+
logger&.info('[Configuration Diagnostics] Writing Effective Configurations to file', path: dir_name)
|
41
|
+
status = false
|
42
|
+
write_to_file_logic(status, reset: reset)
|
43
|
+
rescue IOError => e
|
44
|
+
logger&.warn(ERROR_MESSAGE, e)
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
def extract_settings
|
49
|
+
Contrast::AGENT.to_effective_config(config.effective_config)
|
50
|
+
Contrast::API.to_effective_config(config.effective_config)
|
51
|
+
Contrast::APP_CONTEXT.to_effective_config(config.effective_config)
|
52
|
+
Contrast::ASSESS.to_effective_config(config.effective_config)
|
53
|
+
Contrast::INVENTORY.to_effective_config(config.effective_config)
|
54
|
+
Contrast::PROTECT.to_effective_config(config.effective_config)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Determine the path of the current logger and permissions required for
|
58
|
+
# writing to path.
|
59
|
+
#
|
60
|
+
# @return [String] Path
|
61
|
+
def dir_name
|
62
|
+
@_dir_name ||= if write_permission?(@path)
|
63
|
+
File.dirname(File.absolute_path(@path))
|
64
|
+
else
|
65
|
+
DEFAULT_PATH
|
66
|
+
end
|
67
|
+
rescue Errno::EROFS => e
|
68
|
+
logger.warn(ERROR_MESSAGE, e)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns effective configurations of the agent.
|
72
|
+
#
|
73
|
+
# @return [Contrast::Agent::DiagnosticsConfig::Config]
|
74
|
+
def config
|
75
|
+
@_config ||= Contrast::Agent::DiagnosticsConfig::Config.new
|
76
|
+
end
|
77
|
+
|
78
|
+
# Reset the state of the current effective config.
|
79
|
+
def reset_config
|
80
|
+
@_config = Contrast::Agent::DiagnosticsConfig::Config.new
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_controlled_hash
|
84
|
+
{
|
85
|
+
ReportCreate: report_create_time,
|
86
|
+
Config: config.to_controlled_hash
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def write_to_file_logic status, reset: true
|
91
|
+
# We need to reset the config before updating it's values
|
92
|
+
reset_config if reset
|
93
|
+
extract_settings
|
94
|
+
File.open(File.join(dir_name, FILE_NAME), WRITE) do |file|
|
95
|
+
file.truncate(0)
|
96
|
+
file.write(JSON.pretty_generate(to_controlled_hash, { space: Contrast::Utils::ObjectShare::EMPTY_STRING }))
|
97
|
+
status = true if file
|
98
|
+
file.close
|
99
|
+
end
|
100
|
+
status
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
# Return current time in iso8601 format.
|
106
|
+
#
|
107
|
+
# @return [String] Time of creation
|
108
|
+
def report_create_time
|
109
|
+
Contrast::Utils::Timer.time_now
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,98 @@
|
|
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
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module DiagnosticsConfig
|
9
|
+
# Diagnostics tools to be included in config components.
|
10
|
+
module DiagnosticsTools
|
11
|
+
CHECK = 'd'
|
12
|
+
|
13
|
+
# Converts current configuration for array of values to effective config values class and appends them to
|
14
|
+
# EffectiveConfig class. Must be used inside Config Components only.
|
15
|
+
#
|
16
|
+
# @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
|
17
|
+
# @param config_values [Array<String>] array of the names of values.
|
18
|
+
# @param canonical_prefix [String] starting of the path to config => api.proxy...
|
19
|
+
# @param name_prefix [String] the name of the config prefix => contrast.api_key, contrast.url
|
20
|
+
def add_effective_config_values effective_config, config_values, canonical_prefix, name_prefix
|
21
|
+
return if config_values.to_s.empty?
|
22
|
+
|
23
|
+
config_values.each do |config|
|
24
|
+
Contrast::Agent::DiagnosticsConfig::EffectiveConfigValue.new.tap do |value|
|
25
|
+
next if (config_val = send(config.to_sym)).to_s.empty?
|
26
|
+
|
27
|
+
config_name = assign_name(config)
|
28
|
+
value.canonical_name = "#{ canonical_prefix }.#{ config_name }"
|
29
|
+
value.name = "#{ name_prefix }.#{ config_name }"
|
30
|
+
value.value = config_val
|
31
|
+
value.source = Contrast::CONFIG.sources.get(value.canonical_name)
|
32
|
+
if value.source == Contrast::Components::Config::Sources::YAML
|
33
|
+
value.filename = Contrast::CONFIG.config_file_path
|
34
|
+
end
|
35
|
+
effective_config.values << value
|
36
|
+
rescue StandardError => e
|
37
|
+
log_error(e)
|
38
|
+
next
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Converts current configuration for single value to effective config values class and appends them to
|
44
|
+
# EffectiveConfig class. Must be used inside Config Components only.
|
45
|
+
#
|
46
|
+
# @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
|
47
|
+
# @param config_name [String] name of the config.
|
48
|
+
# @param config_value [String, Boolean] value of the config.
|
49
|
+
# @param canonical_prefix [String] starting of the path to config => api.proxy...
|
50
|
+
# @param name_prefix [String] the name of the config prefix => contrast.api_key, contrast.url
|
51
|
+
def add_single_effective_value effective_config, config_name, config_value, canonical_prefix, name_prefix
|
52
|
+
Contrast::Agent::DiagnosticsConfig::EffectiveConfigValue.new.tap do |value|
|
53
|
+
break if config_value.to_s.empty?
|
54
|
+
|
55
|
+
value.value = config_value
|
56
|
+
value.canonical_name = "#{ canonical_prefix }.#{ config_name }"
|
57
|
+
value.name = "#{ name_prefix }.#{ config_name }"
|
58
|
+
value.source = Contrast::CONFIG.sources.get(value.canonical_name)
|
59
|
+
if value.source == Contrast::Components::Config::Sources::YAML
|
60
|
+
value.filename = Contrast::CONFIG.config_file_path
|
61
|
+
end
|
62
|
+
effective_config.values << value
|
63
|
+
rescue StandardError => e
|
64
|
+
log_error(e)
|
65
|
+
next
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Assigns a proper name for the config removing '?' out of method names.
|
72
|
+
#
|
73
|
+
# @param config [String] name of the configuration
|
74
|
+
# @return [String]
|
75
|
+
def assign_name config
|
76
|
+
return Contrast::Utils::ObjectShare::EMPTY_STRING unless config
|
77
|
+
|
78
|
+
name = config.dup
|
79
|
+
if name.end_with?(Contrast::Utils::ObjectShare::QUESTION_MARK)
|
80
|
+
# check and remove '?' : start_bundled_service? => start_bundled_service
|
81
|
+
name.delete!(Contrast::Utils::ObjectShare::QUESTION_MARK)
|
82
|
+
name.chop! if name.end_with?(CHECK)
|
83
|
+
name
|
84
|
+
end
|
85
|
+
name
|
86
|
+
end
|
87
|
+
|
88
|
+
# Logs any caught error.
|
89
|
+
#
|
90
|
+
# @param error [StandardError]
|
91
|
+
def log_error error
|
92
|
+
Contrast::CONFIG.proto_logger.warn('Could not write effective config to file: ',
|
93
|
+
error: error, backtrace: error.backtrace)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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/config/effective_config_value'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module DiagnosticsConfig
|
9
|
+
# The current effective config received from all authorized configuration channels.
|
10
|
+
class EffectiveConfig
|
11
|
+
# Value of effective agent configurations
|
12
|
+
#
|
13
|
+
# @return [Array]
|
14
|
+
attr_reader :values
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@values = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_controlled_hash
|
21
|
+
{
|
22
|
+
EffectiveConfig: { values: @values&.map(&:to_controlled_hash) },
|
23
|
+
File: yaml_config_settings,
|
24
|
+
Environment: environment_settings,
|
25
|
+
CommandLine: command_line_settings,
|
26
|
+
ContrastUI: contrast_ui_settings
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def yaml_config_settings
|
33
|
+
{
|
34
|
+
Path: Contrast::CONFIG.config_file_path,
|
35
|
+
Values: Contrast::CONFIG.sources.for(Contrast::Components::Config::Sources::YAML)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def command_line_settings
|
40
|
+
flatten_settings(Contrast::CONFIG.sources.for(Contrast::Components::Config::Sources::CLI))
|
41
|
+
end
|
42
|
+
|
43
|
+
def contrast_ui_settings
|
44
|
+
flatten_settings(Contrast::CONFIG.sources.for(Contrast::Components::Config::Sources::CONTRASTUI))
|
45
|
+
end
|
46
|
+
|
47
|
+
def flatten_settings data, path = []
|
48
|
+
data.each_with_object([]) do |(k, v), entries|
|
49
|
+
if v.cs__is_a?(Hash)
|
50
|
+
entries.concat(flatten_settings(v, path.dup.append(k.to_sym)))
|
51
|
+
else
|
52
|
+
entries << { "#{ path.join('.') }.#{ k }" => Contrast::CONFIG.config.loaded_config.dig(*path, k) }
|
53
|
+
end
|
54
|
+
end.flatten # rubocop:disable Style/MethodCalledOnDoEndBlock
|
55
|
+
end
|
56
|
+
|
57
|
+
def environment_settings
|
58
|
+
ENV.select { |e| e.to_s.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) }.
|
59
|
+
to_a.
|
60
|
+
map { |e| Hash[*e] }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Contrast
|
5
|
+
module Agent
|
6
|
+
module DiagnosticsConfig
|
7
|
+
# All In effect config values stored in a easy to write representation.
|
8
|
+
class EffectiveConfigValue
|
9
|
+
# @return [String] Name of the config starting form root of yaml config.
|
10
|
+
attr_accessor :canonical_name
|
11
|
+
# @return [String] Name of the config.
|
12
|
+
attr_accessor :name
|
13
|
+
# @return [String] Value set for the config.
|
14
|
+
attr_accessor :value
|
15
|
+
# @return [String] The source for the entry in the config.
|
16
|
+
attr_accessor :source
|
17
|
+
# @return [String,nil] The filename for the source of the config, if the source was "yaml".
|
18
|
+
attr_accessor :filename
|
19
|
+
|
20
|
+
def to_controlled_hash
|
21
|
+
{
|
22
|
+
canonical_name: canonical_name,
|
23
|
+
name: name, # rubocop:disable Security/Module/Name
|
24
|
+
value: value,
|
25
|
+
Source: source,
|
26
|
+
Filename: filename
|
27
|
+
}.compact
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,20 +1,32 @@
|
|
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/components/base'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Config
|
6
8
|
# Common Configuration settings. Those in this section pertain to the exception handling in Ruby, allowing for the
|
7
9
|
# override of Response Code and Message when Security Exceptions are raised.
|
8
10
|
class ExceptionConfiguration
|
9
11
|
include Contrast::Config::BaseConfiguration
|
12
|
+
include Contrast::Components::ComponentBase
|
13
|
+
|
14
|
+
CANON_NAME = 'agent.ruby.exception'
|
15
|
+
CONFIG_VALUES = %w[capture override_status override_message].cs__freeze
|
10
16
|
|
11
17
|
# @return [Integer] the HTTP status code override
|
12
18
|
attr_accessor :override_status
|
13
19
|
# @return [String] the message text override
|
14
20
|
attr_accessor :override_message
|
15
21
|
attr_writer :capture
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :canon_name
|
24
|
+
# @return [Array]
|
25
|
+
attr_reader :config_values
|
16
26
|
|
17
27
|
def initialize hsh = {}
|
28
|
+
@config_values = CONFIG_VALUES
|
29
|
+
@canon_name = CANON_NAME
|
18
30
|
return unless hsh
|
19
31
|
|
20
32
|
@capture = hsh[:capture]
|
@@ -36,11 +36,11 @@ module Contrast
|
|
36
36
|
# String to its recognized symbol equivalent. If a nonsense value is provided, it'll
|
37
37
|
# be treated the same as disabling the rule.
|
38
38
|
#
|
39
|
-
# @return [Symbol]
|
39
|
+
# @return [Symbol, nil]
|
40
40
|
def applicable_mode
|
41
41
|
return unless mode
|
42
42
|
|
43
|
-
case mode
|
43
|
+
case mode.downcase
|
44
44
|
when 'permit'
|
45
45
|
:PERMIT
|
46
46
|
when 'block_at_perimeter'
|
@@ -11,13 +11,13 @@ module Contrast
|
|
11
11
|
|
12
12
|
attr_accessor :disabled_rules
|
13
13
|
attr_reader :bot_blocker,
|
14
|
-
:cmd_injection, :
|
14
|
+
:cmd_injection, :cmd_injection_command_backdoors,
|
15
15
|
:cmd_injection_semantic_chained_commands, :cmd_injection_semantic_dangerous_paths,
|
16
16
|
:method_tampering,
|
17
17
|
:nosql_injection,
|
18
18
|
:path_traversal, :path_traversal_semantic_file_security_bypass,
|
19
19
|
:reflected_xss,
|
20
|
-
:sql_injection, :
|
20
|
+
:sql_injection, :sql_injection_semantic_dangerous_functions,
|
21
21
|
:unsafe_file_upload,
|
22
22
|
:untrusted_deserialization,
|
23
23
|
:xxe,
|
@@ -28,15 +28,16 @@ module Contrast
|
|
28
28
|
def initialize hsh = {} # rubocop:disable Metrics/AbcSize
|
29
29
|
return unless hsh
|
30
30
|
|
31
|
+
# IVs must be with the same name as rule_id
|
31
32
|
@disabled_rules = hsh[:disabled_rules]
|
32
33
|
@rule_base = Contrast::Config::ProtectRuleConfiguration.new(hsh[BASE_RULE.to_sym])
|
33
34
|
@bot_blocker = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'bot-blocker'])
|
34
35
|
@cmd_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection'])
|
35
|
-
@
|
36
|
+
@cmd_injection_command_backdoors =
|
36
37
|
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-command-backdoors'])
|
37
|
-
@
|
38
|
+
@cmd_injection_semantic_chained_commands =
|
38
39
|
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-chained-commands'])
|
39
|
-
@
|
40
|
+
@cmd_injection_semantic_dangerous_paths =
|
40
41
|
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-dangerous-paths'])
|
41
42
|
@method_tampering = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'method-tampering'])
|
42
43
|
@nosql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'nosql-injection'])
|
@@ -45,7 +46,7 @@ module Contrast
|
|
45
46
|
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal-semantic-file-security-bypass'])
|
46
47
|
@reflected_xss = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'reflected-xss'])
|
47
48
|
@sql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection'])
|
48
|
-
@
|
49
|
+
@sql_injection_semantic_dangerous_functions =
|
49
50
|
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection-semantic-dangerous-functions'])
|
50
51
|
@unsafe_file_upload = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'unsafe-file-upload'])
|
51
52
|
@untrusted_deserialization = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'untrusted-deserialization'])
|
@@ -1,13 +1,18 @@
|
|
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/components/base'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Config
|
6
8
|
# This class holds the Common Settings for the hidden functionality of the TS
|
7
9
|
class RequestAuditConfiguration
|
8
10
|
include Contrast::Config::BaseConfiguration
|
11
|
+
include Contrast::Components::ComponentBase
|
9
12
|
|
10
13
|
DEFAULT_PATH = './messages'
|
14
|
+
CANON_NAME = 'api.request_audit'
|
15
|
+
CONFIG_VALUES = %w[enable requests responses path].cs__freeze
|
11
16
|
|
12
17
|
attr_writer :enable, :requests, :responses, :path
|
13
18
|
|
@@ -39,6 +44,14 @@ module Contrast
|
|
39
44
|
def path
|
40
45
|
@path.nil? ? DEFAULT_PATH : @path
|
41
46
|
end
|
47
|
+
|
48
|
+
# Converts current configuration to effective config values class and appends them to
|
49
|
+
# EffectiveConfig class.
|
50
|
+
#
|
51
|
+
# @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
|
52
|
+
def to_effective_config effective_config
|
53
|
+
add_effective_config_values(effective_config, CONFIG_VALUES, CANON_NAME, "#{ CONTRAST }.#{ CANON_NAME }")
|
54
|
+
end
|
42
55
|
end
|
43
56
|
end
|
44
57
|
end
|
@@ -1,12 +1,18 @@
|
|
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/config/base_configuration'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Config
|
6
8
|
# Common Configuration settings. Those in this section pertain to the server identification functionality of the
|
7
9
|
# Agent.
|
8
10
|
class ServerConfiguration
|
9
11
|
include Contrast::Config::BaseConfiguration
|
12
|
+
include Contrast::Components::ComponentBase
|
13
|
+
|
14
|
+
CANON_NAME = 'server'
|
15
|
+
CONFIG_VALUES = %w[tags environment version].cs__freeze
|
10
16
|
|
11
17
|
# @return [String, nil]
|
12
18
|
attr_reader :name
|
@@ -14,14 +20,19 @@ module Contrast
|
|
14
20
|
attr_accessor :path
|
15
21
|
# @return [String, nil]
|
16
22
|
attr_accessor :type
|
17
|
-
|
18
|
-
attr_accessor :tags
|
23
|
+
attr_writer :tags
|
19
24
|
# @return [String, nil]
|
20
25
|
attr_accessor :environment
|
21
26
|
# @return [String, nil]
|
22
27
|
attr_accessor :version
|
28
|
+
# @return [String]
|
29
|
+
attr_reader :canon_name
|
30
|
+
# @return [Array]
|
31
|
+
attr_reader :config_values
|
23
32
|
|
24
33
|
def initialize hsh = {}
|
34
|
+
@config_values = CONFIG_VALUES
|
35
|
+
@canon_name = CANON_NAME
|
25
36
|
return unless hsh
|
26
37
|
|
27
38
|
@path = hsh[:path]
|
@@ -31,6 +42,34 @@ module Contrast
|
|
31
42
|
@environment = hsh[:environment]
|
32
43
|
@version = hsh[:version]
|
33
44
|
end
|
45
|
+
|
46
|
+
# @return [String, nil]
|
47
|
+
def tags
|
48
|
+
stringify_array(@tags)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Converts current configuration to effective config values class and appends them to
|
52
|
+
# EffectiveConfig class.
|
53
|
+
#
|
54
|
+
# @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
|
55
|
+
def to_effective_config effective_config
|
56
|
+
super
|
57
|
+
add_single_effective_value(effective_config,
|
58
|
+
'type',
|
59
|
+
Contrast::APP_CONTEXT.server_type,
|
60
|
+
CANON_NAME,
|
61
|
+
"#{ CONTRAST }.#{ CANON_NAME }")
|
62
|
+
add_single_effective_value(effective_config,
|
63
|
+
'name',
|
64
|
+
Contrast::APP_CONTEXT.server_name,
|
65
|
+
CANON_NAME,
|
66
|
+
"#{ CONTRAST }.#{ CANON_NAME }")
|
67
|
+
add_single_effective_value(effective_config,
|
68
|
+
'path',
|
69
|
+
Contrast::APP_CONTEXT.server_path,
|
70
|
+
CANON_NAME,
|
71
|
+
"#{ CONTRAST }.#{ CANON_NAME }")
|
72
|
+
end
|
34
73
|
end
|
35
74
|
end
|
36
75
|
end
|
@@ -13,6 +13,7 @@ require 'contrast/components/scope'
|
|
13
13
|
require 'contrast/components/inventory'
|
14
14
|
require 'contrast/components/protect'
|
15
15
|
require 'contrast/components/assess'
|
16
|
+
require 'contrast/components/config/sources'
|
16
17
|
require 'contrast/config/server_configuration'
|
17
18
|
|
18
19
|
module Contrast
|
@@ -45,6 +46,12 @@ module Contrast
|
|
45
46
|
attr_writer :protect
|
46
47
|
# @return [Boolean, nil]
|
47
48
|
attr_accessor :enable
|
49
|
+
# @return [Hash]
|
50
|
+
attr_accessor :loaded_config
|
51
|
+
# @return [Contrast::Config::Sources]
|
52
|
+
attr_accessor :sources
|
53
|
+
# @return [String,nil]
|
54
|
+
attr_reader :config_file
|
48
55
|
|
49
56
|
DEFAULT_YAML_PATH = 'contrast_security.yaml'
|
50
57
|
MILLISECOND_MARKER = '_ms'
|
@@ -53,18 +60,26 @@ module Contrast
|
|
53
60
|
KEYS_TO_REDACT = %i[api_key url service_key user_name].cs__freeze
|
54
61
|
REDACTED = '**REDACTED**'
|
55
62
|
|
56
|
-
def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH
|
63
|
+
def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH # rubocop:disable Metrics/AbcSize
|
57
64
|
@default_name = default_name
|
58
65
|
|
59
66
|
# Load config_kv from file
|
60
67
|
config_kv = deep_symbolize_all_keys(load_config)
|
68
|
+
config_sources = assign_source_to(config_kv, Contrast::Components::Config::Sources::YAML)
|
61
69
|
|
62
70
|
# Overlay CLI options - they take precedence over config file
|
63
71
|
cli_options = deep_symbolize_all_keys(cli_options)
|
64
|
-
|
72
|
+
if cli_options
|
73
|
+
config_kv = deep_merge(cli_options, config_kv)
|
74
|
+
config_sources = deep_merge(assign_source_to(cli_options, Contrast::Components::Config::Sources::CLI),
|
75
|
+
config_sources)
|
76
|
+
end
|
65
77
|
|
66
78
|
# Some in-flight rewrites to maintain backwards compatibility
|
67
79
|
config_kv = update_prop_keys(config_kv)
|
80
|
+
@loaded_config = config_kv
|
81
|
+
|
82
|
+
@sources = Contrast::Components::Config::Sources.new(config_sources)
|
68
83
|
|
69
84
|
@api = Contrast::Components::Api::Interface.new(config_kv[:api])
|
70
85
|
@enable = config_kv[:enable]
|
@@ -132,6 +147,7 @@ module Contrast
|
|
132
147
|
next
|
133
148
|
end
|
134
149
|
config = yaml_to_hash(path) || {}
|
150
|
+
@config_file = path
|
135
151
|
break
|
136
152
|
end
|
137
153
|
|
@@ -307,5 +323,15 @@ module Contrast
|
|
307
323
|
def redactable? key
|
308
324
|
KEYS_TO_REDACT.include?(key.to_sym)
|
309
325
|
end
|
326
|
+
|
327
|
+
def assign_source_to hash, source = Contrast::Components::Config::Sources::YAML
|
328
|
+
hash.transform_values do |value|
|
329
|
+
if value.is_a?(Hash)
|
330
|
+
assign_source_to(value, source)
|
331
|
+
else
|
332
|
+
source
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
310
336
|
end
|
311
337
|
end
|
@@ -13,10 +13,10 @@ module Contrast
|
|
13
13
|
# This is our patch of the Array class required to handle propagation
|
14
14
|
# Disclaimer: there may be a better way, but we're in a 'get it work' state.
|
15
15
|
# Hopefully, we'll be in a 'get it right' state soon.
|
16
|
-
class ArrayPropagator
|
16
|
+
class ArrayPropagator
|
17
17
|
extend Contrast::Components::Scope::InstanceMethods
|
18
18
|
|
19
|
-
ARRAY_JOIN_HASH
|
19
|
+
ARRAY_JOIN_HASH ||= { # rubocop:disable Lint/OrAssignmentToConstant
|
20
20
|
'class_name' => 'Array',
|
21
21
|
'instance_method' => true,
|
22
22
|
'method_visibility' => 'public',
|
@@ -27,7 +27,7 @@ module Contrast
|
|
27
27
|
'patch_class' => 'NOOP',
|
28
28
|
'patch_method' => 'cs__track_join'
|
29
29
|
}.cs__freeze
|
30
|
-
ARRAY_JOIN_NODE
|
30
|
+
ARRAY_JOIN_NODE ||= Contrast::Agent::Assess::Policy::PropagationNode.new(ARRAY_JOIN_HASH) # rubocop:disable Lint/OrAssignmentToConstant
|
31
31
|
|
32
32
|
class << self
|
33
33
|
# When you call join, they use an internal thing, so there's no good way to get at the thing being returned.
|
@@ -39,7 +39,7 @@ module ERBPropagator
|
|
39
39
|
# @param used_binding [Binding] the binding in of the current event, saved as preshift argument
|
40
40
|
# @param erb_pre_result [String] the source saved in the preshift
|
41
41
|
# @param properties [Contrast::Agent::Assess::Properties] properties of the target if none create new
|
42
|
-
# @param parent_events [Array<Contrast::Agent::
|
42
|
+
# @param parent_events [Array<Contrast::Agent::Reporting::FindingEvent>] parents event extracted from the source
|
43
43
|
# properties
|
44
44
|
# @param ret [String] the Return of the invoked method
|
45
45
|
# @return [Array<Symbol>]
|
@@ -17,7 +17,7 @@ module Contrast
|
|
17
17
|
extend Contrast::Components::Logger::InstanceMethods
|
18
18
|
extend Contrast::Components::Scope::InstanceMethods
|
19
19
|
|
20
|
-
REGEXP_EQUAL_SQUIGGLE_HASH
|
20
|
+
REGEXP_EQUAL_SQUIGGLE_HASH ||= { # rubocop:disable Lint/OrAssignmentToConstant
|
21
21
|
'id' => 'regexp_100',
|
22
22
|
'class_name' => 'Regexp',
|
23
23
|
'instance_method' => true,
|
@@ -29,7 +29,7 @@ module Contrast
|
|
29
29
|
'patch_class' => 'Contrast::Extension::Assess::RegexpPropagator',
|
30
30
|
'patch_method' => 'track_equal_squiggle'
|
31
31
|
}.cs__freeze
|
32
|
-
REGEXP_EQUAL_SQUIGGLE_NODE
|
32
|
+
REGEXP_EQUAL_SQUIGGLE_NODE ||= Contrast::Agent::Assess::Policy::PropagationNode.new(REGEXP_EQUAL_SQUIGGLE_HASH) # rubocop:disable Lint/OrAssignmentToConstant
|
33
33
|
private_constant :REGEXP_EQUAL_SQUIGGLE_HASH
|
34
34
|
private_constant :REGEXP_EQUAL_SQUIGGLE_NODE
|
35
35
|
|