contrast-agent 4.8.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.simplecov +1 -0
  4. data/lib/contrast.rb +24 -14
  5. data/lib/contrast/agent/assess/contrast_event.rb +1 -4
  6. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -4
  7. data/lib/contrast/agent/assess/policy/patcher.rb +6 -4
  8. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  9. data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -5
  10. data/lib/contrast/agent/assess/policy/preshift.rb +4 -4
  11. data/lib/contrast/agent/assess/policy/propagation_method.rb +4 -4
  12. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +3 -6
  13. data/lib/contrast/agent/assess/policy/propagator/split.rb +9 -6
  14. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -3
  15. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +7 -7
  16. data/lib/contrast/agent/assess/policy/source_method.rb +6 -6
  17. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -3
  18. data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -3
  19. data/lib/contrast/agent/assess/policy/trigger_node.rb +1 -1
  20. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -4
  21. data/lib/contrast/agent/at_exit_hook.rb +3 -3
  22. data/lib/contrast/agent/class_reopener.rb +6 -5
  23. data/lib/contrast/agent/disable_reaction.rb +3 -4
  24. data/lib/contrast/agent/exclusion_matcher.rb +2 -3
  25. data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
  26. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -5
  27. data/lib/contrast/agent/inventory/policy/datastores.rb +3 -4
  28. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  29. data/lib/contrast/agent/middleware.rb +14 -13
  30. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
  31. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +3 -4
  32. data/lib/contrast/agent/patching/policy/patch.rb +8 -8
  33. data/lib/contrast/agent/patching/policy/patcher.rb +6 -6
  34. data/lib/contrast/agent/patching/policy/policy.rb +2 -4
  35. data/lib/contrast/agent/patching/policy/policy_node.rb +2 -3
  36. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  37. data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -5
  38. data/lib/contrast/agent/protect/rule/base.rb +10 -10
  39. data/lib/contrast/agent/protect/rule/cmd_injection.rb +4 -5
  40. data/lib/contrast/agent/protect/rule/path_traversal.rb +1 -5
  41. data/lib/contrast/agent/reaction_processor.rb +2 -3
  42. data/lib/contrast/agent/request.rb +4 -3
  43. data/lib/contrast/agent/request_context.rb +9 -9
  44. data/lib/contrast/agent/request_handler.rb +5 -3
  45. data/lib/contrast/agent/response.rb +2 -3
  46. data/lib/contrast/agent/rewriter.rb +4 -3
  47. data/lib/contrast/agent/rule_set.rb +5 -4
  48. data/lib/contrast/agent/service_heartbeat.rb +2 -3
  49. data/lib/contrast/agent/static_analysis.rb +6 -5
  50. data/lib/contrast/agent/thread.rb +2 -4
  51. data/lib/contrast/agent/thread_watcher.rb +3 -4
  52. data/lib/contrast/agent/tracepoint_hook.rb +4 -4
  53. data/lib/contrast/agent/version.rb +1 -1
  54. data/lib/contrast/api/communication/messaging_queue.rb +4 -5
  55. data/lib/contrast/api/communication/response_processor.rb +11 -11
  56. data/lib/contrast/api/communication/service_lifecycle.rb +5 -4
  57. data/lib/contrast/api/communication/socket_client.rb +18 -14
  58. data/lib/contrast/api/communication/speedracer.rb +5 -6
  59. data/lib/contrast/api/decorators/address.rb +2 -3
  60. data/lib/contrast/api/decorators/agent_startup.rb +7 -9
  61. data/lib/contrast/api/decorators/application_startup.rb +8 -10
  62. data/lib/contrast/api/decorators/application_update.rb +0 -4
  63. data/lib/contrast/api/decorators/http_request.rb +3 -7
  64. data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
  65. data/lib/contrast/api/decorators/message.rb +7 -7
  66. data/lib/contrast/api/decorators/trace_event_object.rb +2 -3
  67. data/lib/contrast/components/agent.rb +10 -15
  68. data/lib/contrast/components/app_context.rb +7 -11
  69. data/lib/contrast/components/assess.rb +16 -16
  70. data/lib/contrast/components/base.rb +40 -0
  71. data/lib/contrast/components/config.rb +0 -2
  72. data/lib/contrast/components/contrast_service.rb +6 -11
  73. data/lib/contrast/components/heap_dump.rb +5 -4
  74. data/lib/contrast/components/inventory.rb +2 -7
  75. data/lib/contrast/components/logger.rb +1 -2
  76. data/lib/contrast/components/protect.rb +10 -13
  77. data/lib/contrast/components/sampling.rb +5 -5
  78. data/lib/contrast/components/scope.rb +0 -4
  79. data/lib/contrast/components/settings.rb +1 -5
  80. data/lib/contrast/configuration.rb +3 -4
  81. data/lib/contrast/extension/assess/array.rb +2 -4
  82. data/lib/contrast/extension/assess/eval_trigger.rb +2 -3
  83. data/lib/contrast/extension/assess/fiber.rb +6 -5
  84. data/lib/contrast/extension/assess/hash.rb +3 -3
  85. data/lib/contrast/extension/assess/kernel.rb +2 -4
  86. data/lib/contrast/extension/assess/marshal.rb +4 -4
  87. data/lib/contrast/extension/assess/regexp.rb +5 -4
  88. data/lib/contrast/extension/assess/string.rb +6 -6
  89. data/lib/contrast/extension/kernel.rb +2 -4
  90. data/lib/contrast/extension/protect/kernel.rb +0 -5
  91. data/lib/contrast/framework/manager.rb +2 -3
  92. data/lib/contrast/framework/rack/patch/session_cookie.rb +6 -6
  93. data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -7
  94. data/lib/contrast/framework/rails/patch/support.rb +40 -36
  95. data/lib/contrast/framework/rails/railtie.rb +8 -6
  96. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -4
  97. data/lib/contrast/funchook/funchook.rb +4 -3
  98. data/lib/contrast/logger/application.rb +1 -6
  99. data/lib/contrast/logger/log.rb +22 -6
  100. data/lib/contrast/logger/request.rb +0 -4
  101. data/lib/contrast/tasks/service.rb +1 -6
  102. data/lib/contrast/utils/assess/sampling_util.rb +2 -3
  103. data/lib/contrast/utils/assess/tracking_util.rb +2 -4
  104. data/lib/contrast/utils/heap_dump_util.rb +5 -3
  105. data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
  106. data/lib/contrast/utils/inventory_util.rb +2 -3
  107. data/lib/contrast/utils/io_util.rb +2 -4
  108. data/lib/contrast/utils/job_servers_running.rb +4 -3
  109. data/lib/contrast/utils/os.rb +2 -3
  110. data/lib/contrast/utils/string_utils.rb +2 -3
  111. data/lib/contrast/utils/tag_util.rb +25 -19
  112. data/ruby-agent.gemspec +4 -2
  113. data/service_executables/VERSION +1 -1
  114. data/service_executables/linux/contrast-service +0 -0
  115. data/service_executables/mac/contrast-service +0 -0
  116. metadata +28 -15
  117. data/lib/contrast/components/interface.rb +0 -196
  118. data/lib/contrast/delegators/input_analysis.rb +0 -12
