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,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 Sampling
@@ -15,9 +17,6 @@ module Contrast
15
17
  module ClassMethods #:nodoc:
16
18
  include Contrast::Components::ComponentBase
17
19
  include Constants
18
- include Contrast::Components::Interface
19
-
20
- access_component :config, :settings
21
20
 
22
21
  def sampling_enabled?
23
22
  sampling_control[:enabled]
@@ -25,8 +24,8 @@ module Contrast
25
24
 
26
25
  def sampling_control
27
26
  @_sampling_control ||= begin
28
- config_settings = CONFIG.root.assess&.sampling
29
- settings = SETTINGS&.assess_state&.[](:sampling_settings)
27
+ config_settings = ::Contrast::CONFIG.root.assess&.sampling
28
+ settings = ::Contrast::SETTINGS&.assess_state&.[](:sampling_settings)
30
29
  {
31
30
  enabled: enabled?(config_settings, settings),
32
31
  baseline: baseline(config_settings, settings),
@@ -65,7 +64,10 @@ module Contrast
65
64
  # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
66
65
  # @return [Integer] the resolution of the config_settings, settings, and default value
67
66
  def request_frequency config_settings, settings
68
- [config_settings&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY].map(&:to_i).find(&:positive?)
67
+ [
68
+ config_settings&.request_frequency, settings&.request_frequency,
69
+ DEFAULT_SAMPLING_REQUEST_FREQUENCY
70
+ ].map(&:to_i).find(&:positive?)
69
71
  end
70
72
 
71
73
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
@@ -73,7 +75,10 @@ module Contrast
73
75
  # @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
74
76
  # @return [Integer] the resolution of the config_settings, settings, and default value
75
77
  def response_frequency config_settings, settings
76
- [config_settings&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?)
78
+ [
79
+ config_settings&.response_frequency, settings&.response_frequency,
80
+ DEFAULT_SAMPLING_RESPONSE_FREQUENCY
81
+ ].map(&:to_i).find(&:positive?)
77
82
  end
78
83
 
79
84
  # @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
@@ -88,6 +93,7 @@ module Contrast
88
93
  module InstanceMethods #:nodoc:
89
94
  include Contrast::Components::ComponentBase
90
95
  include Constants
96
+ include ClassMethods
91
97
  end
92
98
  end
93
99
  end
@@ -20,8 +20,6 @@ module Contrast
20
20
  EXECUTION_CONTEXT = {} # rubocop:disable Style/MutableConstant
21
21
 
22
22
  class Interface # :nodoc:
23
- include Contrast::Components::ComponentBase
24
-
25
23
  def initialize
26
24
  # This is probably redundant with #scope_for_current_ec's nil check.
27
25
  EXECUTION_CONTEXT[Fiber.current] = Contrast::Agent::Scope.new
@@ -146,8 +144,6 @@ module Contrast
146
144
  end
147
145
 
148
146
  ClassMethods = InstanceMethods
149
-
150
- COMPONENT_INTERFACE = Interface.new
151
147
  end
152
148
  end
153
149
  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/api/settings.pb'
5
+
4
6
  module Contrast
5
7
  module Components
6
8
  # This component encapsulates the statefulness of settings.
@@ -8,8 +10,8 @@ module Contrast
8
10
  # directives (likely provided by TeamServer) about product operation.
9
11
  # 'Settings' is not a generic term for 'configurable stuff'.
10
12
  module Settings
11
- APPLICATION_STATE_BASE = Struct.new(:modes_by_id, :exclusion_matchers).new(
12
- Hash.new { Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION }, [])
13
+ APPLICATION_STATE_BASE = Struct.new(:modes_by_id, :exclusion_matchers).
14
+ new(Hash.new(Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION), [])
13
15
  PROTECT_STATE_BASE = Struct.new(:enabled, :rules).new(false, {})
14
16
  ASSESS_STATE_BASE = Struct.new(:enabled, :sampling_settings, :disabled_assess_rules).new(false, nil, []) do
15
17
  def sampling_settings= new_val
@@ -20,9 +22,7 @@ module Contrast
20
22
 
21
23
  # This is a class.
22
24
  class Interface
23
- include Contrast::Components::ComponentBase
24
- include Contrast::Components::Interface
25
- access_component :config
25
+ extend Contrast::Components::Config
26
26
 
27
27
  # tainted_columns are database columns that receive unsanitized input.
28
28
  attr_reader :tainted_columns # This can probably go into assess_state?
@@ -74,8 +74,6 @@ module Contrast
74
74
  Contrast::Agent::Protect::Rule::Xxe.new
75
75
  end
76
76
  end
77
-
78
- COMPONENT_INTERFACE = Interface.new
79
77
  end
80
78
  end
81
79
  end
@@ -6,9 +6,7 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # disabled assess rule functionality of the Agent.
8
8
  class AssessRulesConfiguration < BaseConfiguration
9
- KEYS = {
10
- disabled_rules: EMPTY_VALUE
11
- }.cs__freeze
9
+ KEYS = { disabled_rules: EMPTY_VALUE }.cs__freeze
12
10
 
13
11
  def initialize hsh
14
12
  super(hsh, KEYS)
@@ -17,10 +17,7 @@ module Contrast
17
17
  attr_reader :map
18
18
 
19
19
  alias_method :to_hash, :map
20
- def_delegators :@map, :empty?, :key?,
21
- :delete,
22
- :fetch, :[], :[]=,
23
- :each, :each_pair, :each_key, :each_value
20
+ def_delegators :@map, :empty?, :key?, :delete, :fetch, :[], :[]=, :each, :each_pair, :each_key, :each_value
24
21
 
25
22
  EMPTY_VALUE = :EMPTY_VALUE
26
23
 
@@ -35,7 +32,9 @@ module Contrast
35
32
  current_level = current_level.send(segment) if current_level.cs__respond_to?(segment)
36
33
  end
37
34
  last_entry = dot_path_array[-1]
38
- current_level.send("#{ last_entry }=", value) if current_level.nil? == false && current_level.cs__respond_to?(last_entry)
35
+ if current_level.nil? == false && current_level.cs__respond_to?(last_entry)
36
+ current_level.send("#{ last_entry }=", value)
37
+ end
39
38
  nil
40
39
  end
41
40
 
@@ -7,11 +7,7 @@ module Contrast
7
7
  # exception handling in Ruby, allowing for the override of Response Code
8
8
  # and Message when Security Exceptions are raised.
9
9
  class ExceptionConfiguration < BaseConfiguration
10
- KEYS = {
11
- capture: EMPTY_VALUE,
12
- override_status: EMPTY_VALUE,
13
- override_message: EMPTY_VALUE
14
- }.cs__freeze
10
+ KEYS = { capture: EMPTY_VALUE, override_status: EMPTY_VALUE, override_message: EMPTY_VALUE }.cs__freeze
15
11
 
16
12
  def initialize hsh
17
13
  super(hsh, KEYS)
@@ -7,12 +7,18 @@ module Contrast
7
7
  # Heap Dump collection functionality of the Agent.
8
8
  class HeapDumpConfiguration < BaseConfiguration
9
9
  KEYS = {
10
- enable: Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::FALSE), # should dumps be taken
11
- path: Contrast::Config::DefaultValue.new('contrast_heap_dumps'), # dir to which dumps should be saved
12
- delay_ms: Contrast::Config::DefaultValue.new(10_000), # time, in ms, after initialization to delay before taking dump
13
- window_ms: Contrast::Config::DefaultValue.new(10_000), # ms between each dump
14
- count: Contrast::Config::DefaultValue.new(5), # number of dumps to take
15
- clean: Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::FALSE) # remove temporary objects
10
+ enable: # should dumps be taken
11
+ Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::FALSE),
12
+ path: # dir to which dumps should be
13
+ Contrast::Config::DefaultValue.new('contrast_heap_dumps'), # saved
14
+ delay_ms: # time, in ms, after initialization
15
+ Contrast::Config::DefaultValue.new(10_000), # to delay before taking dump
16
+ window_ms: # ms between each dump
17
+ Contrast::Config::DefaultValue.new(10_000), #
18
+ count: # number of dumps to take
19
+ Contrast::Config::DefaultValue.new(5), #
20
+ clean: # remove temporary objects or not
21
+ Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::FALSE) #
16
22
  }.cs__freeze
