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
@@ -1,7 +1,7 @@
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'
4
+ require 'contrast/components/logger'
5
5
 
6
6
  module Contrast
7
7
  module Api
@@ -9,8 +9,7 @@ module Contrast
9
9
  # Wraps all connection data to speedracer
10
10
  class Speedracer
11
11
  include Contrast::Api::Communication::ServiceLifecycle
12
- include Contrast::Components::Interface
13
- access_component :contrast_service, :logging, :app_context
12
+ include Contrast::Components::Logger::InstanceMethods
14
13
 
15
14
  attr_reader :status, :response_processor, :socket_client, :ensure_running
16
15
 
@@ -25,7 +24,7 @@ module Contrast
25
24
  return if status.connected?
26
25
 
27
26
  ensure_running.synchronize do
28
- if CONTRAST_SERVICE.use_bundled_service?
27
+ if ::Contrast::CONTRAST_SERVICE.use_bundled_service?
29
28
  logger.info('Attempting to start local service')
30
29
  unless attempt_local_service_startup
31
30
  logger.error('Failed to start local service')
@@ -58,21 +57,19 @@ module Contrast
58
57
  def send_to_speedracer event
59
58
  ensure_startup!
60
59
 
61
- logger.debug_with_time(event.cs__class.name) do
60
+ logger.debug_with_time(event.cs__class.cs__name) do
62
61
  response = socket_client.send_one event
63
62
  status.success!
64
63
  yield response
65
64
  end
66
65
  rescue StandardError => e
67
66
  status.failure!
68
- logger.error('Unable to send message.', e,
69
- event_id: event.__id__,
70
- event_type: event.cs__class.name)
67
+ logger.error('Unable to send message.', e, event_id: event.__id__, event_type: event.cs__class.cs__name)
71
68
  nil
72
69
  end
73
70
 
74
71
  def send_initialization_messages
75
- agent_startup_msg = APP_CONTEXT.build_agent_startup_message
72
+ agent_startup_msg = ::Contrast::APP_CONTEXT.build_agent_startup_message
76
73
 
77
74
  logger.debug('Preparing to send startup messages')
78
75
  # 1 initial attempt, + 3 potential retries.
@@ -82,7 +79,7 @@ module Contrast
82
79
  next unless (agent_response = socket_client.send_one(agent_startup_msg))
83
80
 
84
81
  # Connection was successful; send app create with the resolved features.
85
- app_startup_msg = APP_CONTEXT.build_app_startup_message
82
+ app_startup_msg = ::Contrast::APP_CONTEXT.build_app_startup_message
86
83
  log_send_event(app_startup_msg)
87
84
  app_response = socket_client.send_one(app_startup_msg)
88
85
 
@@ -101,9 +98,7 @@ module Contrast
101
98
  end
102
99
 
103
100
  def log_send_event event
104
- logger.debug('Immediately sending event.',
105
- event_id: event.__id__,
106
- event_type: event.cs__class.name)
101
+ logger.debug('Immediately sending event.', event_id: event.__id__, event_type: event.cs__class.cs__name)
107
102
  end
108
103
  end
109
104
  end
@@ -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/logger'
6
6
  require 'contrast/utils/string_utils'
7
7
  require 'contrast/utils/timer'
8
8
 
@@ -19,8 +19,7 @@ module Contrast
19
19
 
20
20
  # Used to add class methods to the ApplicationUpdate class on inclusion of the decorator
21
21
  module ClassMethods
22
- include Contrast::Components::Interface
23
- access_component :logging
22
+ include Contrast::Components::Logger::InstanceMethods
24
23
  # receiver is memoized because it is the address/host/port of the server, once we
25
24
  # resolve this for the first time, it shouldn't change
26
25
  #
@@ -2,8 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/api/dtm.pb'
5
- require 'contrast/components/interface'
6
5
  require 'contrast/utils/string_utils'
6
+ require 'contrast/components/base'
7
7
 
8
8
  module Contrast
9
9
  module Api
@@ -11,8 +11,6 @@ module Contrast
11
11
  # Used to decorate the AgentStartup protobuf model to handle reporting Agent process start
12
12
  module AgentStartup
13
13
  include Contrast::Components::ComponentBase
14
- include Contrast::Components::Interface
15
- access_component :analysis, :config
16
14
 
17
15
  def self.included klass
18
16
  klass.extend(ClassMethods)
@@ -33,7 +31,7 @@ module Contrast
33
31
  msg.server_path = Contrast::Utils::StringUtils.protobuf_format path
34
32
  msg.server_type = Contrast::Utils::StringUtils.protobuf_format type
35
33
  config!(msg)
36
- msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ASSESS.tags
34
+ msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ::Contrast::ASSESS.tags
37
35
  msg
38
36
  end
39
37
 
@@ -43,11 +41,11 @@ module Contrast
43
41
  #
44
42
  # @param msg [Contrast::Api::Dtm::AgentStartup]
45
43
  def config! msg
