contrast-agent 3.13.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/exe/contrast_service +1 -7
  3. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  4. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  5. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  6. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
  7. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  8. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
  11. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  12. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  13. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  14. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  15. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  16. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
  17. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
  18. data/ext/cs__common/cs__common.c +48 -39
  19. data/ext/cs__common/cs__common.h +16 -21
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  21. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  22. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  23. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  24. data/lib/contrast-agent.rb +1 -1
  25. data/lib/contrast.rb +13 -23
  26. data/lib/contrast/agent.rb +39 -47
  27. data/lib/contrast/agent/assess.rb +12 -12
  28. data/lib/contrast/agent/assess/contrast_event.rb +151 -85
  29. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  30. data/lib/contrast/agent/assess/events/source_event.rb +3 -3
  31. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  32. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  33. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
  34. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  35. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  36. data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
  37. data/lib/contrast/agent/assess/policy/policy_scanner.rb +21 -5
  38. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  39. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
  40. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
  41. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  42. data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
  43. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  45. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  47. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
  48. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  49. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
  50. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  51. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  52. data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
  53. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  54. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  55. data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
  56. data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
  57. data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
  58. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
  59. data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
  60. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  61. data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
  62. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
  65. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  66. data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
  67. data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
  68. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  69. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  70. data/lib/contrast/agent/assess/properties.rb +15 -5
  71. data/lib/contrast/agent/assess/property/evented.rb +7 -20
  72. data/lib/contrast/agent/assess/property/tagged.rb +13 -7
  73. data/lib/contrast/agent/assess/property/updated.rb +131 -0
  74. data/lib/contrast/agent/assess/rule.rb +2 -2
  75. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  76. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  77. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  78. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
  79. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +85 -16
  80. data/lib/contrast/agent/assess/tag.rb +1 -1
  81. data/lib/contrast/agent/assess/tracker.rb +66 -0
  82. data/lib/contrast/agent/at_exit_hook.rb +6 -6
  83. data/lib/contrast/agent/class_reopener.rb +14 -11
  84. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  85. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  86. data/lib/contrast/agent/disable_reaction.rb +1 -1
  87. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  88. data/lib/contrast/agent/inventory.rb +15 -0
  89. data/lib/contrast/agent/inventory/dependencies.rb +50 -0
  90. data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
  91. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
  92. data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
  93. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  94. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  95. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  96. data/lib/contrast/agent/middleware.rb +33 -34
  97. data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
  98. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
  99. data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
  100. data/lib/contrast/agent/patching/policy/patch.rb +15 -15
  101. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  102. data/lib/contrast/agent/patching/policy/policy.rb +23 -12
  103. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  104. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  105. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
  106. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  107. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  108. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +7 -6
  109. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  110. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
  111. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  112. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  113. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  114. data/lib/contrast/agent/protect/rule.rb +18 -18
  115. data/lib/contrast/agent/protect/rule/base.rb +4 -3
  116. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  117. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  118. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  119. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  120. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  121. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  122. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  123. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  124. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  125. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  126. data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
  127. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  128. data/lib/contrast/agent/railtie.rb +1 -1
  129. data/lib/contrast/agent/reaction_processor.rb +2 -2
  130. data/lib/contrast/agent/request.rb +45 -43
  131. data/lib/contrast/agent/request_context.rb +10 -6
  132. data/lib/contrast/agent/request_handler.rb +1 -1
  133. data/lib/contrast/agent/response.rb +23 -12
  134. data/lib/contrast/agent/rewriter.rb +6 -9
  135. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  136. data/lib/contrast/agent/static_analysis.rb +9 -9
  137. data/lib/contrast/agent/thread.rb +1 -1
  138. data/lib/contrast/agent/thread_watcher.rb +2 -2
  139. data/lib/contrast/agent/tracepoint_hook.rb +2 -2
  140. data/lib/contrast/agent/version.rb +1 -1
  141. data/lib/contrast/api.rb +4 -4
  142. data/lib/contrast/api/communication.rb +9 -9
  143. data/lib/contrast/api/communication/messaging_queue.rb +3 -6
  144. data/lib/contrast/api/communication/response_processor.rb +1 -1
  145. data/lib/contrast/api/communication/socket_client.rb +41 -6
  146. data/lib/contrast/api/communication/speedracer.rb +1 -1
  147. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  148. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  149. data/lib/contrast/api/decorators.rb +17 -14
  150. data/lib/contrast/api/decorators/address.rb +20 -20
  151. data/lib/contrast/api/decorators/application_settings.rb +3 -2
  152. data/lib/contrast/api/decorators/application_update.rb +7 -8
  153. data/lib/contrast/api/decorators/http_request.rb +13 -12
  154. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  155. data/lib/contrast/api/decorators/library.rb +53 -0
  156. data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
  157. data/lib/contrast/api/decorators/message.rb +4 -2
  158. data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
  159. data/lib/contrast/api/decorators/route_coverage.rb +3 -2
  160. data/lib/contrast/api/decorators/server_features.rb +3 -2
  161. data/lib/contrast/api/decorators/trace_event.rb +28 -25
  162. data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
  163. data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
  164. data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
  165. data/lib/contrast/api/decorators/user_input.rb +4 -4
  166. data/lib/contrast/common_agent_configuration.rb +2 -2
  167. data/lib/contrast/components/agent.rb +8 -7
  168. data/lib/contrast/components/app_context.rb +50 -39
  169. data/lib/contrast/components/config.rb +32 -50
  170. data/lib/contrast/components/contrast_service.rb +10 -10
  171. data/lib/contrast/components/interface.rb +39 -17
  172. data/lib/contrast/components/inventory.rb +6 -1
  173. data/lib/contrast/components/logger.rb +1 -1
  174. data/lib/contrast/components/scope.rb +3 -3
  175. data/lib/contrast/components/settings.rb +20 -23
  176. data/lib/contrast/config.rb +18 -18
  177. data/lib/contrast/config/application_configuration.rb +5 -2
  178. data/lib/contrast/config/base_configuration.rb +2 -2
  179. data/lib/contrast/config/inventory_configuration.rb +2 -2
  180. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  181. data/lib/contrast/config/service_configuration.rb +8 -0
  182. data/lib/contrast/configuration.rb +93 -52
  183. data/lib/contrast/extension/assess.rb +21 -22
  184. data/lib/contrast/extension/assess/array.rb +18 -11
  185. data/lib/contrast/extension/assess/erb.rb +11 -3
  186. data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
  187. data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
  188. data/lib/contrast/extension/assess/fiber.rb +14 -14
  189. data/lib/contrast/extension/assess/hash.rb +7 -6
  190. data/lib/contrast/extension/assess/kernel.rb +34 -28
  191. data/lib/contrast/extension/assess/marshal.rb +67 -0
  192. data/lib/contrast/extension/assess/regexp.rb +10 -9
  193. data/lib/contrast/extension/assess/string.rb +23 -23
  194. data/lib/contrast/extension/inventory.rb +4 -4
  195. data/lib/contrast/extension/kernel.rb +1 -1
  196. data/lib/contrast/extension/module.rb +1 -1
  197. data/lib/contrast/extension/protect.rb +3 -3
  198. data/lib/contrast/extension/protect/kernel.rb +4 -4
  199. data/lib/contrast/extension/protect/psych.rb +2 -2
  200. data/lib/contrast/framework/base_support.rb +1 -1
  201. data/lib/contrast/framework/manager.rb +10 -11
  202. data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
  203. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  204. data/lib/contrast/framework/rack/support.rb +2 -2
  205. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  206. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
  207. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
  208. data/lib/contrast/framework/rails/patch/support.rb +4 -4
  209. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  210. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  211. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  212. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  213. data/lib/contrast/framework/rails/support.rb +67 -14
  214. data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
  215. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  216. data/lib/contrast/framework/sinatra/support.rb +6 -6
  217. data/lib/contrast/funchook/funchook.rb +1 -1
  218. data/lib/contrast/logger/application.rb +13 -5
  219. data/lib/contrast/logger/format.rb +22 -9
  220. data/lib/contrast/logger/log.rb +17 -10
  221. data/lib/contrast/logger/request.rb +30 -0
  222. data/lib/contrast/tasks/config.rb +1 -1
  223. data/lib/contrast/tasks/service.rb +2 -2
  224. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  225. data/lib/contrast/utils/assess/tracking_util.rb +49 -4
  226. data/lib/contrast/utils/class_util.rb +2 -2
  227. data/lib/contrast/utils/duck_utils.rb +0 -10
  228. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  229. data/lib/contrast/utils/hash_digest.rb +2 -1
  230. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  231. data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
  232. data/lib/contrast/utils/inventory_util.rb +3 -10
  233. data/lib/contrast/utils/io_util.rb +1 -1
  234. data/lib/contrast/utils/os.rb +1 -1
  235. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  236. data/lib/contrast/utils/sha256_builder.rb +2 -14
  237. data/lib/contrast/utils/stack_trace_utils.rb +2 -2
  238. data/lib/contrast/utils/string_utils.rb +11 -6
  239. data/resources/assess/policy.json +31 -22
  240. data/resources/deadzone/policy.json +5 -0
  241. data/ruby-agent.gemspec +21 -19
  242. data/service_executables/VERSION +1 -1
  243. data/service_executables/linux/contrast-service +0 -0
  244. data/service_executables/mac/contrast-service +0 -0
  245. metadata +73 -30
  246. data/lib/contrast/agent/assess/insulator.rb +0 -49
  247. data/lib/contrast/agent/require_state.rb +0 -61
  248. data/lib/contrast/extension/assess/assess_extension.rb +0 -147
  249. data/lib/contrast/utils/boolean_util.rb +0 -30
  250. data/lib/contrast/utils/freeze_util.rb +0 -32
  251. data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -1,10 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/boolean_util'
