contrast-agent 4.6.0 → 4.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -1
- data/.gitmodules +1 -1
- data/.simplecov +1 -0
- data/Rakefile +1 -2
- data/ext/build_funchook.rb +3 -3
- data/ext/extconf_common.rb +1 -5
- data/lib/contrast.rb +24 -14
- data/lib/contrast/agent/assess.rb +1 -1
- data/lib/contrast/agent/assess/contrast_event.rb +1 -4
- data/lib/contrast/agent/assess/contrast_object.rb +2 -2
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +2 -4
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +6 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +16 -21
- data/lib/contrast/agent/assess/policy/policy.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_node.rb +25 -33
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -5
- data/lib/contrast/agent/assess/policy/preshift.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagation_method.rb +10 -19
- data/lib/contrast/agent/assess/policy/propagation_node.rb +19 -8
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/propagator/center.rb +2 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +3 -6
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +3 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -1
- data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
- data/lib/contrast/agent/assess/policy/propagator/select.rb +2 -12
- data/lib/contrast/agent/assess/policy/propagator/split.rb +12 -13
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +3 -10
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -15
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +13 -10
- data/lib/contrast/agent/assess/policy/source_method.rb +12 -12
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -3
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +5 -1
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -3
- data/lib/contrast/agent/assess/policy/trigger_method.rb +8 -18
- data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -2
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +4 -3
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -2
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -8
- data/lib/contrast/agent/assess/property/evented.rb +8 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +11 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +4 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -9
- data/lib/contrast/agent/at_exit_hook.rb +3 -3
- data/lib/contrast/agent/class_reopener.rb +9 -6
- data/lib/contrast/agent/disable_reaction.rb +4 -7
- data/lib/contrast/agent/exclusion_matcher.rb +7 -14
- data/lib/contrast/agent/inventory/dependencies.rb +2 -0
- data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -5
- data/lib/contrast/agent/inventory/policy/datastores.rb +3 -4
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +17 -18
- data/lib/contrast/agent/module_data.rb +3 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +9 -9
- data/lib/contrast/agent/patching/policy/method_policy.rb +6 -2
- data/lib/contrast/agent/patching/policy/module_policy.rb +14 -7
- data/lib/contrast/agent/patching/policy/patch.rb +20 -25
- data/lib/contrast/agent/patching/policy/patch_status.rb +6 -7
- data/lib/contrast/agent/patching/policy/patcher.rb +21 -18
- data/lib/contrast/agent/patching/policy/policy.rb +2 -4
- data/lib/contrast/agent/patching/policy/policy_node.rb +16 -7
- data/lib/contrast/agent/patching/policy/trigger_node.rb +21 -8
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -3
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +5 -9
- data/lib/contrast/agent/protect/policy/policy.rb +1 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +7 -9
- data/lib/contrast/agent/protect/rule/base.rb +20 -23
- data/lib/contrast/agent/protect/rule/base_service.rb +9 -5
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +18 -23
- data/lib/contrast/agent/protect/rule/deserialization.rb +6 -13
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -14
- data/lib/contrast/agent/protect/rule/no_sqli.rb +6 -2
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -3
- data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
- data/lib/contrast/agent/protect/rule/sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +5 -12
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +1 -2
- data/lib/contrast/agent/reaction_processor.rb +13 -13
- data/lib/contrast/agent/request.rb +27 -26
- data/lib/contrast/agent/request_context.rb +17 -22
- data/lib/contrast/agent/request_handler.rb +5 -3
- data/lib/contrast/agent/response.rb +2 -3
- data/lib/contrast/agent/rewriter.rb +9 -6
- data/lib/contrast/agent/rule_set.rb +5 -4
- data/lib/contrast/agent/service_heartbeat.rb +4 -6
- data/lib/contrast/agent/static_analysis.rb +6 -5
- data/lib/contrast/agent/thread.rb +2 -4
- data/lib/contrast/agent/thread_watcher.rb +3 -4
- data/lib/contrast/agent/tracepoint_hook.rb +5 -5
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +4 -5
- data/lib/contrast/api/communication/response_processor.rb +11 -13
- data/lib/contrast/api/communication/service_lifecycle.rb +9 -6
- data/lib/contrast/api/communication/socket_client.rb +22 -31
- data/lib/contrast/api/communication/speedracer.rb +8 -13
- data/lib/contrast/api/decorators/address.rb +2 -3
- data/lib/contrast/api/decorators/agent_startup.rb +7 -9
- data/lib/contrast/api/decorators/application_startup.rb +12 -10
- data/lib/contrast/api/decorators/application_update.rb +0 -4
- data/lib/contrast/api/decorators/http_request.rb +3 -7
- data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
- data/lib/contrast/api/decorators/library.rb +8 -6
- data/lib/contrast/api/decorators/message.rb +9 -9
- data/lib/contrast/api/decorators/trace_event.rb +3 -1
- data/lib/contrast/api/decorators/trace_event_object.rb +3 -6
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +1 -6
- data/lib/contrast/components/agent.rb +17 -17
- data/lib/contrast/components/app_context.rb +11 -15
- data/lib/contrast/components/assess.rb +16 -16
- data/lib/contrast/components/base.rb +40 -0
- data/lib/contrast/components/config.rb +2 -3
- data/lib/contrast/components/contrast_service.rb +12 -18
- data/lib/contrast/components/heap_dump.rb +5 -4
- data/lib/contrast/components/inventory.rb +2 -7
- data/lib/contrast/components/logger.rb +1 -2
- data/lib/contrast/components/protect.rb +10 -13
- data/lib/contrast/components/sampling.rb +13 -7
- data/lib/contrast/components/scope.rb +0 -4
- data/lib/contrast/components/settings.rb +5 -7
- data/lib/contrast/config/assess_rules_configuration.rb +1 -3
- data/lib/contrast/config/base_configuration.rb +4 -5
- data/lib/contrast/config/exception_configuration.rb +1 -5
- data/lib/contrast/config/heap_dump_configuration.rb +12 -6
- data/lib/contrast/config/logger_configuration.rb +1 -5
- data/lib/contrast/configuration.rb +6 -18
- data/lib/contrast/extension/assess/array.rb +3 -10
- data/lib/contrast/extension/assess/erb.rb +1 -7
- data/lib/contrast/extension/assess/eval_trigger.rb +4 -9
- data/lib/contrast/extension/assess/exec_trigger.rb +3 -9
- data/lib/contrast/extension/assess/fiber.rb +8 -17
- data/lib/contrast/extension/assess/hash.rb +3 -3
- data/lib/contrast/extension/assess/kernel.rb +4 -13
- data/lib/contrast/extension/assess/marshal.rb +6 -10
- data/lib/contrast/extension/assess/regexp.rb +6 -10
- data/lib/contrast/extension/assess/string.rb +8 -6
- data/lib/contrast/extension/kernel.rb +2 -2
- data/lib/contrast/extension/protect/kernel.rb +0 -5
- data/lib/contrast/framework/manager.rb +3 -5
- data/lib/contrast/framework/rack/patch/session_cookie.rb +11 -24
- data/lib/contrast/framework/rack/patch/support.rb +6 -4
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +12 -9
- data/lib/contrast/framework/rails/patch/support.rb +41 -35
- data/lib/contrast/framework/rails/railtie.rb +34 -0
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +4 -1
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +2 -0
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +5 -4
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -0
- data/lib/contrast/framework/rails/support.rb +2 -2
- data/lib/contrast/framework/sinatra/support.rb +3 -1
- data/lib/contrast/funchook/funchook.rb +5 -8
- data/lib/contrast/logger/application.rb +13 -15
- data/lib/contrast/logger/format.rb +2 -5
- data/lib/contrast/logger/log.rb +26 -9
- data/lib/contrast/logger/request.rb +1 -6
- data/lib/contrast/security_exception.rb +1 -1
- data/lib/contrast/tasks/config.rb +0 -1
- data/lib/contrast/tasks/service.rb +6 -7
- data/lib/contrast/utils/assess/sampling_util.rb +2 -3
- data/lib/contrast/utils/assess/tracking_util.rb +3 -6
- data/lib/contrast/utils/class_util.rb +0 -8
- data/lib/contrast/utils/hash_digest.rb +2 -5
- data/lib/contrast/utils/heap_dump_util.rb +5 -3
- data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
- data/lib/contrast/utils/inventory_util.rb +2 -3
- data/lib/contrast/utils/io_util.rb +3 -5
- data/lib/contrast/utils/job_servers_running.rb +13 -7
- data/lib/contrast/utils/os.rb +4 -4
- data/lib/contrast/utils/ruby_ast_rewriter.rb +2 -1
- data/lib/contrast/utils/string_utils.rb +2 -3
- data/lib/contrast/utils/tag_util.rb +25 -19
- data/resources/assess/policy.json +55 -0
- data/ruby-agent.gemspec +17 -16
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- data/sonar-project.properties +9 -0
- metadata +61 -46
- data/lib/contrast/agent/railtie.rb +0 -31
- data/lib/contrast/components/interface.rb +0 -195
- data/lib/contrast/delegators/input_analysis.rb +0 -12
@@ -16,9 +16,7 @@ module Contrast
|
|
16
16
|
# including the Client, Process, and Server information.
|
17
17
|
class Interface
|
18
18
|
include Contrast::Components::ComponentBase
|
19
|
-
include Contrast::Components::
|
20
|
-
|
21
|
-
access_component :agent, :analysis, :config, :logging
|
19
|
+
include Contrast::Components::Logger::InstanceMethods
|
22
20
|
|
23
21
|
DEFAULT_APP_NAME = 'rails'
|
24
22
|
DEFAULT_APP_PATH = '/'
|
@@ -31,15 +29,15 @@ module Contrast
|
|
31
29
|
|
32
30
|
def server_type
|
33
31
|
@_server_type ||= begin
|
34
|
-
tmp = CONFIG.root.server.type
|
32
|
+
tmp = ::Contrast::CONFIG.root.server.type
|
35
33
|
tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
|
36
34
|
tmp
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
|
-
def
|
41
|
-
@
|
42
|
-
tmp = CONFIG.root.application.name
|
38
|
+
def app_name
|
39
|
+
@_app_name ||= begin
|
40
|
+
tmp = ::Contrast::CONFIG.root.application.name # rubocop:disable Security/Module/Name
|
43
41
|
tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
|
44
42
|
tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
|
45
43
|
Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
|
@@ -50,7 +48,7 @@ module Contrast
|
|
50
48
|
|
51
49
|
def path
|
52
50
|
@_path ||= begin
|
53
|
-
tmp = CONFIG.root.application.path
|
51
|
+
tmp = ::Contrast::CONFIG.root.application.path
|
54
52
|
Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
|
55
53
|
rescue StandardError
|
56
54
|
DEFAULT_APP_PATH
|
@@ -59,7 +57,7 @@ module Contrast
|
|
59
57
|
|
60
58
|
def server_name
|
61
59
|
@_server_name ||= begin
|
62
|
-
tmp = CONFIG.root.server.name
|
60
|
+
tmp = ::Contrast::CONFIG.root.server.name # rubocop:disable Security/Module/Name
|
63
61
|
tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
|
64
62
|
tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
|
65
63
|
Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
|
@@ -70,7 +68,7 @@ module Contrast
|
|
70
68
|
|
71
69
|
def server_path
|
72
70
|
@_server_path ||= begin
|
73
|
-
tmp = CONFIG.root.server.path
|
71
|
+
tmp = ::Contrast::CONFIG.root.server.path
|
74
72
|
tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
|
75
73
|
Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
|
76
74
|
rescue StandardError
|
@@ -88,7 +86,7 @@ module Contrast
|
|
88
86
|
server_name: msg.server_name,
|
89
87
|
server_path: msg.server_path,
|
90
88
|
server_type: msg.server_type,
|
91
|
-
application_name:
|
89
|
+
application_name: app_name,
|
92
90
|
application_path: path,
|
93
91
|
application_language: Contrast::Utils::ObjectShare::RUBY)
|
94
92
|
|
@@ -108,7 +106,7 @@ module Contrast
|
|
108
106
|
end
|
109
107
|
|
110
108
|
def client_id
|
111
|
-
@_client_id ||= [
|
109
|
+
@_client_id ||= [app_name, pgid].join('-')
|
112
110
|
end
|
113
111
|
|
114
112
|
def instrument_middleware_stack?
|
@@ -116,7 +114,7 @@ module Contrast
|
|
116
114
|
end
|
117
115
|
|
118
116
|
def disabled_agent_rake_tasks
|
119
|
-
CONFIG.root.agent.ruby.disabled_agent_rake_tasks
|
117
|
+
::Contrast::CONFIG.root.agent.ruby.disabled_agent_rake_tasks
|
120
118
|
end
|
121
119
|
|
122
120
|
# Determines if the Process we're currently in matches that of the
|
@@ -137,8 +135,6 @@ module Contrast
|
|
137
135
|
@_original_pid ||= Process.pid
|
138
136
|
end
|
139
137
|
end
|
140
|
-
|
141
|
-
COMPONENT_INTERFACE = Interface.new
|
142
138
|
end
|
143
139
|
end
|
144
140
|
end
|
@@ -1,6 +1,11 @@
|
|
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/components/base'
|
5
|
+
require 'contrast/components/config'
|
6
|
+
require 'contrast/components/settings'
|
7
|
+
|
8
|
+
|
4
9
|
module Contrast
|
5
10
|
module Components
|
6
11
|
module Assess
|
@@ -10,24 +15,21 @@ module Contrast
|
|
10
15
|
# Specifically, this allows for querying the state of the Assess product.
|
11
16
|
class Interface
|
12
17
|
include Contrast::Components::ComponentBase
|
13
|
-
include Contrast::Components::Interface
|
14
|
-
|
15
|
-
access_component :config, :settings
|
16
18
|
|
17
19
|
def enabled?
|
18
20
|
# config overrides if forcibly set
|
19
21
|
return false if forcibly_disabled?
|
20
22
|
return true if forcibly_enabled?
|
21
23
|
|
22
|
-
SETTINGS.assess_state.enabled == true
|
24
|
+
::Contrast::SETTINGS.assess_state.enabled == true
|
23
25
|
end
|
24
26
|
|
25
27
|
def tainted_columns
|
26
|
-
SETTINGS.tainted_columns
|
28
|
+
::Contrast::SETTINGS.tainted_columns
|
27
29
|
end
|
28
30
|
|
29
31
|
def forcibly_disabled?
|
30
|
-
@_forcibly_disabled = false?(CONFIG.root.assess.enable) if @_forcibly_disabled.nil?
|
32
|
+
@_forcibly_disabled = false?(::Contrast::CONFIG.root.assess.enable) if @_forcibly_disabled.nil?
|
31
33
|
@_forcibly_disabled
|
32
34
|
end
|
33
35
|
|
@@ -39,9 +41,9 @@ module Contrast
|
|
39
41
|
# faster comparisons when we use it. Anything not one of the known values of
|
40
42
|
# 'NONE', 'SOME', or 'ALL' is treated as 'ALL'
|
41
43
|
#
|
42
|
-
# @return [Symbol] the normalized value of CONFIG.root.assess.stacktraces
|
44
|
+
# @return [Symbol] the normalized value of ::Contrast::CONFIG.root.assess.stacktraces
|
43
45
|
def capture_stacktrace_value
|
44
|
-
@_capture_stacktrace_value ||= case CONFIG.root.assess.stacktraces.upcase
|
46
|
+
@_capture_stacktrace_value ||= case ::Contrast::CONFIG.root.assess.stacktraces.upcase
|
45
47
|
when 'NONE'
|
46
48
|
:NONE
|
47
49
|
when 'SOME'
|
@@ -71,38 +73,36 @@ module Contrast
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def scan_response?
|
74
|
-
@_scan_response = !false?(CONFIG.root.assess.enable_scan_response) if @_scan_response.nil?
|
76
|
+
@_scan_response = !false?(::Contrast::CONFIG.root.assess.enable_scan_response) if @_scan_response.nil?
|
75
77
|
@_scan_response
|
76
78
|
end
|
77
79
|
|
78
80
|
def track_frozen_sources?
|
79
|
-
@_track_frozen_sources = !false?(CONFIG.root.agent.ruby.track_frozen_sources) if @_track_frozen_sources.nil?
|
81
|
+
@_track_frozen_sources = !false?(::Contrast::CONFIG.root.agent.ruby.track_frozen_sources) if @_track_frozen_sources.nil?
|
80
82
|
@_track_frozen_sources
|
81
83
|
end
|
82
84
|
|
83
85
|
def require_scan?
|
84
|
-
@_require_scan = !false?(CONFIG.root.agent.ruby.require_scan) if @_require_scan.nil?
|
86
|
+
@_require_scan = !false?(::Contrast::CONFIG.root.agent.ruby.require_scan) if @_require_scan.nil?
|
85
87
|
@_require_scan
|
86
88
|
end
|
87
89
|
|
88
90
|
def tags
|
89
|
-
CONFIG.root.assess&.tags
|
91
|
+
::Contrast::CONFIG.root.assess&.tags
|
90
92
|
end
|
91
93
|
|
92
94
|
def disabled_rules
|
93
95
|
# TODO: RUBY-903
|
94
|
-
CONFIG.root.assess&.rules&.disabled_rules || SETTINGS.assess_state.disabled_assess_rules || []
|
96
|
+
::Contrast::CONFIG.root.assess&.rules&.disabled_rules || ::Contrast::SETTINGS.assess_state.disabled_assess_rules || []
|
95
97
|
end
|
96
98
|
|
97
99
|
private
|
98
100
|
|
99
101
|
def forcibly_enabled?
|
100
|
-
@_forcibly_enabled = true?(CONFIG.root.assess.enable) if @_forcibly_enabled.nil?
|
102
|
+
@_forcibly_enabled = true?(::Contrast::CONFIG.root.assess.enable) if @_forcibly_enabled.nil?
|
101
103
|
@_forcibly_enabled
|
102
104
|
end
|
103
105
|
end
|
104
|
-
|
105
|
-
COMPONENT_INTERFACE = Interface.new
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -0,0 +1,40 @@
|
|
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 Components
|
6
|
+
# All components should inherit from this,
|
7
|
+
# whether Interfaces, InstanceMethods or ClassMethods.
|
8
|
+
module ComponentBase
|
9
|
+
# use this to determine if the configuration value is literally boolean
|
10
|
+
# false or some form of the word `false`, regardless of case. It should
|
11
|
+
# be used for those values which default to `true` as they should only
|
12
|
+
# treat a value explicitly set to `false` as such.
|
13
|
+
#
|
14
|
+
# @param config_param [Boolean,String] the value to check
|
15
|
+
# @return [Boolean] should the value be treated as `false`
|
16
|
+
def false? config_param
|
17
|
+
return false if config_param == true
|
18
|
+
return true if config_param == false
|
19
|
+
return false unless config_param.cs__is_a?(String)
|
20
|
+
|
21
|
+
Contrast::Utils::ObjectShare::FALSE.casecmp?(config_param)
|
22
|
+
end
|
23
|
+
|
24
|
+
# use this to determine if the configuration value is literally boolean
|
25
|
+
# true or some form of the word `true`, regardless of case. It should
|
26
|
+
# be used for those values which default to `false` as they should only
|
27
|
+
# treat a value explicitly set to `true` as such.
|
28
|
+
#
|
29
|
+
# @param config_param [Boolean,String] the value to check
|
30
|
+
# @return [Boolean] should the value be treated as `true`
|
31
|
+
def true? config_param
|
32
|
+
return false if config_param == false
|
33
|
+
return true if config_param == true
|
34
|
+
return false unless config_param.cs__is_a?(String)
|
35
|
+
|
36
|
+
Contrast::Utils::ObjectShare::TRUE.casecmp?(config_param)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -56,7 +56,8 @@ module Contrast
|
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
|
-
SESSION_VARIABLES =
|
59
|
+
SESSION_VARIABLES = 'Invalid configuration. '\
|
60
|
+
"Setting both application.session_id and application.session_metadata is not allowed.\n"
|
60
61
|
def validate log: false
|
61
62
|
# The config has information about how to construct the logger.
|
62
63
|
# If the config is invalid, and you want to know about it, then
|
@@ -107,8 +108,6 @@ module Contrast
|
|
107
108
|
@config.application.session_metadata
|
108
109
|
end
|
109
110
|
end
|
110
|
-
|
111
|
-
COMPONENT_INTERFACE = Interface.new
|
112
111
|
end
|
113
112
|
end
|
114
113
|
end
|
@@ -13,38 +13,34 @@ module Contrast
|
|
13
13
|
# the Service, as well as sending a message to the Service.
|
14
14
|
class Interface
|
15
15
|
include Contrast::Components::ComponentBase
|
16
|
-
include Contrast::Components::Interface
|
17
16
|
|
18
17
|
DEFAULT_SERVICE_LOG = 'contrast_service.log'
|
19
18
|
# The Rails ActionDispatch regexp for localhost IP + literal localhost
|
20
19
|
# https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb#L32
|
21
20
|
LOCALHOST = Regexp.union [/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/, /^localhost$/]
|
22
21
|
|
23
|
-
access_component :agent, :config
|
24
|
-
|
25
22
|
def use_bundled_service?
|
26
23
|
# Validates the config to decide if it's suitable for starting
|
27
24
|
# the bundled service
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
25
|
+
|
26
|
+
# Requirement says "must be true" but that
|
27
|
+
# should be "must not be false" -- oops.
|
28
|
+
@_use_bundled_service ||= !false?(::Contrast::CONFIG.root.agent.start_bundled_service) &&
|
29
|
+
# Either a valid host or a valid socket
|
30
|
+
# Path validity is the service's problem
|
31
|
+
(LOCALHOST.match?(host) || !!socket_path)
|
36
32
|
end
|
37
33
|
|
38
34
|
def host
|
39
|
-
@_host ||= (CONFIG.root.agent.service.host || Contrast::Config::ServiceConfiguration::DEFAULT_HOST).to_s
|
35
|
+
@_host ||= (::Contrast::CONFIG.root.agent.service.host || Contrast::Config::ServiceConfiguration::DEFAULT_HOST).to_s
|
40
36
|
end
|
41
37
|
|
42
38
|
def port
|
43
|
-
@_port ||= (CONFIG.root.agent.service.port || Contrast::Config::ServiceConfiguration::DEFAULT_PORT).to_i
|
39
|
+
@_port ||= (::Contrast::CONFIG.root.agent.service.port || Contrast::Config::ServiceConfiguration::DEFAULT_PORT).to_i
|
44
40
|
end
|
45
41
|
|
46
42
|
def socket_path
|
47
|
-
@_socket_path ||= CONFIG.root.agent.service.socket
|
43
|
+
@_socket_path ||= ::Contrast::CONFIG.root.agent.service.socket
|
48
44
|
end
|
49
45
|
|
50
46
|
def use_tcp?
|
@@ -52,18 +48,16 @@ module Contrast
|
|
52
48
|
end
|
53
49
|
|
54
50
|
def logger_path
|
55
|
-
@_logger_path ||= CONFIG.root.agent.service.logger.path || DEFAULT_SERVICE_LOG
|
51
|
+
@_logger_path ||= ::Contrast::CONFIG.root.agent.service.logger.path || DEFAULT_SERVICE_LOG
|
56
52
|
end
|
57
53
|
|
58
54
|
private
|
59
55
|
|
60
56
|
def disabled?
|
61
|
-
@_disabled = false?(CONFIG.root.agent.start_bundled_service) if @_disabled.nil?
|
57
|
+
@_disabled = false?(::Contrast::CONFIG.root.agent.start_bundled_service) if @_disabled.nil?
|
62
58
|
@_disabled
|
63
59
|
end
|
64
60
|
end
|
65
|
-
|
66
|
-
COMPONENT_INTERFACE = Interface.new
|
67
61
|
end
|
68
62
|
end
|
69
63
|
end
|
@@ -1,6 +1,9 @@
|
|
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/components/base'
|
5
|
+
require 'contrast/components/heap_dump'
|
6
|
+
|
4
7
|
module Contrast
|
5
8
|
module Components
|
6
9
|
module HeapDump
|
@@ -11,9 +14,6 @@ module Contrast
|
|
11
14
|
# utility.
|
12
15
|
module ClassMethods
|
13
16
|
include Contrast::Components::ComponentBase
|
14
|
-
include Contrast::Components::Interface
|
15
|
-
|
16
|
-
access_component :config
|
17
17
|
|
18
18
|
def heap_dump_enabled?
|
19
19
|
heap_dump_control[:enabled]
|
@@ -21,7 +21,7 @@ module Contrast
|
|
21
21
|
|
22
22
|
def heap_dump_control
|
23
23
|
@_heap_dump_control ||= begin
|
24
|
-
config = CONFIG.root&.agent&.heap_dump
|
24
|
+
config = ::Contrast::CONFIG.root&.agent&.heap_dump
|
25
25
|
{
|
26
26
|
enabled: true?(config&.enable),
|
27
27
|
path: File.absolute_path(config&.path),
|
@@ -33,6 +33,7 @@ module Contrast
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
InstanceMethods = ClassMethods
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
@@ -11,22 +11,17 @@ module Contrast
|
|
11
11
|
# product.
|
12
12
|
class Interface
|
13
13
|
include Contrast::Components::ComponentBase
|
14
|
-
include Contrast::Components::Interface
|
15
|
-
|
16
|
-
access_component :config, :settings
|
17
14
|
|
18
15
|
def enabled?
|
19
|
-
@_enabled = !false?(CONFIG.root.inventory.enable) if @_enabled.nil?
|
16
|
+
@_enabled = !false?(::Contrast::CONFIG.root.inventory.enable) if @_enabled.nil?
|
20
17
|
@_enabled
|
21
18
|
end
|
22
19
|
|
23
20
|
def analyze_libraries?
|
24
|
-
@_analyze_libraries = !false?(CONFIG.root.inventory.analyze_libraries) if @_analyze_libraries.nil?
|
21
|
+
@_analyze_libraries = !false?(::Contrast::CONFIG.root.inventory.analyze_libraries) if @_analyze_libraries.nil?
|
25
22
|
@_analyze_libraries
|
26
23
|
end
|
27
24
|
end
|
28
|
-
|
29
|
-
COMPONENT_INTERFACE = Interface.new
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/logger/log'
|
5
|
+
require 'contrast/components/base'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Components
|
@@ -20,8 +21,6 @@ module Contrast
|
|
20
21
|
class Interface
|
21
22
|
include Contrast::Components::ComponentBase
|
22
23
|
end
|
23
|
-
|
24
|
-
COMPONENT_INTERFACE = Interface.new
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -1,6 +1,8 @@
|
|
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/components/base'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Components
|
6
8
|
module Protect
|
@@ -8,34 +10,31 @@ module Contrast
|
|
8
10
|
# its parent_configuration_spec.yaml. Specifically, this allows for querying the state of the Protect product.
|
9
11
|
class Interface
|
10
12
|
include Contrast::Components::ComponentBase
|
11
|
-
include Contrast::Components::Interface
|
12
|
-
|
13
|
-
access_component :config, :settings
|
14
13
|
|
15
14
|
def enabled?
|
16
15
|
# config overrides if forcibly set
|
17
16
|
return false if forcibly_disabled?
|
18
17
|
return true if forcibly_enabled?
|
19
18
|
|
20
|
-
SETTINGS.protect_state.enabled == true
|
19
|
+
::Contrast::SETTINGS.protect_state.enabled == true
|
21
20
|
end
|
22
21
|
|
23
22
|
def rule_config
|
24
|
-
CONFIG.root.protect.rules
|
23
|
+
::Contrast::CONFIG.root.protect.rules
|
25
24
|
end
|
26
25
|
|
27
26
|
def rules
|
28
|
-
SETTINGS.protect_state.rules
|
27
|
+
::Contrast::SETTINGS.protect_state.rules
|
29
28
|
end
|
30
29
|
|
31
30
|
def rule_mode rule_id
|
32
|
-
CONFIG.root.protect.rules[rule_id]&.applicable_mode ||
|
33
|
-
SETTINGS.application_state.modes_by_id[rule_id] ||
|
31
|
+
::Contrast::CONFIG.root.protect.rules[rule_id]&.applicable_mode ||
|
32
|
+
::Contrast::SETTINGS.application_state.modes_by_id[rule_id] ||
|
34
33
|
Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
|
35
34
|
end
|
36
35
|
|
37
36
|
def rule name
|
38
|
-
SETTINGS.protect_state.rules[name]
|
37
|
+
::Contrast::SETTINGS.protect_state.rules[name]
|
39
38
|
end
|
40
39
|
|
41
40
|
def report_any_command_execution?
|
@@ -55,17 +54,15 @@ module Contrast
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def forcibly_disabled?
|
58
|
-
@_forcibly_disabled ||= false?(CONFIG.root.protect.enable)
|
57
|
+
@_forcibly_disabled ||= false?(::Contrast::CONFIG.root.protect.enable)
|
59
58
|
end
|
60
59
|
|
61
60
|
private
|
62
61
|
|
63
62
|
def forcibly_enabled?
|
64
|
-
@_forcibly_enabled ||= true?(CONFIG.root.protect.enable)
|
63
|
+
@_forcibly_enabled ||= true?(::Contrast::CONFIG.root.protect.enable)
|
65
64
|
end
|
66
65
|
end
|
67
|
-
|
68
|
-
COMPONENT_INTERFACE = Interface.new
|
69
66
|
end
|
70
67
|
end
|
71
68
|
end
|