46
- msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
47
- msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
48
- msg.server_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
49
- msg.application_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
50
- msg.library_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory.tags
44
+ msg.version = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.server.version
45
+ msg.environment = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.server.environment
46
+ msg.server_tags = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.server.tags
47
+ msg.application_tags = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.application.tags
48
+ msg.library_tags = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.inventory.tags
51
49
  end
52
50
  end
53
51
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'contrast/api/dtm.pb'
5
5
  require 'contrast/api/decorators/instrumentation_mode'
6
- require 'contrast/components/interface'
6
+ require 'contrast/components/base'
7
7
  require 'contrast/utils/string_utils'
8
8
 
9
9
  module Contrast
@@ -12,8 +12,6 @@ module Contrast
12
12
  # Used to decorate the ApplicationCreate protobuf model to handle reporting Agent process start
13
13
  module ApplicationStartup
14
14
  include Contrast::Components::ComponentBase
15
- include Contrast::Components::Interface
16
- access_component :config
17
15
 
18
16
  def self.included klass
19
17
  klass.extend(ClassMethods)
@@ -26,11 +24,11 @@ module Contrast
26
24
  # @return [Contrast::Api::Dtm::ApplicationCreate]
27
25
  def build
28
26
  msg = new
29
- msg.app_version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.version.to_s
30
- msg.code = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.code
31
- msg.group = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.group
32
- msg.metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.metadata
33
- msg.mode = Contrast::Api::Dtm::InstrumentationMode.build
27
+ msg.app_version = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.application.version.to_s
28
+ msg.code = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.application.code
29
+ msg.group = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.application.group
30
+ msg.metadata = Contrast::Utils::StringUtils.protobuf_format ::Contrast::CONFIG.root.application.metadata
31
+ msg.mode = Contrast::Api::Dtm::InstrumentationMode.build
34
32
  session!(msg)
35
33
  msg
36
34
  end
@@ -41,8 +39,12 @@ module Contrast
41
39
  #
42
40
  # @param msg [Contrast::Api::Dtm::ApplicationCreate]
43
41
  def session! msg
44
- msg.session_id = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_id, truncate: false
45
- msg.session_metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_metadata, truncate: false
42
+ msg.session_id = Contrast::Utils::StringUtils.protobuf_format(
43
+ ::Contrast::CONFIG.root.application.session_id,
44
+ truncate: false)
45
+ msg.session_metadata = Contrast::Utils::StringUtils.protobuf_format(
46
+ ::Contrast::CONFIG.root.application.session_metadata,
47
+ truncate: false)
46
48
  end
47
49
  end
48
50
  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/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
@@ -10,6 +10,8 @@ module Contrast
10
10
  module Decorators
11
11
  # Used to decorate the Library protobuf model to handle Gem::Specification translation
12
12
  module Library
13
+ StringUtils = Contrast::Utils::StringUtils
14
+
13
15
  def self.included klass
14
16
  klass.extend(ClassMethods)
15
17
  end
@@ -18,13 +20,13 @@ module Contrast
18
20
  module ClassMethods
19
21
  def build digest, gem_specification
20
22
  msg = new
21
- msg.file_path = Contrast::Utils::StringUtils.force_utf8(gem_specification.name)
22
- msg.hash_code = Contrast::Utils::StringUtils.force_utf8(digest)
23
- msg.version = Contrast::Utils::StringUtils.force_utf8(gem_specification.version)
24
- msg.manifest = Contrast::Utils::StringUtils.force_utf8(build_manifest(gem_specification))
23
+ msg.file_path = StringUtils.force_utf8(gem_specification.name) # rubocop:disable Security/Module/Name
24
+ msg.hash_code = StringUtils.force_utf8(digest)
25
+ msg.version = StringUtils.force_utf8(gem_specification.version)
26
+ msg.manifest = StringUtils.force_utf8(build_manifest(gem_specification))
25
27
  msg.external_ms = date_to_ms(gem_specification.date)
26
28
  msg.internal_ms = msg.external_ms
27
- msg.url = Contrast::Utils::StringUtils.force_utf8(gem_specification.homepage)
29
+ msg.url = StringUtils.force_utf8(gem_specification.homepage)
28
30
  msg.class_count = file_count(gem_specification.full_gem_path.to_s)
29
31
  msg.used_class_count = 0
30
32
  msg
@@ -37,7 +39,7 @@ module Contrast
37
39
  end
38
40
 
39
41
  def build_manifest spec
40
- Contrast::Utils::StringUtils.force_utf8(spec.to_yaml.to_s)
42
+ StringUtils.force_utf8(spec.to_yaml.to_s)
41
43
  rescue StandardError
42
44
  nil
43
45
  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)
@@ -38,7 +38,7 @@ module Contrast
38
38
  when Contrast::Api::Dtm::ObservedRoute
39
39
  self.observed_route = event
40
40
  else