5
- cs__scoped_require 'contrast/utils/env_configuration_item'
6
- cs__scoped_require 'contrast/utils/object_share'
7
- cs__scoped_require 'contrast/configuration'
4
+ require 'contrast/utils/env_configuration_item'
5
+ require 'contrast/configuration'
8
6
 
9
7
  module Contrast
10
8
  module Components
@@ -34,47 +32,14 @@ module Contrast
34
32
  def build log: true
35
33
  @_valid = nil
36
34
  @config = Contrast::Configuration.new
37
- defaults
38
- overrides
35
+ env_overrides
39
36
  validate(log: log)
40
37
  end
41
38
  alias_method :rebuild, :build
42
39
 
43
- # Prefer abstraction, but use #raw if you need.
44
- # grep 'CONFIG.raw' for opportunities to refactor.
45
- def raw
46
- @config
47
- end
48
-
40
+ # @return [Contrast::Config::RootConfiguration]
49
41
  def root
50
- raw.root
51
- end
52
-
53
- def enabled?
54
- @_enabled = !Contrast::Utils::BooleanUtil.false?(raw.enable) if @_enabled.nil?
55
- @_enabled
56
- end
57
-
58
- def disabled?
59
- !enabled?
60
- end
61
-
62
- def protect?
63
- @_protect = Contrast::Utils::BooleanUtil.true?(raw.protect.enable) if @_protect.nil?
64
- @_protect
65
- end
66
-
67
- def assess?
68
- @_assess = Contrast::Utils::BooleanUtil.true?(raw.assess.enable) if @_assess.nil?
69
- @_assess
70
- end
71
-
72
- def session_id
73
- @_session_id ||= raw.application.session_id || Contrast::Utils::ObjectShare::EMPTY_STRING
74
- end
75
-
76
- def session_metadata
77
- @_session_metadata ||= raw.application.session_metadata || Contrast::Utils::ObjectShare::EMPTY_STRING
42
+ @config.root
78
43
  end
