contrast-agent 4.11.0 → 4.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -0
- data/ext/cs__assess_module/cs__assess_module.c +48 -0
- data/ext/cs__assess_module/cs__assess_module.h +7 -0
- data/ext/cs__common/cs__common.c +24 -7
- data/ext/cs__common/cs__common.h +12 -2
- data/ext/cs__contrast_patch/cs__contrast_patch.c +48 -11
- data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -2
- data/ext/cs__os_information/cs__os_information.c +31 -0
- data/ext/cs__os_information/cs__os_information.h +7 -0
- data/ext/{cs__protect_kernel → cs__os_information}/extconf.rb +0 -0
- data/lib/contrast/agent/assess/contrast_event.rb +1 -1
- data/lib/contrast/agent/assess/contrast_object.rb +1 -1
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +6 -6
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +5 -0
- data/lib/contrast/agent/assess/policy/preshift.rb +19 -6
- data/lib/contrast/agent/assess/policy/propagation_method.rb +2 -116
- data/lib/contrast/agent/assess/policy/propagation_node.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +2 -0
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -154
- data/lib/contrast/agent/assess/policy/source_method.rb +2 -71
- data/lib/contrast/agent/assess/policy/trigger_method.rb +45 -110
- data/lib/contrast/agent/assess/policy/trigger_node.rb +62 -21
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/tagged.rb +66 -189
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +40 -6
- data/lib/contrast/agent/deadzone/policy/policy.rb +6 -0
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +1 -0
- data/lib/contrast/agent/metric_telemetry_event.rb +26 -0
- data/lib/contrast/agent/middleware.rb +14 -62
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +0 -1
- data/lib/contrast/agent/patching/policy/method_policy.rb +3 -44
- data/lib/contrast/agent/patching/policy/method_policy_extend.rb +111 -0
- data/lib/contrast/agent/patching/policy/patch.rb +37 -238
- data/lib/contrast/agent/patching/policy/patcher.rb +15 -50
- data/lib/contrast/agent/reporting/report.rb +21 -0
- data/lib/contrast/agent/reporting/reporter.rb +142 -0
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +90 -0
- data/lib/contrast/agent/reporting/reporting_events/preflight.rb +25 -0
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +56 -0
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +37 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +127 -0
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +168 -0
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +66 -0
- data/lib/contrast/agent/request.rb +2 -81
- data/lib/contrast/agent/request_context.rb +18 -126
- data/lib/contrast/agent/request_context_extend.rb +138 -0
- data/lib/contrast/agent/request_handler.rb +7 -3
- data/lib/contrast/agent/response.rb +2 -73
- data/lib/contrast/agent/rule_set.rb +2 -4
- data/lib/contrast/agent/startup_metrics_telemetry_event.rb +94 -0
- data/lib/contrast/agent/static_analysis.rb +5 -3
- data/lib/contrast/agent/telemetry.rb +137 -0
- data/lib/contrast/agent/telemetry_event.rb +33 -0
- data/lib/contrast/agent/thread_watcher.rb +66 -11
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +21 -1
- data/lib/contrast/api/communication/connection_status.rb +10 -7
- data/lib/contrast/api/communication/messaging_queue.rb +37 -3
- data/lib/contrast/api/communication/response_processor.rb +15 -8
- data/lib/contrast/api/communication/service_lifecycle.rb +13 -3
- data/lib/contrast/api/communication/socket.rb +6 -8
- data/lib/contrast/api/communication/socket_client.rb +29 -12
- data/lib/contrast/api/communication/speedracer.rb +37 -1
- data/lib/contrast/api/communication/tcp_socket.rb +4 -3
- data/lib/contrast/api/communication/unix_socket.rb +1 -0
- data/lib/contrast/api/decorators/finding.rb +45 -0
- data/lib/contrast/components/api.rb +90 -0
- data/lib/contrast/components/app_context.rb +10 -41
- data/lib/contrast/components/app_context_extend.rb +78 -0
- data/lib/contrast/components/assess.rb +7 -0
- data/lib/contrast/components/base.rb +23 -0
- data/lib/contrast/components/config.rb +92 -13
- data/lib/contrast/components/contrast_service.rb +11 -0
- data/lib/contrast/components/sampling.rb +2 -2
- data/lib/contrast/config/agent_configuration.rb +1 -1
- data/lib/contrast/config/api_configuration.rb +27 -0
- data/lib/contrast/config/api_proxy_configuration.rb +14 -0
- data/lib/contrast/config/application_configuration.rb +2 -3
- data/lib/contrast/config/assess_configuration.rb +3 -2
- data/lib/contrast/config/base_configuration.rb +17 -28
- data/lib/contrast/config/certification_configuration.rb +15 -0
- data/lib/contrast/config/env_variables.rb +18 -0
- data/lib/contrast/config/heap_dump_configuration.rb +6 -6
- data/lib/contrast/config/inventory_configuration.rb +1 -5
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/config/request_audit_configuration.rb +18 -0
- data/lib/contrast/config/root_configuration.rb +1 -0
- data/lib/contrast/config/ruby_configuration.rb +6 -6
- data/lib/contrast/config/service_configuration.rb +2 -2
- data/lib/contrast/config.rb +1 -1
- data/lib/contrast/configuration.rb +4 -2
- data/lib/contrast/extension/assess/array.rb +5 -7
- data/lib/contrast/framework/manager.rb +22 -44
- data/lib/contrast/framework/manager_extend.rb +50 -0
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +9 -6
- data/lib/contrast/framework/rails/patch/support.rb +31 -29
- data/lib/contrast/framework/rails/railtie.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +2 -1
- data/lib/contrast/logger/application.rb +4 -0
- data/lib/contrast/logger/log.rb +8 -103
- data/lib/contrast/utils/assess/propagation_method_utils.rb +129 -0
- data/lib/contrast/utils/assess/property/tagged_utils.rb +165 -0
- data/lib/contrast/utils/assess/source_method_utils.rb +83 -0
- data/lib/contrast/utils/assess/tracking_util.rb +20 -15
- data/lib/contrast/utils/assess/trigger_method_utils.rb +138 -0
- data/lib/contrast/utils/class_util.rb +65 -54
- data/lib/contrast/utils/exclude_key.rb +20 -0
- data/lib/contrast/utils/findings.rb +62 -0
- data/lib/contrast/utils/hash_digest.rb +10 -73
- data/lib/contrast/utils/hash_digest_extend.rb +86 -0
- data/lib/contrast/utils/head_dump_utils_extend.rb +74 -0
- data/lib/contrast/utils/heap_dump_util.rb +2 -65
- data/lib/contrast/utils/invalid_configuration_util.rb +29 -0
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/log_utils.rb +108 -0
- data/lib/contrast/utils/lru_cache.rb +4 -2
- data/lib/contrast/utils/metrics_hash.rb +59 -0
- data/lib/contrast/utils/middleware_utils.rb +87 -0
- data/lib/contrast/utils/net_http_base.rb +158 -0
- data/lib/contrast/utils/object_share.rb +1 -0
- data/lib/contrast/utils/os.rb +23 -0
- data/lib/contrast/utils/patching/policy/patch_utils.rb +232 -0
- data/lib/contrast/utils/patching/policy/patcher_utils.rb +54 -0
- data/lib/contrast/utils/request_utils.rb +88 -0
- data/lib/contrast/utils/response_utils.rb +97 -0
- data/lib/contrast/utils/substitution_utils.rb +167 -0
- data/lib/contrast/utils/tag_util.rb +9 -9
- data/lib/contrast/utils/telemetry.rb +79 -0
- data/lib/contrast/utils/telemetry_client.rb +90 -0
- data/lib/contrast/utils/telemetry_identifier.rb +130 -0
- data/lib/contrast.rb +19 -1
- data/resources/assess/policy.json +12 -6
- data/resources/deadzone/policy.json +86 -5
- data/ruby-agent.gemspec +7 -6
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +68 -26
- data/ext/cs__protect_kernel/cs__protect_kernel.c +0 -47
- data/ext/cs__protect_kernel/cs__protect_kernel.h +0 -12
- data/lib/contrast/config/default_value.rb +0 -17
- data/lib/contrast/extension/protect/kernel.rb +0 -29
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/utils/env_configuration_item'
|
5
|
+
require 'ougai'
|
5
6
|
require 'contrast/configuration'
|
6
7
|
|
7
8
|
module Contrast
|
@@ -23,17 +24,33 @@ module Contrast
|
|
23
24
|
# time than to silently fail to deliver functionality.
|
24
25
|
module Config
|
25
26
|
CONTRAST_ENV_MARKER = 'CONTRAST__'
|
27
|
+
CONTRAST_LOG = 'contrast_agent.log'
|
28
|
+
CONTRAST_NAME = 'Contrast Agent'
|
26
29
|
|
27
30
|
class Interface # :nodoc:
|
28
31
|
def initialize
|
29
32
|
build
|
30
33
|
end
|
31
34
|
|
32
|
-
|
35
|
+
# Basic logger for handling configuration validation logging
|
36
|
+
# the file to log is determined by the default one or set
|
37
|
+
# by the config file, if that configuration is found
|
38
|
+
def proto_logger
|
39
|
+
@_proto_logger ||= begin
|
40
|
+
@_proto_logger = ::Ougai::Logger.new(logger_path || CONTRAST_LOG)
|
41
|
+
@_proto_logger.progname = CONTRAST_NAME
|
42
|
+
@_proto_logger.level = ::Ougai::Logging::Severity::WARN
|
43
|
+
@_proto_logger.formatter = Contrast::Logger::Format.new
|
44
|
+
@_proto_logger.formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%L%z'
|
45
|
+
@_proto_logger
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def build
|
33
50
|
@_valid = nil
|
34
51
|
@config = Contrast::Configuration.new
|
35
52
|
env_overrides
|
36
|
-
validate
|
53
|
+
validate
|
37
54
|
end
|
38
55
|
alias_method :rebuild, :build
|
39
56
|
|
@@ -43,7 +60,7 @@ module Contrast
|
|
43
60
|
end
|
44
61
|
|
45
62
|
def valid?
|
46
|
-
@_valid = validate
|
63
|
+
@_valid = validate if @_valid.nil?
|
47
64
|
@_valid
|
48
65
|
end
|
49
66
|
|
@@ -59,20 +76,28 @@ module Contrast
|
|
59
76
|
|
60
77
|
SESSION_VARIABLES = 'Invalid configuration. '\
|
61
78
|
"Setting both application.session_id and application.session_metadata is not allowed.\n"
|
62
|
-
|
79
|
+
API_URL = "Invalid configuration. Missing a required connection value 'url' is not set."
|
80
|
+
API_KEY = "Invalid configuration. Missing a required connection value 'api_key' is not set."
|
81
|
+
API_SERVICE_KEY = "Invalid configuration. Missing a required connection value 'service_tag' is not set."
|
82
|
+
API_USERNAME = "Invalid configuration. Missing a required connection value 'user_name' is not set."
|
83
|
+
def validate
|
63
84
|
# The config has information about how to construct the logger.
|
64
85
|
# If the config is invalid, and you want to know about it, then
|
65
86
|
# you have a circular dependency if you try to log it,
|
66
|
-
#
|
87
|
+
# so we use basic proto_logger to do this job.
|
67
88
|
if !session_id.empty? && !session_metadata.empty?
|
68
|
-
|
69
|
-
cs__class.log_error(SESSION_VARIABLES)
|
70
|
-
else
|
71
|
-
puts SESSION_VARIABLES
|
72
|
-
end
|
89
|
+
proto_logger.error(SESSION_VARIABLES)
|
73
90
|
return false
|
74
91
|
end
|
75
|
-
|
92
|
+
if bypass
|
93
|
+
msg = []
|
94
|
+
msg << API_URL unless api_url
|
95
|
+
msg << API_KEY unless api_key
|
96
|
+
msg << API_SERVICE_KEY unless api_service_key
|
97
|
+
msg << API_USERNAME unless api_username
|
98
|
+
msg.any? { |m| proto_logger.error(m) }
|
99
|
+
return false unless msg.empty?
|
100
|
+
end
|
76
101
|
true
|
77
102
|
end
|
78
103
|
|
@@ -95,7 +120,7 @@ module Contrast
|
|
95
120
|
# @return [String,nil] the value of the session id set in the
|
96
121
|
# configuration, or nil if unset
|
97
122
|
def session_id
|
98
|
-
|
123
|
+
root.application.session_id
|
99
124
|
end
|
100
125
|
|
101
126
|
# Typically, this would be accessed through
|
@@ -106,7 +131,61 @@ module Contrast
|
|
106
131
|
# @return [String,nil] the value of the session metadata set in the
|
107
132
|
# configuration, or nil if unset
|
108
133
|
def session_metadata
|
109
|
-
|
134
|
+
root.application.session_metadata
|
135
|
+
end
|
136
|
+
|
137
|
+
# Typically, the following values would be accessed through Contrast::Components::AppContext
|
138
|
+
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
|
139
|
+
# that mechanism, so we look it up directly for ourselves.
|
140
|
+
#
|
141
|
+
# @return [String, nil]
|
142
|
+
def api_url
|
143
|
+
root.api.url
|
144
|
+
end
|
145
|
+
|
146
|
+
# Typically, the following values would be accessed through Contrast::Components::AppContext
|
147
|
+
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
|
148
|
+
# that mechanism, so we look it up directly for ourselves.
|
149
|
+
#
|
150
|
+
# @return [String, nil]
|
151
|
+
def api_key
|
152
|
+
root.api.api_key
|
153
|
+
end
|
154
|
+
|
155
|
+
# Typically, the following values would be accessed through Contrast::Components::AppContext
|
156
|
+
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
|
157
|
+
# that mechanism, so we look it up directly for ourselves.
|
158
|
+
#
|
159
|
+
# @return [String, nil]
|
160
|
+
def api_service_key
|
161
|
+
root.api.service_key
|
162
|
+
end
|
163
|
+
|
164
|
+
# Typically, the following values would be accessed through Contrast::Components::AppContext
|
165
|
+
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
|
166
|
+
# that mechanism, so we look it up directly for ourselves.
|
167
|
+
#
|
168
|
+
# @return [String, nil]
|
169
|
+
def api_username
|
170
|
+
root.api.user_name
|
171
|
+
end
|
172
|
+
|
173
|
+
# Typically, the following values would be accessed through Contrast::Components::AppContext
|
174
|
+
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
|
175
|
+
# that mechanism, so we look it up directly for ourselves.
|
176
|
+
#
|
177
|
+
# @return [String, nil]
|
178
|
+
def bypass
|
179
|
+
root.agent.service.bypass
|
180
|
+
end
|
181
|
+
|
182
|
+
# Typically, the following values would be accessed through Contrast::Components::AppContext
|
183
|
+
# and Contrast::Components::Logger, but we're too early in the initialization of the Agent to use
|
184
|
+
# that mechanism, so we look it up directly for ourselves.
|
185
|
+
#
|
186
|
+
# @return [String, nil]
|
187
|
+
def logger_path
|
188
|
+
root.agent.logger.path
|
110
189
|
end
|
111
190
|
end
|
112
191
|
end
|
@@ -15,6 +15,7 @@ module Contrast
|
|
15
15
|
include Contrast::Components::ComponentBase
|
16
16
|
|
17
17
|
DEFAULT_SERVICE_LOG = 'contrast_service.log'
|
18
|
+
DEFAULT_SERVICE_LEVEL = :TRACE
|
18
19
|
# The Rails ActionDispatch regexp for localhost IP + literal localhost
|
19
20
|
# https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb#L32
|
20
21
|
LOCALHOST = Regexp.union [/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/, /^localhost$/]
|
@@ -31,6 +32,12 @@ module Contrast
|
|
31
32
|
(LOCALHOST.match?(host) || !!socket_path)
|
32
33
|
end
|
33
34
|
|
35
|
+
def use_agent_communication?
|
36
|
+
return @_use_agent_communication unless @_use_agent_communication.nil?
|
37
|
+
|
38
|
+
@_use_agent_communication = true?(::Contrast::CONFIG.root.agent.service.bypass)
|
39
|
+
end
|
40
|
+
|
34
41
|
def host
|
35
42
|
@_host ||=
|
36
43
|
(::Contrast::CONFIG.root.agent.service.host || Contrast::Config::ServiceConfiguration::DEFAULT_HOST).to_s
|
@@ -53,6 +60,10 @@ module Contrast
|
|
53
60
|
@_logger_path ||= ::Contrast::CONFIG.root.agent.service.logger.path || DEFAULT_SERVICE_LOG
|
54
61
|
end
|
55
62
|
|
63
|
+
def logger_level
|
64
|
+
@_logger_level ||= ::Contrast::CONFIG.root.agent.service.logger.level || DEFAULT_SERVICE_LEVEL
|
65
|
+
end
|
66
|
+
|
56
67
|
private
|
57
68
|
|
58
69
|
def disabled?
|
@@ -14,7 +14,7 @@ module Contrast
|
|
14
14
|
DEFAULT_SAMPLING_WINDOW_MS = 180_000
|
15
15
|
end
|
16
16
|
|
17
|
-
module ClassMethods
|
17
|
+
module ClassMethods # :nodoc:
|
18
18
|
include Contrast::Components::ComponentBase
|
19
19
|
include Constants
|
20
20
|
|
@@ -90,7 +90,7 @@ module Contrast
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
module InstanceMethods
|
93
|
+
module InstanceMethods # :nodoc:
|
94
94
|
include Contrast::Components::ComponentBase
|
95
95
|
include Constants
|
96
96
|
include ClassMethods
|
@@ -8,7 +8,7 @@ module Contrast
|
|
8
8
|
class AgentConfiguration < BaseConfiguration
|
9
9
|
KEYS = {
|
10
10
|
enable: EMPTY_VALUE,
|
11
|
-
start_bundled_service:
|
11
|
+
start_bundled_service: true,
|
12
12
|
omit_body: EMPTY_VALUE,
|
13
13
|
service: Contrast::Config::ServiceConfiguration,
|
14
14
|
logger: Contrast::Config::LoggerConfiguration,
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/config/api_proxy_configuration'
|
5
|
+
require 'contrast/config/certification_configuration'
|
6
|
+
require 'contrast/config/request_audit_configuration'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Config
|
10
|
+
# Api keys configuration
|
11
|
+
class ApiConfiguration < BaseConfiguration
|
12
|
+
URL = 'https://app.contrastsecurity.com/contrast'
|
13
|
+
KEYS = {
|
14
|
+
api_key: EMPTY_VALUE,
|
15
|
+
url: URL,
|
16
|
+
user_name: EMPTY_VALUE,
|
17
|
+
service_key: EMPTY_VALUE,
|
18
|
+
proxy: Contrast::Config::ApiProxyConfiguration,
|
19
|
+
request_audit: Contrast::Config::RequestAuditConfiguration,
|
20
|
+
certificate: Contrast::Config::CertificationConfiguration
|
21
|
+
}.cs__freeze
|
22
|
+
def initialize hsh
|
23
|
+
super(hsh, KEYS)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Copyright (c) 2021 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 Config
|
6
|
+
# Api Proxy keys configuration
|
7
|
+
class ApiProxyConfiguration < BaseConfiguration
|
8
|
+
KEYS = { enable: false, url: EMPTY_VALUE }.cs__freeze
|
9
|
+
def initialize hsh
|
10
|
+
super(hsh, KEYS)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# Copyright (c) 2021 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/default_value'
|
5
4
|
require 'contrast/utils/object_share'
|
6
5
|
|
7
6
|
module Contrast
|
@@ -18,8 +17,8 @@ module Contrast
|
|
18
17
|
tags: EMPTY_VALUE,
|
19
18
|
code: EMPTY_VALUE,
|
20
19
|
metadata: EMPTY_VALUE,
|
21
|
-
session_id: Contrast::
|
22
|
-
session_metadata: Contrast::
|
20
|
+
session_id: Contrast::Utils::ObjectShare::EMPTY_STRING,
|
21
|
+
session_metadata: Contrast::Utils::ObjectShare::EMPTY_STRING
|
23
22
|
}.cs__freeze
|
24
23
|
|
25
24
|
def initialize hsh
|
@@ -9,10 +9,11 @@ module Contrast
|
|
9
9
|
KEYS = {
|
10
10
|
tags: EMPTY_VALUE,
|
11
11
|
enable: EMPTY_VALUE,
|
12
|
-
enable_scan_response:
|
12
|
+
enable_scan_response: true,
|
13
|
+
enable_dynamic_sources: true,
|
13
14
|
sampling: Contrast::Config::SamplingConfiguration,
|
14
15
|
rules: Contrast::Config::AssessRulesConfiguration,
|
15
|
-
stacktraces:
|
16
|
+
stacktraces: 'ALL'
|
16
17
|
}.cs__freeze
|
17
18
|
|
18
19
|
def initialize hsh
|
@@ -12,17 +12,18 @@ module Contrast
|
|
12
12
|
class BaseConfiguration
|
13
13
|
extend Forwardable
|
14
14
|
|
15
|
-
|
15
|
+
attr_reader :configuration_map
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def_delegators :@map, :empty?, :key?, :delete, :fetch, :[], :[]=, :each, :each_pair, :each_key, :each_value
|
17
|
+
alias_method :to_hash, :configuration_map
|
18
|
+
def_delegators :@configuration_map, :empty?, :key?, :delete, :fetch,
|
19
|
+
:[], :[]=, :each, :each_pair, :each_key, :each_value
|
21
20
|
|
22
21
|
EMPTY_VALUE = :EMPTY_VALUE
|
23
22
|
|
24
23
|
def initialize hsh = {}, keys = {}
|
25
|
-
|
24
|
+
# holds configuration key value pairs
|
25
|
+
# each configuration class can contain nested BaseConfigurations
|
26
|
+
@configuration_map = {}
|
26
27
|
traverse_config(hsh, keys)
|
27
28
|
end
|
28
29
|
|
@@ -39,7 +40,7 @@ module Contrast
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def nil?
|
42
|
-
@
|
43
|
+
@configuration_map.empty?
|
43
44
|
end
|
44
45
|
|
45
46
|
private
|
@@ -69,25 +70,13 @@ module Contrast
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def assign_config_value str_key, spec_value, user_provided_value
|
72
|
-
@
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
case value
|
80
|
-
when STRING_BOOLEANS[1]
|
81
|
-
true
|
82
|
-
when STRING_BOOLEANS[0]
|
83
|
-
false
|
84
|
-
else
|
85
|
-
# returns non boolean string values
|
86
|
-
user_provided_value
|
87
|
-
end
|
88
|
-
else
|
89
|
-
user_provided_value
|
90
|
-
end
|
73
|
+
@configuration_map[str_key] = if spec_value.is_a?(Class) && spec_value <= Contrast::Config::BaseConfiguration
|
74
|
+
spec_value.new(user_provided_value)
|
75
|
+
elsif user_provided_value == EMPTY_VALUE
|
76
|
+
spec_value
|
77
|
+
else
|
78
|
+
user_provided_value
|
79
|
+
end
|
91
80
|
end
|
92
81
|
|
93
82
|
def value_from_key_config key, config_hash
|
@@ -99,13 +88,13 @@ module Contrast
|
|
99
88
|
|
100
89
|
def define_getter str_key
|
101
90
|
define_singleton_method str_key.to_sym do
|
102
|
-
@
|
91
|
+
@configuration_map[str_key] == EMPTY_VALUE ? nil : @configuration_map[str_key]
|
103
92
|
end
|
104
93
|
end
|
105
94
|
|
106
95
|
def define_setter str_key
|
107
96
|
define_singleton_method "#{ str_key }=".to_sym do |new_value|
|
108
|
-
@
|
97
|
+
@configuration_map[str_key] = new_value
|
109
98
|
end
|
110
99
|
end
|
111
100
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Copyright (c) 2021 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 Config
|
6
|
+
# Certificate Configuration
|
7
|
+
class CertificationConfiguration < BaseConfiguration
|
8
|
+
KEYS = { enable: false, ca_file: EMPTY_VALUE, cert_file: EMPTY_VALUE, key_file: EMPTY_VALUE }.cs__freeze
|
9
|
+
|
10
|
+
def initialize hsh
|
11
|
+
super(hsh, KEYS)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (c) 2021 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 Config
|
6
|
+
# This module is holding all the Env Variables that we could use through the agent lifecycle
|
7
|
+
module EnvVariables
|
8
|
+
ENV_VARIABLES = { telemetry_opt_outs: ENV['CONTRAST_AGENT_TELEMETRY_OPTOUT'].to_s || false }.cs__freeze
|
9
|
+
|
10
|
+
def return_value key
|
11
|
+
return unless ENV_VARIABLES.key?(key.to_sym)
|
12
|
+
|
13
|
+
sym_key = key.downcase.to_sym
|
14
|
+
ENV_VARIABLES[sym_key]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -8,17 +8,17 @@ module Contrast
|
|
8
8
|
class HeapDumpConfiguration < BaseConfiguration
|
9
9
|
KEYS = {
|
10
10
|
enable: # should dumps be taken
|
11
|
-
Contrast::
|
11
|
+
Contrast::Utils::ObjectShare::FALSE,
|
12
12
|
path: # dir to which dumps should be
|
13
|
-
|
13
|
+
'contrast_heap_dumps', # saved
|
14
14
|
delay_ms: # time, in ms, after initialization
|
15
|
-
|
15
|
+
10_000, # to delay before taking dump
|
16
16
|
window_ms: # ms between each dump
|
17
|
-
|
17
|
+
10_000, #
|
18
18
|
count: # number of dumps to take
|
19
|
-
|
19
|
+
5, #
|
20
20
|
clean: # remove temporary objects or not
|
21
|
-
Contrast::
|
21
|
+
Contrast::Utils::ObjectShare::FALSE #
|
22
22
|
}.cs__freeze
|
23
23
|
|
24
24
|
def initialize hsh
|
@@ -6,11 +6,7 @@ module Contrast
|
|
6
6
|
# Common Configuration settings. Those in this section pertain to the
|
7
7
|
# inventory functionality of the Agent.
|
8
8
|
class InventoryConfiguration < BaseConfiguration
|
9
|
-
KEYS = {
|
10
|
-
enable: Contrast::Config::DefaultValue.new(true),
|
11
|
-
analyze_libraries: Contrast::Config::DefaultValue.new(true),
|
12
|
-
tags: EMPTY_VALUE
|
13
|
-
}.cs__freeze
|
9
|
+
KEYS = { enable: true, analyze_libraries: true, tags: EMPTY_VALUE }.cs__freeze
|
14
10
|
|
15
11
|
def initialize hsh
|
16
12
|
super(hsh, KEYS)
|
@@ -12,7 +12,7 @@ module Contrast
|
|
12
12
|
enable: EMPTY_VALUE,
|
13
13
|
mode: EMPTY_VALUE,
|
14
14
|
disable_system_commands: EMPTY_VALUE,
|
15
|
-
detect_custom_code_accessing_system_files:
|
15
|
+
detect_custom_code_accessing_system_files: true
|
16
16
|
}.cs__freeze
|
17
17
|
|
18
18
|
def initialize hsh
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (c) 2021 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 Config
|
6
|
+
# This class holds the Common Settings for the
|
7
|
+
# hidden functionality of the TS
|
8
|
+
class RequestAuditConfiguration < BaseConfiguration
|
9
|
+
DEFAULT_PATH = './messages'
|
10
|
+
|
11
|
+
KEYS = { enable: false, requests: false, responses: false, path: DEFAULT_PATH }.cs__freeze
|
12
|
+
|
13
|
+
def initialize hsh
|
14
|
+
super(hsh, KEYS)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -6,6 +6,7 @@ module Contrast
|
|
6
6
|
# The base of the Common Configuration settings.
|
7
7
|
class RootConfiguration < BaseConfiguration
|
8
8
|
KEYS = {
|
9
|
+
api: Contrast::Config::ApiConfiguration,
|
9
10
|
enable: BaseConfiguration::EMPTY_VALUE,
|
10
11
|
agent: Contrast::Config::AgentConfiguration,
|
11
12
|
application: Contrast::Config::ApplicationConfiguration,
|
@@ -23,17 +23,17 @@ module Contrast
|
|
23
23
|
DEFAULT_UNINSTRUMENTED_NAMESPACES = %w[FactoryGirl FactoryBot].cs__freeze
|
24
24
|
|
25
25
|
KEYS = {
|
26
|
-
disabled_agent_rake_tasks:
|
26
|
+
disabled_agent_rake_tasks: DISABLED_RAKE_TASK_LIST,
|
27
27
|
exceptions: Contrast::Config::ExceptionConfiguration,
|
28
28
|
# controls whether or not we patch interpolation, either by rewrite or by funchook
|
29
|
-
interpolate: Contrast::
|
29
|
+
interpolate: Contrast::Utils::ObjectShare::TRUE,
|
30
30
|
# controls whether or not we patch the rb_yield block to track split propagation
|
31
|
-
propagate_yield: Contrast::
|
31
|
+
propagate_yield: Contrast::Utils::ObjectShare::TRUE,
|
32
32
|
# control whether or not we run file scanning rules on require
|
33
|
-
require_scan: Contrast::
|
33
|
+
require_scan: Contrast::Utils::ObjectShare::TRUE,
|
34
34
|
# controls whether or not we track frozen Strings by replacing them
|
35
|
-
track_frozen_sources: Contrast::
|
36
|
-
uninstrument_namespace:
|
35
|
+
track_frozen_sources: Contrast::Utils::ObjectShare::TRUE,
|
36
|
+
uninstrument_namespace: DEFAULT_UNINSTRUMENTED_NAMESPACES
|
37
37
|
}.cs__freeze
|
38
38
|
|
39
39
|
def initialize hsh
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# Copyright (c) 2021 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/default_value'
|
5
4
|
require 'contrast/config/logger_configuration'
|
6
5
|
|
7
6
|
module Contrast
|
@@ -19,7 +18,8 @@ module Contrast
|
|
19
18
|
host: EMPTY_VALUE,
|
20
19
|
port: EMPTY_VALUE,
|
21
20
|
socket: EMPTY_VALUE,
|
22
|
-
logger: Contrast::Config::LoggerConfiguration
|
21
|
+
logger: Contrast::Config::LoggerConfiguration,
|
22
|
+
bypass: false
|
23
23
|
}.cs__freeze
|
24
24
|
|
25
25
|
def initialize hsh
|
data/lib/contrast/config.rb
CHANGED
@@ -11,7 +11,6 @@ module Contrast
|
|
11
11
|
end
|
12
12
|
|
13
13
|
require 'contrast/config/base_configuration'
|
14
|
-
require 'contrast/config/default_value'
|
15
14
|
|
16
15
|
require 'contrast/config/logger_configuration'
|
17
16
|
|
@@ -24,6 +23,7 @@ require 'contrast/config/protect_rules_configuration'
|
|
24
23
|
require 'contrast/config/sampling_configuration'
|
25
24
|
|
26
25
|
require 'contrast/config/ruby_configuration'
|
26
|
+
require 'contrast/config/api_configuration'
|
27
27
|
require 'contrast/config/agent_configuration'
|
28
28
|
require 'contrast/config/application_configuration'
|
29
29
|
require 'contrast/config/server_configuration'
|
@@ -7,6 +7,7 @@ require 'fileutils'
|
|
7
7
|
require 'contrast/config'
|
8
8
|
require 'contrast/utils/object_share'
|
9
9
|
require 'contrast/components/scope'
|
10
|
+
require 'contrast/utils/exclude_key'
|
10
11
|
|
11
12
|
module Contrast
|
12
13
|
# This is how we read in the local settings for the Agent, both ENV/ CMD line
|
@@ -86,7 +87,7 @@ module Contrast
|
|
86
87
|
def yaml_to_hash path
|
87
88
|
if path && File.readable?(path)
|
88
89
|
begin
|
89
|
-
yaml =
|
90
|
+
yaml = File.read(path)
|
90
91
|
yaml = ERB.new(yaml).result if defined?(ERB)
|
91
92
|
return YAML.safe_load(yaml)
|
92
93
|
rescue Psych::Exception => e
|
@@ -204,7 +205,6 @@ module Contrast
|
|
204
205
|
# in the thing to convert and setting them in the given hash. For now, this
|
205
206
|
# logs every possible key, whether set or not. If we want to change that
|
206
207
|
# behavior, we can skip adding keys to the hash if the value is nil, blank,
|
207
|
-
# or Contrast::Config::DefaultValue depending on desired behavior
|
208
208
|
#
|
209
209
|
# @param hash [Hash] the hash to populate
|
210
210
|
# @param convert [Contrast::Config::BaseConfiguration, Object] the level of
|
@@ -218,6 +218,8 @@ module Contrast
|
|
218
218
|
case convert
|
219
219
|
when Contrast::Config::BaseConfiguration
|
220
220
|
convert.cs__class::KEYS.each_key do |key|
|
221
|
+
next if Contrast::Utils::ExcludeKey.excludable? key.to_s
|
222
|
+
|
221
223
|
hash[key] = convert_to_hash(convert.send(key), {})
|
222
224
|
end
|
223
225
|
hash
|
@@ -42,13 +42,11 @@ module Contrast
|
|
42
42
|
shift = 0
|
43
43
|
separator_length = separator.nil? ? 0 : separator.to_s.length
|
44
44
|
parent_events = []
|
45
|
-
ary.each do |obj|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
parent_events << parent_event if parent_event
|
51
|
-
end
|
45
|
+
ary.compact.each do |obj|
|
46
|
+
properties.copy_from(obj, ret, shift)
|
47
|
+
shift += obj.to_s.length
|
48
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(obj)&.event
|
49
|
+
parent_events << parent_event if parent_event
|
52
50
|
shift += separator_length
|
53
51
|
end
|
54
52
|
return ret unless Contrast::Agent::Assess::Tracker.tracked?(ret)
|