@@ -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/components/interface'
5
4
  require 'contrast/utils/string_utils'
6
5
 
7
6
  module Contrast
@@ -11,9 +10,6 @@ module Contrast
11
10
  # model so it can own some of the data massaging required for AppUpdate
12
11
  # dtm.
13
12
  module ApplicationUpdate
14
- include Contrast::Components::Interface
15
- access_component :config
16
-
17
13
  def self.included klass
18
14
  klass.extend(ClassMethods)
19
15
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'contrast/api/dtm.pb'
5
5
  require 'contrast/api/decorators/address'
6
- require 'contrast/components/interface'
6
+ require 'contrast/components/scope'
7
7
  require 'contrast/utils/string_utils'
8
8
  require 'contrast/utils/timer'
9
9
 
@@ -14,9 +14,6 @@ module Contrast
14
14
  # so it can own some of the data massaging required for Request dtm. Only
15
15
  # works as an extension of that class.
16
16
  module HttpRequest
17
- include Contrast::Components::Interface
18
- access_component :agent
19
-
20
17
  OMITTED_BODY = '{{body-omitted-by-contrast}}'
21
18
 
22
19
  def self.included klass
@@ -93,7 +90,7 @@ module Contrast
93
90
  end
94
91
 
95
92
  def omit_body? request
96
- return true if AGENT.omit_body?
93
+ return true if ::Contrast::AGENT.omit_body?
97
94
  return false if request.document_type != :NORMAL
98
95
 
99
96
  request.content_type&.include?('multipart/form-data')
@@ -111,8 +108,7 @@ module Contrast
111
108
 
112
109
  # Used to add class methods to the ApplicationUpdate class on inclusion of the decorator
113
110
  module ClassMethods
114
- include Contrast::Components::Interface
115
- access_component :scope
111
+ include Contrast::Components::Scope::InstanceMethods
116
112
 
117
113
  # Convert our Request into a DTM