79
44
 
80
45
  def valid?
@@ -85,6 +50,10 @@ module Contrast
85
50
  !valid?
86
51
  end
87
52
 
53
+ def loggable
54
+ @config.loggable
55
+ end
56
+
88
57
  private
89
58
 
90
59
  SESSION_VARIABLES = "Invalid configuration. Setting both application.session_id and application.session_metadata is not allowed.\n"
@@ -105,15 +74,6 @@ module Contrast
105
74
  true
106
75
  end
107
76
 
108
- def defaults
109
- raw.agent.service.host ||= Contrast::Configuration::DEFAULT_HOST
110
- raw.agent.service.port ||= Contrast::Configuration::DEFAULT_PORT
111
- end
112
-
113
- def overrides
114
- env_overrides
115
- end
116
-
117
77
  def env_overrides
118
78
  # For env variables resembling CONTRAST__WHATEVER__NESTED_VALUE
119
79
  # override raw.whatever.nested_value
@@ -121,9 +81,31 @@ module Contrast
121
81
  next unless env_key.to_s.start_with?(CONTRAST_ENV_MARKER)
122
82
 
123
83
  config_item = Contrast::Utils::EnvConfigurationItem.new(env_key, env_value)
124
- raw.assign_value_to_path_array(config_item.dot_path_array, config_item.value)
84
+ @config.assign_value_to_path_array(config_item.dot_path_array, config_item.value)
125
85
  end
126
86
  end