17
23
 
18
24
  def initialize hsh
@@ -6,11 +6,7 @@ module Contrast
6
6
  # Common Configuration settings. Those in this section pertain to the
7
7
  # logging in the Agent.
8
8
  class LoggerConfiguration < BaseConfiguration
9
- KEYS = {
10
- path: EMPTY_VALUE,
11
- level: EMPTY_VALUE,
12
- progname: EMPTY_VALUE
13
- }.cs__freeze
9
+ KEYS = { path: EMPTY_VALUE, level: EMPTY_VALUE, progname: EMPTY_VALUE }.cs__freeze
14
10
 
15
11
  def initialize hsh
16
12
  super(hsh, KEYS)
@@ -6,7 +6,7 @@ require 'fileutils'
6
6
 
7
7
  require 'contrast/config'
8
8
  require 'contrast/utils/object_share'
9
- require 'contrast/components/interface'
9
+ require 'contrast/components/scope'
10
10
 
11
11
  module Contrast
12
12
  # This is how we read in the local settings for the Agent, both ENV/ CMD line
@@ -15,9 +15,8 @@ module Contrast
15
15
  class Configuration
16
16
  extend Forwardable
17
17
 
18
- include Contrast::Components::Interface
19
-
20
- access_component :scope
18
+ include Contrast::Components::Scope::InstanceMethods
19
+ extend Contrast::Components::Scope::InstanceMethods
21
20
 