118
114
  # @param request [Contrast::Agent::Request]
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/api/dtm.pb'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/base'
6
6
 
7
7
  module Contrast
8
8
  module Api
@@ -10,8 +10,6 @@ module Contrast
10
10
  # Used to decorate the InstrumentationMode protobuf model to handle reporting Agent process start
11
11
  module InstrumentationMode
12
12
  include Contrast::Components::ComponentBase
13
- include Contrast::Components::Interface
14
- access_component :analysis
15
13
 
16
14
  def self.included klass
17
15
  klass.extend(ClassMethods)
@@ -24,8 +22,8 @@ module Contrast
24
22
  # @return [Contrast::Api::Dtm::InstrumentationMode]
25
23
  def build
26
24
  msg = new
27
- msg.assess = ASSESS.enabled?
28
- msg.protect = PROTECT.enabled?
25
+ msg.assess = ::Contrast::ASSESS.enabled?
26
+ msg.protect = ::Contrast::PROTECT.enabled?
29
27
  msg
30
28
  end
31
29
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'contrast/utils/object_share'
5
5
  require 'contrast/utils/string_utils'
6
+ require 'contrast/components/logger'
6
7
 
7
8
  module Contrast
8
9
  module Api
@@ -10,8 +11,7 @@ module Contrast
10
11
  # Used to decorate the {Contrast::Api::Dtm::Message} protobuf model so it
11
12
  # can handle instance data massaging.
12
13
  module Message
13
- include Contrast::Components::Interface
14
- access_component :app_context, :logging
14
+ include Contrast::Components::Logger::InstanceMethods
15
15
 
16
16
  def self.included klass
17
17
  klass.extend(ClassMethods)
@@ -58,13 +58,13 @@ module Contrast
58
58
 
59
59
  def build event
60
60
  msg = new
61
- msg.app_name = APP_CONTEXT.app_name
62
- msg.app_path = APP_CONTEXT.path
61
+ msg.app_name = ::Contrast::APP_CONTEXT.app_name
62
+ msg.app_path = ::Contrast::APP_CONTEXT.path
63
63
  msg.app_language = Contrast::Utils::ObjectShare::RUBY
64
- msg.client_id = APP_CONTEXT.client_id
64
+ msg.client_id = ::Contrast::APP_CONTEXT.client_id
65
65
  msg.message_count = message_count
66
- msg.pid = APP_CONTEXT.pid
67
- msg.ppid = APP_CONTEXT.ppid
66
+ msg.pid = ::Contrast::APP_CONTEXT.pid
67
+ msg.ppid = ::Contrast::APP_CONTEXT.ppid
68
68
  msg.append_event(event)
69
69
  msg
70
70
  end
@@ -4,7 +4,7 @@
4
4
  require 'contrast/utils/string_utils'
5
5
  require 'contrast/utils/assess/tracking_util'
6
6
  require 'base64'
7
- require 'contrast/components/interface'
7
+ require 'contrast/components/scope'
8
8
 
9
9
  module Contrast
10
10
  module Api
@@ -18,8 +18,7 @@ module Contrast
18
18
 
19
19
  # Class methods for TraceEventObject
20
20
  module ClassMethods
21
- include Contrast::Components::Interface
22
- access_component :scope
21
+ include Contrast::Components::Scope::InstanceMethods
23
22
  # Build the event object. We were originally going to include taint on
24
23
  # each one, but TS doesn't accept / use that, so it is a waste of time.
25
24
  #
@@ -12,12 +12,9 @@ module Contrast
12
12
  # Specifically, this allows for querying the state of the Agent.
13
13
  class Interface
14
14
  include Contrast::Components::ComponentBase
15
- include Contrast::Components::Interface
16
-
17
- access_component :analysis, :config, :settings
18
15
 
19
16
  def enabled?
20
- @_enabled = !false?(CONFIG.root.enable) if @_enabled.nil?
17
+ @_enabled = !false?(::Contrast::CONFIG.root.enable) if @_enabled.nil?
21
18
  @_enabled
22
19
  end
23
20
 
@@ -52,34 +49,34 @@ module Contrast
52
49
  end
53
50
 
54
51
  def patch_yield?
55
- @_patch_yield = !false?(CONFIG.root.agent.ruby.propagate_yield) if @_patch_yield.nil?
52
+ @_patch_yield = !false?(::Contrast::CONFIG.root.agent.ruby.propagate_yield) if @_patch_yield.nil?
56
53
  @_patch_yield
57
54
  end
58
55
 
59
56
  def interpolation_enabled?