87
+
88
+ # Typically, this would be accessed through
89
+ # Contrast::Components::AppContext, but we're too early in the
90
+ # initialization of the Agent to use that mechanism, so we look it up
91
+ # directly for ourselves
92
+ #
93
+ # @return [String,nil] the value of the session id set in the
94
+ # configuration, or nil if unset
95
+ def session_id
96
+ @config.application.session_id
97
+ end
98
+
99
+ # Typically, this would be accessed through
100
+ # Contrast::Components::AppContext, but we're too early in the
101
+ # initialization of the Agent to use that mechanism, so we look it up
102
+ # directly for ourselves
103
+ #
104
+ # @return [String,nil] the value of the session metadata set in the
105
+ # configuration, or nil if unset
106
+ def session_metadata
107
+ @config.application.session_metadata
108
+ end
127
109
  end
128
110
 
129
111
  COMPONENT_INTERFACE = Interface.new
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'monitor'
4
+ require 'monitor'
5
5
 
6
6
  module Contrast
7
7
  module Components
@@ -26,21 +26,21 @@ module Contrast
26
26
  # Validates the config to decide if it's suitable for starting
27
27
  # the bundled service
28
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
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
36
36
  end
37
37
 
38
38
  def host
39
- @_host ||= (CONFIG.root.agent.service.host || Contrast::Configuration::DEFAULT_HOST).to_s
39
+ @_host ||= (CONFIG.root.agent.service.host || Contrast::Config::ServiceConfiguration::DEFAULT_HOST).to_s
40
40
  end
41
41
 
42
42
  def port
43
- @_port ||= (CONFIG.root.agent.service.port || DEFAULT_PORT).to_i
43
+ @_port ||= (CONFIG.root.agent.service.port || Contrast::Config::ServiceConfiguration::DEFAULT_PORT).to_i
44
44
  end
45
45
 
46
46
  def socket_path
@@ -1,9 +1,9 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'delegate'
5
- cs__scoped_require 'contrast/extension/module'
6
- cs__scoped_require 'contrast/utils/boolean_util'
4
+ require 'delegate'
5
+ require 'contrast/extension/module'
6
+ require 'contrast/utils/object_share'
7
7
 
8
8
  module Contrast
9
9
  # This is the base module for our components classes. It is intended to
@@ -49,12 +49,34 @@ module Contrast
49
49
  end
50
50
 
51
51
  module Methods # :nodoc:
52
+ # use this to determine if the configuration value is literally boolean
53
+ # false or some form of the word `false`, regardless of case. It should
54
+ # be used for those values which default to `true` as they should only
55
+ # treat a value explicitly set to `false` as such.
56
+ #
57
+ # @param config_param [Boolean,String] the value to check
58
+ # @return [Boolean] should the value be treated as `false`
52
59
  def false? config_param
53
- Contrast::Utils::BooleanUtil.false?(config_param)
60
+ return false if config_param == true
61
+ return true if config_param == false
62
+ return false unless config_param.cs__is_a?(String)
63
+
64
+ Contrast::Utils::ObjectShare::FALSE.casecmp?(config_param)
54
65
  end
55
66
 
67
+ # use this to determine if the configuration value is literally boolean
68
+ # true or some form of the word `true`, regardless of case. It should
69
+ # be used for those values which default to `false` as they should only
70
+ # treat a value explicitly set to `true` as such.
71
+ #
72
+ # @param config_param [Boolean,String] the value to check
73
+ # @return [Boolean] should the value be treated as `true`
56
74
  def true? config_param
57
- Contrast::Utils::BooleanUtil.true?(config_param)
75
+ return false if config_param == false
76
+ return true if config_param == true
77
+ return false unless config_param.cs__is_a?(String)
78
+
79
+ Contrast::Utils::ObjectShare::TRUE.casecmp?(config_param)
58
80
  end
59
81
  end
60
82
  end
@@ -132,40 +154,40 @@ end
132
154
  # directed acyclic graph.
133
155
 
134
156
  # Scope shouldn't depend on anything.
135
- cs__scoped_require 'contrast/components/scope'
157
+ require 'contrast/components/scope'
136
158
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:scope] = [Contrast::Components::Scope]
137
159
 
138
160
  # Config depends on Scope.
139
- cs__scoped_require 'contrast/components/config'
161
+ require 'contrast/components/config'
140
162
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:config] = [Contrast::Components::Config]
141
163
 
142
164
  # Settings should not depend on anything but Config.
143
- cs__scoped_require 'contrast/components/settings'
165
+ require 'contrast/components/settings'
144
166
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings] = [Contrast::Components::Settings]
145
167
 
