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.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.gitmodules +1 -1
  4. data/.simplecov +1 -0
  5. data/Rakefile +1 -2
  6. data/ext/build_funchook.rb +3 -3
  7. data/ext/extconf_common.rb +1 -5
  8. data/lib/contrast.rb +24 -14
  9. data/lib/contrast/agent/assess.rb +1 -1
  10. data/lib/contrast/agent/assess/contrast_event.rb +1 -4
  11. data/lib/contrast/agent/assess/contrast_object.rb +2 -2
  12. data/lib/contrast/agent/assess/events/event_factory.rb +2 -1
  13. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -4
  14. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +6 -3
  15. data/lib/contrast/agent/assess/policy/patcher.rb +16 -21
  16. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  17. data/lib/contrast/agent/assess/policy/policy_node.rb +25 -33
  18. data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -5
  19. data/lib/contrast/agent/assess/policy/preshift.rb +7 -5
  20. data/lib/contrast/agent/assess/policy/propagation_method.rb +10 -19
  21. data/lib/contrast/agent/assess/policy/propagation_node.rb +19 -8
  22. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  23. data/lib/contrast/agent/assess/policy/propagator/center.rb +2 -1
  24. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +3 -6
  25. data/lib/contrast/agent/assess/policy/propagator/insert.rb +3 -1
  26. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -1
  27. data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
  28. data/lib/contrast/agent/assess/policy/propagator/select.rb +2 -12
  29. data/lib/contrast/agent/assess/policy/propagator/split.rb +12 -13
  30. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +3 -10
  31. data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -15
  32. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +13 -10
  33. data/lib/contrast/agent/assess/policy/source_method.rb +12 -12
  34. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -3
  35. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +5 -1
  36. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -3
  37. data/lib/contrast/agent/assess/policy/trigger_method.rb +8 -18
  38. data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -2
  39. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +4 -3
  40. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -2
  41. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -8
  42. data/lib/contrast/agent/assess/property/evented.rb +8 -5
  43. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +11 -5
  44. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +4 -1
  45. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -9
  46. data/lib/contrast/agent/at_exit_hook.rb +3 -3
  47. data/lib/contrast/agent/class_reopener.rb +9 -6
  48. data/lib/contrast/agent/disable_reaction.rb +4 -7
  49. data/lib/contrast/agent/exclusion_matcher.rb +7 -14
  50. data/lib/contrast/agent/inventory/dependencies.rb +2 -0
  51. data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
  52. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -5
  53. data/lib/contrast/agent/inventory/policy/datastores.rb +3 -4
  54. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  55. data/lib/contrast/agent/middleware.rb +17 -18
  56. data/lib/contrast/agent/module_data.rb +3 -3
  57. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
  58. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +9 -9
  59. data/lib/contrast/agent/patching/policy/method_policy.rb +6 -2
  60. data/lib/contrast/agent/patching/policy/module_policy.rb +14 -7
  61. data/lib/contrast/agent/patching/policy/patch.rb +20 -25
  62. data/lib/contrast/agent/patching/policy/patch_status.rb +6 -7
  63. data/lib/contrast/agent/patching/policy/patcher.rb +21 -18
  64. data/lib/contrast/agent/patching/policy/policy.rb +2 -4
  65. data/lib/contrast/agent/patching/policy/policy_node.rb +16 -7
  66. data/lib/contrast/agent/patching/policy/trigger_node.rb +21 -8
  67. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +1 -1
  68. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +1 -1
  69. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  70. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -3
  71. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -1
  72. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +5 -9
  73. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  74. data/lib/contrast/agent/protect/policy/rule_applicator.rb +7 -9
  75. data/lib/contrast/agent/protect/rule/base.rb +20 -23
  76. data/lib/contrast/agent/protect/rule/base_service.rb +9 -5
  77. data/lib/contrast/agent/protect/rule/cmd_injection.rb +18 -23
  78. data/lib/contrast/agent/protect/rule/deserialization.rb +6 -13
  79. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -14
  80. data/lib/contrast/agent/protect/rule/no_sqli.rb +6 -2
  81. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -3
  82. data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
  83. data/lib/contrast/agent/protect/rule/sqli.rb +1 -1
  84. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  85. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  86. data/lib/contrast/agent/protect/rule/xxe.rb +5 -12
  87. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +1 -2
  88. data/lib/contrast/agent/reaction_processor.rb +13 -13
  89. data/lib/contrast/agent/request.rb +27 -26
  90. data/lib/contrast/agent/request_context.rb +17 -22
  91. data/lib/contrast/agent/request_handler.rb +5 -3
  92. data/lib/contrast/agent/response.rb +2 -3
  93. data/lib/contrast/agent/rewriter.rb +9 -6
  94. data/lib/contrast/agent/rule_set.rb +5 -4
  95. data/lib/contrast/agent/service_heartbeat.rb +4 -6
  96. data/lib/contrast/agent/static_analysis.rb +6 -5
  97. data/lib/contrast/agent/thread.rb +2 -4
  98. data/lib/contrast/agent/thread_watcher.rb +3 -4
  99. data/lib/contrast/agent/tracepoint_hook.rb +5 -5
  100. data/lib/contrast/agent/version.rb +1 -1
  101. data/lib/contrast/api/communication/messaging_queue.rb +4 -5
  102. data/lib/contrast/api/communication/response_processor.rb +11 -13
  103. data/lib/contrast/api/communication/service_lifecycle.rb +9 -6
  104. data/lib/contrast/api/communication/socket_client.rb +22 -31
  105. data/lib/contrast/api/communication/speedracer.rb +8 -13
  106. data/lib/contrast/api/decorators/address.rb +2 -3
  107. data/lib/contrast/api/decorators/agent_startup.rb +7 -9
  108. data/lib/contrast/api/decorators/application_startup.rb +12 -10
  109. data/lib/contrast/api/decorators/application_update.rb +0 -4
  110. data/lib/contrast/api/decorators/http_request.rb +3 -7
  111. data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
  112. data/lib/contrast/api/decorators/library.rb +8 -6
  113. data/lib/contrast/api/decorators/message.rb +9 -9
  114. data/lib/contrast/api/decorators/trace_event.rb +3 -1
  115. data/lib/contrast/api/decorators/trace_event_object.rb +3 -6
  116. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +1 -6
  117. data/lib/contrast/components/agent.rb +17 -17
  118. data/lib/contrast/components/app_context.rb +11 -15
  119. data/lib/contrast/components/assess.rb +16 -16
  120. data/lib/contrast/components/base.rb +40 -0
  121. data/lib/contrast/components/config.rb +2 -3
  122. data/lib/contrast/components/contrast_service.rb +12 -18
  123. data/lib/contrast/components/heap_dump.rb +5 -4
  124. data/lib/contrast/components/inventory.rb +2 -7
  125. data/lib/contrast/components/logger.rb +1 -2
  126. data/lib/contrast/components/protect.rb +10 -13
  127. data/lib/contrast/components/sampling.rb +13 -7
  128. data/lib/contrast/components/scope.rb +0 -4
  129. data/lib/contrast/components/settings.rb +5 -7
  130. data/lib/contrast/config/assess_rules_configuration.rb +1 -3
  131. data/lib/contrast/config/base_configuration.rb +4 -5
  132. data/lib/contrast/config/exception_configuration.rb +1 -5
  133. data/lib/contrast/config/heap_dump_configuration.rb +12 -6
  134. data/lib/contrast/config/logger_configuration.rb +1 -5
  135. data/lib/contrast/configuration.rb +6 -18
  136. data/lib/contrast/extension/assess/array.rb +3 -10
  137. data/lib/contrast/extension/assess/erb.rb +1 -7
  138. data/lib/contrast/extension/assess/eval_trigger.rb +4 -9
  139. data/lib/contrast/extension/assess/exec_trigger.rb +3 -9
  140. data/lib/contrast/extension/assess/fiber.rb +8 -17
  141. data/lib/contrast/extension/assess/hash.rb +3 -3
  142. data/lib/contrast/extension/assess/kernel.rb +4 -13
  143. data/lib/contrast/extension/assess/marshal.rb +6 -10
  144. data/lib/contrast/extension/assess/regexp.rb +6 -10
  145. data/lib/contrast/extension/assess/string.rb +8 -6
  146. data/lib/contrast/extension/kernel.rb +2 -2
  147. data/lib/contrast/extension/protect/kernel.rb +0 -5
  148. data/lib/contrast/framework/manager.rb +3 -5
  149. data/lib/contrast/framework/rack/patch/session_cookie.rb +11 -24
  150. data/lib/contrast/framework/rack/patch/support.rb +6 -4
  151. data/lib/contrast/framework/rails/patch/assess_configuration.rb +12 -9
  152. data/lib/contrast/framework/rails/patch/support.rb +41 -35
  153. data/lib/contrast/framework/rails/railtie.rb +34 -0
  154. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +4 -1
  155. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +2 -0
  156. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +5 -4
  157. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -0
  158. data/lib/contrast/framework/rails/support.rb +2 -2
  159. data/lib/contrast/framework/sinatra/support.rb +3 -1
  160. data/lib/contrast/funchook/funchook.rb +5 -8
  161. data/lib/contrast/logger/application.rb +13 -15
  162. data/lib/contrast/logger/format.rb +2 -5
  163. data/lib/contrast/logger/log.rb +26 -9
  164. data/lib/contrast/logger/request.rb +1 -6
  165. data/lib/contrast/security_exception.rb +1 -1
  166. data/lib/contrast/tasks/config.rb +0 -1
  167. data/lib/contrast/tasks/service.rb +6 -7
  168. data/lib/contrast/utils/assess/sampling_util.rb +2 -3
  169. data/lib/contrast/utils/assess/tracking_util.rb +3 -6
  170. data/lib/contrast/utils/class_util.rb +0 -8
  171. data/lib/contrast/utils/hash_digest.rb +2 -5
  172. data/lib/contrast/utils/heap_dump_util.rb +5 -3
  173. data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
  174. data/lib/contrast/utils/inventory_util.rb +2 -3
  175. data/lib/contrast/utils/io_util.rb +3 -5
  176. data/lib/contrast/utils/job_servers_running.rb +13 -7
  177. data/lib/contrast/utils/os.rb +4 -4
  178. data/lib/contrast/utils/ruby_ast_rewriter.rb +2 -1
  179. data/lib/contrast/utils/string_utils.rb +2 -3
  180. data/lib/contrast/utils/tag_util.rb +25 -19
  181. data/resources/assess/policy.json +55 -0
  182. data/ruby-agent.gemspec +17 -16
  183. data/service_executables/VERSION +1 -1
  184. data/service_executables/linux/contrast-service +0 -0
  185. data/service_executables/mac/contrast-service +0 -0
  186. data/sonar-project.properties +9 -0
  187. metadata +61 -46
  188. data/lib/contrast/agent/railtie.rb +0 -31
  189. data/lib/contrast/components/interface.rb +0 -195
  190. 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::Interface
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 name
41
- @_name ||= begin
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: 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 ||= [name, pgid].join('-')
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 = "Invalid configuration. Setting both application.session_id and application.session_metadata is not allowed.\n"
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
- @_use_bundled_service ||= begin
29
- # Requirement says "must be true" but that
30
- # should be "must not be false" -- oops.
31
- !false?(CONFIG.root.agent.start_bundled_service) &&
32
- # Either a valid host or a valid socket
33
- # Path validity is the service's problem
34
- (LOCALHOST.match?(host) || !!socket_path)
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