60
- @_interpolation_enabled = !false?(CONFIG.root.agent.ruby.interpolate) if @_interpolation_enabled.nil?
57
+ @_interpolation_enabled = !false?(::Contrast::CONFIG.root.agent.ruby.interpolate) if @_interpolation_enabled.nil?
61
58
  @_interpolation_enabled
62
59
  end
63
60
 
64
61
  def omit_body?
65
- @_omit_body = true?(CONFIG.root.agent.omit_body) if @_omit_body.nil?
62
+ @_omit_body = true?(::Contrast::CONFIG.root.agent.omit_body) if @_omit_body.nil?
66
63
  @_omit_body
67
64
  end
68
65
 
69
66
  def exception_control
70
67
  @_exception_control ||= {
71
- enable: true?(CONFIG.root.agent.ruby.exceptions.capture),
68
+ enable: true?(::Contrast::CONFIG.root.agent.ruby.exceptions.capture),
72
69
  status:
73
- CONFIG.root.agent.ruby.exceptions.override_status || 403,
70
+ ::Contrast::CONFIG.root.agent.ruby.exceptions.override_status || 403,
74
71
  message:
75
- CONFIG.root.agent.ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
72
+ ::Contrast::CONFIG.root.agent.ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
76
73
  }
77
74
  end
78
75
 
79
76
  def skip_instrumentation? loaded_module_name
80
77
  return true unless loaded_module_name
81
78
 
82
- loaded_module_name.start_with?(*CONFIG.root.agent.ruby.uninstrument_namespace)
79
+ loaded_module_name.start_with?(*::Contrast::CONFIG.root.agent.ruby.uninstrument_namespace)
83
80
  end
84
81
 
85
82
  # Insert ourselves into the application, keeping our middleware at the outermost layer of the onion
@@ -104,13 +101,11 @@ module Contrast
104
101
  end
105
102
 
106
103
  def retrieve_protect_ruleset
107
- return {} unless enabled? && PROTECT.enabled?
104
+ return {} unless enabled? && ::Contrast::PROTECT.enabled?
108
105
 
109
- PROTECT.rules
106
+ ::Contrast::PROTECT.rules
110
107
  end
111
108
  end
112
-
113
- COMPONENT_INTERFACE = Interface.new
114
109
  end
115
110
  end
116
111
  end
@@ -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,7 +29,7 @@ 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
@@ -39,7 +37,7 @@ module Contrast
39
37
 
40
38
  def app_name
41
39
  @_app_name ||= begin
42
- tmp = CONFIG.root.application.name # rubocop:disable Security/Module/Name
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 # rubocop:disable Security/Module/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
@@ -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
@@ -108,8 +108,6 @@ module Contrast
108
108
  @config.application.session_metadata
109
109
  end
110
110
  end
111
-
112
- COMPONENT_INTERFACE = Interface.new
113
111
  end
114
112
  end
115
113
  end
@@ -13,37 +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
25
 
29
26
  # Requirement says "must be true" but that
30
27
  # should be "must not be false" -- oops.
31
- @_use_bundled_service ||= !false?(CONFIG.root.agent.start_bundled_service) &&
28
+ @_use_bundled_service ||= !false?(::Contrast::CONFIG.root.agent.start_bundled_service) &&
32
29
  # Either a valid host or a valid socket
33
30
  # Path validity is the service's problem
34
31
  (LOCALHOST.match?(host) || !!socket_path)
35
32
  end
36
33
 
37
34
  def host
38
- @_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
39
36
  end
40
37
 
41
38
  def port
42
- @_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
43
40
  end
44
41
 
45
42
  def socket_path
46
- @_socket_path ||= CONFIG.root.agent.service.socket
43
+ @_socket_path ||= ::Contrast::CONFIG.root.agent.service.socket
47
44
  end
48
45
 
49
46
  def use_tcp?
@@ -51,18 +48,16 @@ module Contrast
51
48
  end
52
49
 
53
50
  def logger_path
54
- @_logger_path ||= CONFIG.root.agent.service.logger.path || DEFAULT_SERVICE_LOG
51
+ @_logger_path ||= ::Contrast::CONFIG.root.agent.service.logger.path || DEFAULT_SERVICE_LOG
55
52
  end
56
53
 
57
54
  private
58
55
 
59
56
  def disabled?
60
- @_disabled = false?(CONFIG.root.agent.start_bundled_service) if @_disabled.nil?
57
+ @_disabled = false?(::Contrast::CONFIG.root.agent.start_bundled_service) if @_disabled.nil?
61
58
  @_disabled
62
59
  end
63
60
  end
64
-
65
- COMPONENT_INTERFACE = Interface.new
66
61
  end
67
62
  end
68
63
  end