146
- cs__scoped_require 'contrast/components/assess'
147
- cs__scoped_require 'contrast/components/protect'
148
- cs__scoped_require 'contrast/components/inventory'
168
+ require 'contrast/components/assess'
169
+ require 'contrast/components/protect'
170
+ require 'contrast/components/inventory'
149
171
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [Contrast::Components::Protect,
150
172
  Contrast::Components::Assess,
151
173
  Contrast::Components::Inventory]
152
174
 
153
- cs__scoped_require 'contrast/components/logger'
175
+ require 'contrast/components/logger'
154
176
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
155
177
 
156
- cs__scoped_require 'contrast/components/agent'
178
+ require 'contrast/components/agent'
157
179
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:agent] = [Contrast::Components::Agent]
158
180
 
159
- cs__scoped_require 'contrast/components/contrast_service'
181
+ require 'contrast/components/contrast_service'
160
182
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:contrast_service] = [Contrast::Components::ContrastService]
161
183
 
162
- cs__scoped_require 'contrast/components/app_context'
184
+ require 'contrast/components/app_context'
163
185
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:app_context] = [Contrast::Components::AppContext]
164
186
 
165
- cs__scoped_require 'contrast/components/heap_dump'
187
+ require 'contrast/components/heap_dump'
166
188
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:heap_dump] = [Contrast::Components::HeapDump]
167
189
 
168
- cs__scoped_require 'contrast/components/sampling'
190
+ require 'contrast/components/sampling'
169
191
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:sampling] = [Contrast::Components::Sampling]
170
192
 
171
193
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP.cs__freeze
@@ -13,12 +13,17 @@ module Contrast
13
13
  include Contrast::Components::ComponentBase
14
14
  include Contrast::Components::Interface
15
15
 
16
- access_component :config
16
+ access_component :config, :settings
17
17
 
18
18
  def enabled?
19
19
  @_enabled = !false?(CONFIG.root.inventory.enable) if @_enabled.nil?
20
20
  @_enabled
21
21
  end
22
+
23
+ def analyze_libraries?
24
+ @_analyze_libraries = !false?(CONFIG.root.inventory.analyze_libraries) if @_analyze_libraries.nil?
25
+ @_analyze_libraries
26
+ end
22
27
  end
23
28
 
24
29
  COMPONENT_INTERFACE = Interface.new
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/logger/log'
4
+ require 'contrast/logger/log'
5
5
 
6
6
  module Contrast
7
7
  module Components
@@ -1,9 +1,9 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'fiber'
5
- cs__scoped_require 'monitor'
6
- cs__scoped_require 'contrast/agent/scope'
4
+ require 'fiber'
5
+ require 'monitor'
6
+ require 'contrast/agent/scope'
7
7
 
8
8
  # This is the Scope component.
9
9
  #
@@ -55,23 +55,22 @@ module Contrast
55
55
  APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules].cs__freeze
56
56
 
57
57
  # Meta-define an accessor for each state attribute.
58
- begin
59
- PROTECT_STATE_ATTRS.each do |attr|
60
- define_method(attr) do
61
- protect_state[attr]
62
- end
58
+
59
+ PROTECT_STATE_ATTRS.each do |attr|
60
+ define_method(attr) do
61
+ protect_state[attr]
63
62
  end
63
+ end
64
64
 
65
- ASSESS_STATE_ATTRS.each do |attr|
66
- define_method(attr) do
67
- assess_state[attr]
68
- end
65
+ ASSESS_STATE_ATTRS.each do |attr|
66
+ define_method(attr) do
67
+ assess_state[attr]
69
68
  end
69
+ end
70
70
 
71
- APPLICATION_STATE_ATTRS.each do |attr|
72
- define_method(attr) do
73
- application_state[attr]
74
- end
71
+ APPLICATION_STATE_ATTRS.each do |attr|
72
+ define_method(attr) do
73
+ application_state[attr]
75
74
  end
76
75
  end
77
76
 
@@ -95,18 +94,16 @@ module Contrast
95
94
 
96
95
  def update_from_server_features server_features
97
96
  # protect
98
- begin
99
- @_protect_enabled = nil
100
- protect_state[:enabled] = server_features.protect_enabled?
101
- end
97
+
98
+ @_protect_enabled = nil
99
+ protect_state[:enabled] = server_features.protect_enabled?
102
100
 
103
101
  # assess