41
- logger.error('Unknown event type received. Unsure how to send.', event_type: event.cs__class.name)
41
+ logger.error('Unknown event type received. Unsure how to send.', event_type: event.cs__class.cs__name)
42
42
  return
43
43
  end
44
44
  logger.debug('Wrapping event in message',
@@ -46,7 +46,7 @@ module Contrast
46
46
  p_id: pid,
47
47
  msg_count: message_count,
48
48
  event_id: event.__id__,
49
- event_type: event.cs__class.name)
49
+ event_type: event.cs__class.cs__name)
50
50
  end
51
51
 
52
52
  # Used to add class methods to the ApplicationUpdate class on inclusion of the decorator
@@ -58,13 +58,13 @@ module Contrast
58
58
 
59
59
  def build event
60
60
  msg = new
61
- msg.app_name = APP_CONTEXT.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
@@ -106,7 +106,9 @@ module Contrast
106
106
  event_dtm.thread = Contrast::Utils::StringUtils.force_utf8(contrast_event.thread)
107
107
  event_dtm.build_parent_ids!(contrast_event)
108
108
  event_dtm.object_id = contrast_event.event_id.to_i
109
- event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret, contrast_event.policy_node, contrast_event.args)
109
+ event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret,
110
+ contrast_event.policy_node,
111
+ contrast_event.args)
110
112
  event_dtm
111
113
  end
112
114
  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
  #
@@ -52,9 +51,7 @@ module Contrast
52
51
  tmp = []
53
52
  tmp << obj_string[0, UNTRUNCATED_PORTION_LENGTH]
54
53
  tmp << ELLIPSIS
55
- tmp << obj_string[
56
- obj_string.length - UNTRUNCATED_PORTION_LENGTH,
57
- UNTRUNCATED_PORTION_LENGTH]
54
+ tmp << obj_string[obj_string.length - UNTRUNCATED_PORTION_LENGTH, UNTRUNCATED_PORTION_LENGTH]
58
55
  tmp.join
59
56
  end
60
57
  end
@@ -97,12 +97,7 @@ module Contrast
97
97
  DATABASE_WRITE
98
98
  ].cs__freeze
99
99
 
100
- VALID_SOURCE_TAGS = %w[
101
- NO_NEWLINES
102
- UNTRUSTED
103
- CROSS_SITE
104
- LIMITED_CHARS
105
- ].cs__freeze
100
+ VALID_SOURCE_TAGS = %w[NO_NEWLINES UNTRUSTED CROSS_SITE LIMITED_CHARS].cs__freeze
106
101
  end
107
102
  end
108
103
  end
@@ -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,36 +49,39 @@ 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),
72
- status: CONFIG.root.agent.ruby.exceptions.override_status || 403,
73
- message: CONFIG.root.agent.ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
68
+ enable: true?(::Contrast::CONFIG.root.agent.ruby.exceptions.capture),
69
+ status:
70
+ ::Contrast::CONFIG.root.agent.ruby.exceptions.override_status || 403,
71
+ message:
72
+ ::Contrast::CONFIG.root.agent.ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
74
73
  }
75
74
  end
76
75
 
77
76
  def skip_instrumentation? loaded_module_name
78
77
  return true unless loaded_module_name
79
78
 
80
- loaded_module_name.start_with?(*CONFIG.root.agent.ruby.uninstrument_namespace)
79
+ loaded_module_name.start_with?(*::Contrast::CONFIG.root.agent.ruby.uninstrument_namespace)
81
80
  end
82
81
 
82
+ # Insert ourselves into the application, keeping our middleware at the outermost layer of the onion
83
83
  def insert_middleware app
84
- app.middleware.insert_before 0, Contrast::Agent::Middleware # Keep our middleware at the outermost layer of the onion
84
+ app.middleware.insert_before 0, Contrast::Agent::Middleware
85
85
  end
86
86
 
87
87
  def enable_tracepoint
@@ -94,18 +94,18 @@ module Contrast
94
94
  # Ruby exposed the C method for interpolation in version 2.6.0, meaning
95
95
  # we can attempt to patch using Funchook for that version and later.
96
96
  def interpolation_patch_possible?
97
- @_interpolation_patch_possible = Gem::Version.new(RUBY_VERSION) >= INTERPOLATION_HOOKABLE_VERSION if @_interpolation_patch_possible.nil?
97
+ if @_interpolation_patch_possible.nil?
98
+ @_interpolation_patch_possible = Gem::Version.new(RUBY_VERSION) >= INTERPOLATION_HOOKABLE_VERSION
99
+ end
98
100
  @_interpolation_patch_possible
99
101
  end
100
102
 
101
103
  def retrieve_protect_ruleset
102
- return {} unless enabled? && PROTECT.enabled?
104
+ return {} unless enabled? && ::Contrast::PROTECT.enabled?
103
105
 
104
- PROTECT.rules
106
+ ::Contrast::PROTECT.rules
105
107
  end
106
108
  end
107
-
108
- COMPONENT_INTERFACE = Interface.new
109
109
  end
110
110
  end
111
111
  end