22
21
  def_delegator :root, :assign_value_to_path_array
23
22
 
@@ -25,16 +24,8 @@ module Contrast
25
24
 
26
25
  DEFAULT_YAML_PATH = 'contrast_security.yaml'
27
26
  MILLISECOND_MARKER = '_ms'
28
- CONVERSION = {
29
- 'agent.service.enable' => 'agent.start_bundled_service'
30
- }.cs__freeze
31
- CONFIG_BASE_PATHS = [
32
- '',
33
- 'config/',
34
- '/etc/contrast/ruby/',
35
- '/etc/contrast/',
36
- '/etc/'
37
- ].cs__freeze
27
+ CONVERSION = { 'agent.service.enable' => 'agent.start_bundled_service' }.cs__freeze
28
+ CONFIG_BASE_PATHS = ['', 'config/', '/etc/contrast/ruby/', '/etc/contrast/', '/etc/'].cs__freeze
38
29
 
39
30
  def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH
40
31
  @default_name = default_name
@@ -189,10 +180,7 @@ module Contrast
189
180
  # When we fail to parse a configuration because it is misformatted, log an
190
181
  # appropriate message based on the Agent Onboarding specification
191
182
  def log_yaml_parse_error path, exception
192
- hash = {
193
- path: path,
194
- pwd: Dir.pwd
195
- }
183
+ hash = { path: path, pwd: Dir.pwd }
196
184
  if exception.is_a?(Psych::SyntaxError)
197
185
  hash[:context] = exception.context
198
186
  hash[:column] = exception.column
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'contrast/agent/patching/policy/patch'
5
5
  require 'contrast/agent/patching/policy/patcher'
6
- require 'contrast/components/interface'
6
+ require 'contrast/components/scope'
7
7
 
8
8
  module Contrast
9
9
  module Extension
@@ -12,9 +12,7 @@ module Contrast
12
12
  # Disclaimer: there may be a better way, but we're in a 'get it work' state.
13
13
  # Hopefully, we'll be in a 'get it right' state soon.
14
14
  class ArrayPropagator
15
- include Contrast::Components::Interface
16
-
17
- access_component :scope
15
+ extend Contrast::Components::Scope::InstanceMethods
18
16
 
19
17
  ARRAY_JOIN_HASH = {
20
18
  'class_name' => 'Array',
@@ -56,12 +54,7 @@ module Contrast
56
54
  return ret unless Contrast::Agent::Assess::Tracker.tracked?(ret)
57
55
 
58
56
  properties.cleanup_tags
59
- properties.build_event(
60
- ARRAY_JOIN_NODE,
61
- ret,
62
- ary,
63
- ret,
64
- [separator])
57
+ properties.build_event(ARRAY_JOIN_NODE, ret, ary, ret, [separator])
65
58
  properties.event.instance_variable_set(:@_parent_events, parent_events)
66
59
  ret
67
60
  end
@@ -25,13 +25,7 @@ module ERBPropagator
25
25
  parent_event = Contrast::Agent::Assess::Tracker.properties(bound_variable_value)&.event
26
26
  parent_events << parent_event if parent_event
27
27
  end
28
- properties.build_event(
29
- patcher,
30
- ret,
31
- preshift.object,
32
- ret,
33
- preshift.args,
34
- 1)
28
+ properties.build_event(patcher, ret, preshift.object, ret, preshift.args, 1)
35
29
  properties.event.instance_variable_set(:@_parent_events, parent_events)
36
30
 
37
31
  ret
@@ -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 Extension
@@ -11,8 +11,7 @@ module Contrast
11
11
  # apply the trigger in a custom patch over one of the generic triggers in
12
12
  # TriggerMethod.
13
13
  class EvalTrigger
14
- include Contrast::Components::Interface
15
- access_component :logging
14
+ include Contrast::Components::Logger::InstanceMethods
16
15
 
17
16
  class << self
18
17
  def instance_eval_trigger_check obj, source, ret
@@ -31,12 +30,8 @@ module Contrast
31
30
  # source might not be all the args passed in, but it is the one we care
32
31
  # about. we could pass in all the args in the last param here if it
33
32
  # becomes an issue in rendering on TS
34
- Contrast::Agent::Assess::Policy::TriggerMethod.apply_eval_trigger(
35
- trigger_node(clazz, method),
36
- source,
37
- obj,
38
- ret,
39
- source)
33
+ Contrast::Agent::Assess::Policy::TriggerMethod.apply_eval_trigger(trigger_node(clazz, method), source, obj,
34
+ ret, source)
40
35
  end
41
36
 
42
37
  def instrument_basic_object_track
@@ -18,20 +18,14 @@ module Contrast
18
18
  # source might not be all the args passed in, but it is the one we care
19
19
  # about. we could pass in all the args in the last param here if it
20
20
  # becomes an issue in rendering on TS
21
- Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(
22
- trigger_node,
23
- source,
24
- Kernel,
25
- nil,
26
- source)
21
+ Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node, source, Kernel, nil, source)
27
22
  end