104
- begin
105
- @_assess_enabled = nil
106
- assess_state[:enabled] = server_features.assess_enabled?
107
- assess_state[:sampling_settings] = server_features.assess.sampling
108
- Contrast::Utils::Assess::SamplingUtil.instance.update
109
- end
102
+
103
+ @_assess_enabled = nil
104
+ assess_state[:enabled] = server_features.assess_enabled?
105
+ assess_state[:sampling_settings] = server_features.assess.sampling
106
+ Contrast::Utils::Assess::SamplingUtil.instance.update
110
107
  end
111
108
 
112
109
  def update_from_application_settings application_settings
@@ -10,24 +10,24 @@ module Contrast
10
10
  end
11
11
  end
12
12
 
13
- cs__scoped_require 'contrast/config/base_configuration'
14
- cs__scoped_require 'contrast/config/default_value'
13
+ require 'contrast/config/base_configuration'
14
+ require 'contrast/config/default_value'
15
15
 
16
- cs__scoped_require 'contrast/config/logger_configuration'
16
+ require 'contrast/config/logger_configuration'
17
17
 
18
- cs__scoped_require 'contrast/config/heap_dump_configuration'
19
- cs__scoped_require 'contrast/config/service_configuration'
20
- cs__scoped_require 'contrast/config/exception_configuration'
21
- cs__scoped_require 'contrast/config/assess_rules_configuration'
22
- cs__scoped_require 'contrast/config/protect_rule_configuration'
23
- cs__scoped_require 'contrast/config/protect_rules_configuration'
24
- cs__scoped_require 'contrast/config/sampling_configuration'
18
+ require 'contrast/config/heap_dump_configuration'
19
+ require 'contrast/config/service_configuration'
20
+ require 'contrast/config/exception_configuration'
21
+ require 'contrast/config/assess_rules_configuration'
22
+ require 'contrast/config/protect_rule_configuration'
23
+ require 'contrast/config/protect_rules_configuration'
24
+ require 'contrast/config/sampling_configuration'
25
25
 
26
- cs__scoped_require 'contrast/config/ruby_configuration'
27
- cs__scoped_require 'contrast/config/agent_configuration'
28
- cs__scoped_require 'contrast/config/application_configuration'
29
- cs__scoped_require 'contrast/config/server_configuration'
30
- cs__scoped_require 'contrast/config/assess_configuration'
31
- cs__scoped_require 'contrast/config/inventory_configuration'
32
- cs__scoped_require 'contrast/config/protect_configuration'
33
- cs__scoped_require 'contrast/config/root_configuration'
26
+ require 'contrast/config/ruby_configuration'
27
+ require 'contrast/config/agent_configuration'
28
+ require 'contrast/config/application_configuration'
29
+ require 'contrast/config/server_configuration'
30
+ require 'contrast/config/assess_configuration'
31
+ require 'contrast/config/inventory_configuration'
32
+ require 'contrast/config/protect_configuration'
33
+ require 'contrast/config/root_configuration'
@@ -1,6 +1,9 @@
1
1
  # Copyright (c) 2020 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/config/default_value'
5
+ require 'contrast/utils/object_share'
6
+
4
7
  module Contrast
5
8
  module Config
6
9
  # Common Configuration settings. Those in this section pertain to the
@@ -15,8 +18,8 @@ module Contrast
15
18
  tags: EMPTY_VALUE,
16
19
  code: EMPTY_VALUE,
17
20
  metadata: EMPTY_VALUE,
18
- session_id: EMPTY_VALUE,
19
- session_metadata: EMPTY_VALUE
21
+ session_id: Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::EMPTY_STRING),
22
+ session_metadata: Contrast::Config::DefaultValue.new(Contrast::Utils::ObjectShare::EMPTY_STRING)
20
23
  }.cs__freeze
21
24
 
22
25
  def initialize hsh
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'forwardable'
5
- cs__scoped_require 'contrast/utils/object_share'
4
+ require 'forwardable'
5
+ require 'contrast/utils/object_share'
6
6
 
7
7
  module Contrast
8
8
  module Config
@@ -7,8 +7,8 @@ module Contrast
7
7
  # inventory functionality of the Agent.
8
8
  class InventoryConfiguration < BaseConfiguration
9
9
  KEYS = {
10
- enable: EMPTY_VALUE,
11
- record_used_classes: EMPTY_VALUE,
10
+ enable: Contrast::Config::DefaultValue.new(true),
11
+ analyze_libraries: Contrast::Config::DefaultValue.new(true),
12
12
  tags: EMPTY_VALUE
13
13
  }.cs__freeze
14
14