28
23
 
29
24
  private
30
25
 
31
26
  def trigger_node
32
- @_trigger_node ||= begin
33
- Contrast::Agent::Assess::Policy::Policy.instance.find_node('cmd-injection', 'Kernel', :exec, false)
34
- end
27
+ @_trigger_node ||= Contrast::Agent::Assess::Policy::Policy.instance.find_node('cmd-injection', 'Kernel',
28
+ :exec, false)
35
29
  end
36
30
  end
37
31
  end
@@ -2,7 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/assess/policy/propagation_node'
5
- require 'contrast/components/interface'
5
+ require 'contrast/components/logger'
6
+ require 'contrast/components/scope'
6
7
 
7
8
  # In order to instrument some difficult methods like String#gsub, as it
8
9
  # returns an enumerator, we need to instrument methods on Fiber.
@@ -16,9 +17,9 @@ module Contrast
16
17
  # Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
17
18
  # Fiber Class or exposing our methods there.
18
19
  class FiberPropagator
19
- include Contrast::Components::Interface
20
+ extend Contrast::Components::Logger::InstanceMethods
21
+ extend Contrast::Components::Scope::InstanceMethods
20
22
 
21
- access_component :analysis, :logging, :scope
22
23
 
23
24
  # we use funchook to patch rb_fiber_new the initialize method is not exposed by Ruby core
24
25
  FIBER_NEW_NODE_HASH = {
@@ -53,7 +54,7 @@ module Contrast
53
54
 
54
55
  class << self
55
56
  def track_rb_fiber_yield fiber, _method, results
56
- return unless ASSESS.enabled?
57
+ return unless ::Contrast::ASSESS.enabled?
57
58
 
58
59
  # results will be nil if StopIteration was raised,
59
60
  # otherwise an Array of the yielded arguments
@@ -64,12 +65,7 @@ module Contrast
64
65
  next unless (result_properties = Contrast::Agent::Assess::Tracker.properties!(result))
65
66
 
66
67
  result_properties.splat_from(fiber, result)
67
- result_properties.build_event(
68
- FIBER_YIELD_NODE,
69
- result,
70
- fiber,
71
- result,
72
- [])
68
+ result_properties.build_event(FIBER_YIELD_NODE, result, fiber, result, [])
73
69
  end
74
70
  end
75
71
  rescue Exception => e # rubocop:disable Lint/RescueException
@@ -77,7 +73,7 @@ module Contrast
77
73
  end
78
74
 
79
75
  def track_rb_fiber_new fiber, _enum, _enum_method, underlying, _underlying_method
80
- return unless ASSESS.enabled?
76
+ return unless ::Contrast::ASSESS.enabled?
81
77
  return unless underlying.is_a?(String) && !underlying.empty?
82
78
 
83
79
  with_contrast_scope do
@@ -85,12 +81,7 @@ module Contrast
85
81
  return unless properties
86
82
 
87
83
  properties.splat_from(underlying, fiber)
88
- properties.build_event(
89
- FIBER_NEW_NODE,
90
- fiber,
91
- underlying,
92
- fiber,
93
- [])
84
+ properties.build_event(FIBER_NEW_NODE, fiber, underlying, fiber, [])
94
85
  end
95
86
  rescue Exception => e # rubocop:disable Lint/RescueException
96
87
  logger.error('Unable to propagate during Fiber.new', e)
@@ -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 Extension
@@ -10,8 +10,8 @@ module Contrast
10
10
  # methods which are too complex to fit into one of the standard
11
11
  # Contrast::Agent::Assess::Policy::Propagator molds.
12
12
  class HashPropagator
13
- include Contrast::Components::Interface
14
- access_component :logging
13
+ include Contrast::Components::Logger::InstanceMethods
14
+
15
15
  class << self
16
16
  def cs__duplicate_and_freeze object
17
17
  return object unless object.is_a?(String) && !object.cs__frozen?