contrast-agent 3.15.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -0
  3. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +22 -10
  4. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +4 -3
  5. data/lib/contrast/agent.rb +4 -12
  6. data/lib/contrast/agent/assess/contrast_event.rb +121 -130
  7. data/lib/contrast/agent/assess/contrast_object.rb +51 -0
  8. data/lib/contrast/agent/assess/events/source_event.rb +5 -10
  9. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
  10. data/lib/contrast/agent/assess/policy/patcher.rb +4 -3
  11. data/lib/contrast/agent/assess/policy/policy_node.rb +46 -69
  12. data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -2
  13. data/lib/contrast/agent/assess/policy/preshift.rb +3 -3
  14. data/lib/contrast/agent/assess/policy/propagation_method.rb +13 -19
  15. data/lib/contrast/agent/assess/policy/propagation_node.rb +12 -24
  16. data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -2
  17. data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -2
  18. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  19. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
  20. data/lib/contrast/agent/assess/policy/propagator/insert.rb +2 -3
  21. data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -2
  22. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -5
  23. data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -2
  24. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -2
  25. data/lib/contrast/agent/assess/policy/propagator/remove.rb +2 -4
  26. data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -2
  27. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -2
  28. data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -7
  29. data/lib/contrast/agent/assess/policy/propagator/splat.rb +2 -9
  30. data/lib/contrast/agent/assess/policy/propagator/split.rb +77 -122
  31. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +32 -25
  32. data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -7
  33. data/lib/contrast/agent/assess/policy/source_method.rb +2 -14
  34. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +9 -13
  35. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
  36. data/lib/contrast/agent/assess/policy/trigger_method.rb +39 -14
  37. data/lib/contrast/agent/assess/policy/trigger_node.rb +31 -37
  38. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  39. data/lib/contrast/agent/assess/property/evented.rb +5 -18
  40. data/lib/contrast/agent/assess/property/tagged.rb +28 -16
  41. data/lib/contrast/agent/assess/property/updated.rb +0 -5
  42. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  43. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
  44. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
  45. data/lib/contrast/agent/assess/rule/redos.rb +1 -1
  46. data/lib/contrast/agent/assess/tag.rb +1 -1
  47. data/lib/contrast/agent/assess/tracker.rb +16 -18
  48. data/lib/contrast/agent/at_exit_hook.rb +5 -5
  49. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +7 -0
  50. data/lib/contrast/agent/inventory.rb +15 -0
  51. data/lib/contrast/agent/inventory/dependencies.rb +50 -0
  52. data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
  53. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
  54. data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
  55. data/lib/contrast/agent/middleware.rb +51 -3
  56. data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
  57. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
  58. data/lib/contrast/agent/patching/policy/method_policy.rb +1 -1
  59. data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
  60. data/lib/contrast/agent/patching/policy/patch.rb +6 -0
  61. data/lib/contrast/agent/patching/policy/policy.rb +16 -2
  62. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
  63. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +47 -1
  64. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
  65. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  66. data/lib/contrast/agent/protect/policy/rule_applicator.rb +53 -0
  67. data/lib/contrast/agent/protect/rule/base.rb +63 -14
  68. data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -28
  69. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -4
  70. data/lib/contrast/agent/protect/rule/deserialization.rb +4 -1
  71. data/lib/contrast/agent/protect/rule/no_sqli.rb +3 -3
  72. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  73. data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
  74. data/lib/contrast/agent/protect/rule/xxe.rb +32 -11
  75. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +10 -6
  76. data/lib/contrast/agent/reaction_processor.rb +1 -1
  77. data/lib/contrast/agent/request.rb +34 -34
  78. data/lib/contrast/agent/request_handler.rb +1 -1
  79. data/lib/contrast/agent/response.rb +5 -5
  80. data/lib/contrast/agent/rewriter.rb +3 -3
  81. data/lib/contrast/agent/scope.rb +81 -55
  82. data/lib/contrast/agent/static_analysis.rb +15 -9
  83. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  84. data/lib/contrast/agent/version.rb +1 -1
  85. data/lib/contrast/api/communication/socket_client.rb +36 -1
  86. data/lib/contrast/api/decorators.rb +3 -0
  87. data/lib/contrast/api/decorators/address.rb +13 -14
  88. data/lib/contrast/api/decorators/application_update.rb +1 -1
  89. data/lib/contrast/api/decorators/library.rb +54 -0
  90. data/lib/contrast/api/decorators/library_usage_update.rb +31 -0
  91. data/lib/contrast/api/decorators/message.rb +1 -0
  92. data/lib/contrast/api/decorators/trace_event.rb +31 -41
  93. data/lib/contrast/api/decorators/trace_event_object.rb +11 -3
  94. data/lib/contrast/api/decorators/trace_event_signature.rb +27 -5
  95. data/lib/contrast/api/decorators/user_input.rb +2 -1
  96. data/lib/contrast/common_agent_configuration.rb +2 -1
  97. data/lib/contrast/components/agent.rb +6 -5
  98. data/lib/contrast/components/app_context.rb +39 -30
  99. data/lib/contrast/components/assess.rb +36 -0
  100. data/lib/contrast/components/config.rb +29 -37
  101. data/lib/contrast/components/contrast_service.rb +9 -9
  102. data/lib/contrast/components/interface.rb +30 -6
  103. data/lib/contrast/components/inventory.rb +6 -1
  104. data/lib/contrast/components/scope.rb +72 -6
  105. data/lib/contrast/components/settings.rb +23 -23
  106. data/lib/contrast/config/assess_configuration.rb +2 -1
  107. data/lib/contrast/config/inventory_configuration.rb +2 -2
  108. data/lib/contrast/config/service_configuration.rb +4 -2
  109. data/lib/contrast/configuration.rb +1 -1
  110. data/lib/contrast/extension/assess/array.rb +9 -6
  111. data/lib/contrast/extension/assess/erb.rb +6 -3
  112. data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
  113. data/lib/contrast/extension/assess/exec_trigger.rb +0 -3
  114. data/lib/contrast/extension/assess/fiber.rb +5 -6
  115. data/lib/contrast/extension/assess/hash.rb +7 -5
  116. data/lib/contrast/extension/assess/kernel.rb +19 -22
  117. data/lib/contrast/extension/assess/marshal.rb +40 -28
  118. data/lib/contrast/extension/assess/regexp.rb +6 -11
  119. data/lib/contrast/extension/assess/string.rb +14 -13
  120. data/lib/contrast/extension/protect/kernel.rb +3 -3
  121. data/lib/contrast/framework/base_support.rb +51 -53
  122. data/lib/contrast/framework/manager.rb +6 -5
  123. data/lib/contrast/framework/rack/patch/session_cookie.rb +10 -10
  124. data/lib/contrast/framework/rack/support.rb +2 -1
  125. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -14
  126. data/lib/contrast/framework/rails/patch/assess_configuration.rb +1 -1
  127. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
  128. data/lib/contrast/framework/rails/patch/support.rb +1 -1
  129. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +12 -12
  130. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +13 -13
  131. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +3 -3
  132. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +13 -13
  133. data/lib/contrast/framework/rails/support.rb +5 -1
  134. data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
  135. data/lib/contrast/framework/sinatra/support.rb +7 -6
  136. data/lib/contrast/logger/application.rb +1 -4
  137. data/lib/contrast/logger/log.rb +7 -2
  138. data/lib/contrast/utils/duck_utils.rb +1 -1
  139. data/lib/contrast/utils/heap_dump_util.rb +1 -1
  140. data/lib/contrast/utils/invalid_configuration_util.rb +2 -5
  141. data/lib/contrast/utils/inventory_util.rb +0 -7
  142. data/lib/contrast/utils/object_share.rb +3 -3
  143. data/lib/contrast/utils/preflight_util.rb +1 -1
  144. data/lib/contrast/utils/prevent_serialization.rb +1 -1
  145. data/lib/contrast/utils/resource_loader.rb +1 -1
  146. data/lib/contrast/utils/sha256_builder.rb +2 -14
  147. data/lib/contrast/utils/string_utils.rb +1 -1
  148. data/lib/contrast/utils/tag_util.rb +9 -13
  149. data/resources/assess/policy.json +31 -12
  150. data/resources/deadzone/policy.json +156 -0
  151. data/resources/protect/policy.json +12 -0
  152. data/ruby-agent.gemspec +11 -6
  153. data/service_executables/VERSION +1 -1
  154. data/service_executables/linux/contrast-service +0 -0
  155. data/service_executables/mac/contrast-service +0 -0
  156. metadata +91 -28
  157. data/lib/contrast/utils/boolean_util.rb +0 -30
  158. data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -12,7 +12,8 @@ module Contrast
12
12
  module UserInput
13
13
  UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
14
14
  user_input.input_type = :UNKNOWN
15
- end.cs__freeze
15
+ end
16
+ UNKNOWN_USER_INPUT.cs__freeze
16
17
 
17
18
  def self.included klass
18
19
  klass.extend(ClassMethods)
@@ -65,7 +65,8 @@ module Contrast
65
65
  end
66
66
 
67
67
  %w[name default description required_languages display].each do |field|
68
- define_method(field) { hsh[field].dup }
68
+ # TODO: RUBY-1052
69
+ define_method(field) { hsh[field].dup } # rubocop:disable Performance/Kernel/DefineMethod
69
70
  end
70
71
  end
71
72
 
@@ -17,7 +17,8 @@ module Contrast
17
17
  access_component :analysis, :config, :settings
18
18
 
19
19
  def enabled?
20
- !!@enabled
20
+ @_enabled = !false?(CONFIG.root.enable) if @_enabled.nil?
21
+ @_enabled
21
22
  end
22
23
 
23
24
  def disabled?
@@ -25,11 +26,11 @@ module Contrast
25
26
  end
26
27
 
27
28
  def enable!
28
- @enabled = true
29
+ @_enabled = true
29
30
  end
30
31
 
31
32
  def disable!
32
- @enabled = false
33
+ @_enabled = false
33
34
  end
34
35
 
35
36
  def ruleset
@@ -49,12 +50,12 @@ module Contrast
49
50
  end
50
51
 
51
52
  def patch_yield?
52
- @_patch_yield = !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.propagate_yield) if @_patch_yield.nil?
53
+ @_patch_yield = !false?(CONFIG.root.agent.ruby.propagate_yield) if @_patch_yield.nil?
53
54
  @_patch_yield
54
55
  end
55
56
 
56
57
  def interpolation_enabled?
57
- @_interpolation_enabled = !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.interpolate) if @_interpolation_enabled.nil?
58
+ @_interpolation_enabled = !false?(CONFIG.root.agent.ruby.interpolate) if @_interpolation_enabled.nil?
58
59
  @_interpolation_enabled
59
60
  end
60
61
 
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rubygems/version'
5
+ require 'contrast/utils/object_share'
5
6
 
6
7
  module Contrast
7
8
  module Components
@@ -15,7 +16,7 @@ module Contrast
15
16
  include Contrast::Components::ComponentBase
16
17
  include Contrast::Components::Interface
17
18
 
18
- access_component :agent, :analysis, :config
19
+ access_component :agent, :analysis, :config, :logging
19
20
 
20
21
  DEFAULT_APP_NAME = 'rails'
21
22
  DEFAULT_APP_PATH = '/'
@@ -28,51 +29,51 @@ module Contrast
28
29
 
29
30
  def server_type
30
31
  @_server_type ||= begin
31
- tmp = CONFIG.root.server.type
32
- tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
33
- tmp
34
- end
32
+ tmp = CONFIG.root.server.type
33
+ tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
34
+ tmp
35
+ end
35
36
  end
36
37
 
37
38
  def name
38
39
  @_name ||= begin
39
- tmp = CONFIG.root.application.name
40
- tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
41
- tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
42
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
43
- rescue StandardError
44
- DEFAULT_APP_NAME
45
- end
40
+ tmp = CONFIG.root.application.name
41
+ tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
42
+ tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
43
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
44
+ rescue StandardError
45
+ DEFAULT_APP_NAME
46
+ end
46
47
  end
47
48
 
48
49
  def path
49
50
  @_path ||= begin
50
- tmp = CONFIG.root.application.path
51
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
52
- rescue StandardError
53
- DEFAULT_APP_PATH
54
- end
51
+ tmp = CONFIG.root.application.path
52
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
53
+ rescue StandardError
54
+ DEFAULT_APP_PATH
55
+ end
55
56
  end
56
57
 
57
58
  def server_name
58
59
  @_server_name ||= begin
59
- tmp = CONFIG.root.server.name
60
- tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
61
- tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
62
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
63
- rescue StandardError
64
- DEFAULT_SERVER_NAME
65
- end
60
+ tmp = CONFIG.root.server.name
61
+ tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
62
+ tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
63
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
64
+ rescue StandardError
65
+ DEFAULT_SERVER_NAME
66
+ end
66
67
  end
67
68
 
68
69
  def server_path
69
70
  @_server_path ||= begin
70
- tmp = CONFIG.root.server.path
71
- tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
72
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
73
- rescue StandardError
74
- DEFAULT_SERVER_PATH
75
- end
71
+ tmp = CONFIG.root.server.path
72
+ tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
73
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
74
+ rescue StandardError
75
+ DEFAULT_SERVER_PATH
76
+ end
76
77
  end
77
78
 
78
79
  def build_app_startup_message
@@ -101,6 +102,14 @@ module Contrast
101
102
  msg.application_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
102
103
  msg.library_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory.tags
103
104
  msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ASSESS.tags
105
+ logger.info('Application context',
106
+ server_name: msg.server_name,
107
+ server_path: msg.server_path,
108
+ server_type: msg.server_type,
109
+ application_name: name,
110
+ application_path: path,
111
+ application_language: Contrast::Utils::ObjectShare::RUBY)
112
+
104
113
  msg
105
114
  end
106
115
 
@@ -35,6 +35,42 @@ module Contrast
35
35
  disabled_rules.include?(name)
36
36
  end
37
37
 
38
+ # The value of the stacktrace should be treated as an ENUM. We upcase it for
39
+ # faster comparisons when we use it. Anything not one of the known values of
40
+ # 'NONE', 'SOME', or 'ALL' is treated as 'ALL'
41
+ #
42
+ # @return [Symbol] the normalized value of CONFIG.root.assess.stacktraces
43
+ def capture_stacktrace_value
44
+ @_capture_stacktrace_value ||= case CONFIG.root.assess.stacktraces.upcase
45
+ when 'NONE'
46
+ :NONE
47
+ when 'SOME'
48
+ :SOME
49
+ else
50
+ :ALL
51
+ end
52
+ end
53
+
54
+ # Consider capture_stacktrace_value along with the node type
55
+ # to dertmine whether stacktraces should be captured.
56
+ #
57
+ # capture_stacktrace_value -> (:ALL, :NONE, :SOME)
58
+ # node types (SourceNode, PolicyNode, TriggerNode, PropagationNode)
59
+ #
60
+ # @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode] The node in question.
61
+ # @param return [Boolean] to capture or not to capture, that is the question.
62
+ def capture_stacktrace? policy_node
63
+ return true if capture_stacktrace_value == :ALL
64
+
65
+ return false if capture_stacktrace_value == :NONE
66
+
67
+ # Below here capture_stacktrace_value must be :SOME.
68
+ return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::SourceNode)
69
+ return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::TriggerNode)
70
+
71
+ false
72
+ end
73
+
38
74
  def scan_response?
39
75
  @_scan_response = !false?(CONFIG.root.assess.enable_scan_response) if @_scan_response.nil?
40
76
  @_scan_response
@@ -1,9 +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
- require 'contrast/utils/boolean_util'
5
4
  require 'contrast/utils/env_configuration_item'
6
- require 'contrast/utils/object_share'
7
5
  require 'contrast/configuration'
8
6
 
9
7
  module Contrast
@@ -39,41 +37,9 @@ module Contrast
39
37
  end
40
38
  alias_method :rebuild, :build
41
39
 
42
- # Prefer abstraction, but use #raw if you need.
43
- # grep 'CONFIG.raw' for opportunities to refactor.
44
- def raw
45
- @config
46
- end
47
-
40
+ # @return [Contrast::Config::RootConfiguration]
48
41
  def root
49
- raw.root
50
- end
51
-
52
- def enabled?
53
- @_enabled = !Contrast::Utils::BooleanUtil.false?(raw.enable) if @_enabled.nil?
54
- @_enabled
55
- end
56
-
57
- def disabled?
58
- !enabled?
59
- end
60
-
61
- def protect?
62
- @_protect = Contrast::Utils::BooleanUtil.true?(raw.protect.enable) if @_protect.nil?
63
- @_protect
64
- end
65
-
66
- def assess?
67
- @_assess = Contrast::Utils::BooleanUtil.true?(raw.assess.enable) if @_assess.nil?
68
- @_assess
69
- end
70
-
71
- def session_id
72
- @_session_id ||= raw.application.session_id
73
- end
74
-
75
- def session_metadata
76
- @_session_metadata ||= raw.application.session_metadata
42
+ @config.root
77
43
  end
78
44
 
79
45
  def valid?
@@ -84,6 +50,10 @@ module Contrast
84
50
  !valid?
85
51
  end
86
52
 
53
+ def loggable
54
+ @config.loggable
55
+ end
56
+
87
57
  private
88
58
 
89
59
  SESSION_VARIABLES = "Invalid configuration. Setting both application.session_id and application.session_metadata is not allowed.\n"
@@ -111,9 +81,31 @@ module Contrast
111
81
  next unless env_key.to_s.start_with?(CONTRAST_ENV_MARKER)
112
82
 
113
83
  config_item = Contrast::Utils::EnvConfigurationItem.new(env_key, env_value)
114
- 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)
115
85
  end
116
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
117
109
  end
118
110
 
119
111
  COMPONENT_INTERFACE = Interface.new
@@ -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.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.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
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'delegate'
5
5
  require 'contrast/extension/module'
6
- require 'contrast/utils/boolean_util'
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
@@ -146,9 +168,11 @@ Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings]
146
168
  require 'contrast/components/assess'
147
169
  require 'contrast/components/protect'
148
170
  require 'contrast/components/inventory'
149
- Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [Contrast::Components::Protect,
150
- Contrast::Components::Assess,
151
- Contrast::Components::Inventory]
171
+ Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [
172
+ Contrast::Components::Protect,
173
+ Contrast::Components::Assess,
174
+ Contrast::Components::Inventory
175
+ ]
152
176
 
153
177
  require 'contrast/components/logger'
154
178
  Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
@@ -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
@@ -42,18 +42,84 @@ module Contrast
42
42
  # For each instance method on a scope, define a forwarder
43
43
  # to the scope on the current execution context's scope.
44
44
 
45
- Contrast::Agent::Scope.public_instance_methods(false).each do |method_sym|
46
- define_method(method_sym) do |*args, &block|
47
- scope_for_current_ec.send(method_sym, *args, &block)
48
- end
49
- end
50
-
51
45
  def scope_for_current_ec
52
46
  MONITOR.synchronize do
53
47
  return EXECUTION_CONTEXT[Fiber.current] ||= Contrast::Agent::Scope.new
54
48
  end
55
49
  end
56
50
 
51
+ def enter_contrast_scope!
52
+ scope_for_current_ec.enter_contrast_scope!
53
+ end
54
+
55
+ def enter_deserialization_scope!
56
+ scope_for_current_ec.enter_deserialization_scope!
57
+ end
58
+
59
+ def enter_split_scope!
60
+ scope_for_current_ec.enter_split_scope!
61
+ end
62
+
63
+ def enter_scope! name
64
+ scope_for_current_ec.enter_scope! name
65
+ end
66
+
67
+ def exit_contrast_scope!
68
+ scope_for_current_ec.exit_contrast_scope!
69
+ end
70
+
71
+ def exit_deserialization_scope!
72
+ scope_for_current_ec.exit_deserialization_scope!
73
+ end
74
+
75
+ def exit_split_scope!
76
+ scope_for_current_ec.exit_split_scope!
77
+ end
78
+
79
+ def exit_scope! name
80
+ scope_for_current_ec.exit_scope! name
81
+ end
82
+
83
+ def in_contrast_scope?
84
+ scope_for_current_ec.in_contrast_scope?
85
+ end
86
+
87
+ def in_deserialization_scope?
88
+ scope_for_current_ec.in_deserialization_scope?
89
+ end
90
+
91
+ def in_split_scope?
92
+ scope_for_current_ec.in_split_scope?
93
+ end
94
+
95
+ def split_scope_depth
96
+ scope_for_current_ec.split_scope_depth
97
+ end
98
+
99
+ def in_scope? name
100
+ scope_for_current_ec.in_scope? name
101
+ end
102
+
103
+ def with_contrast_scope
104
+ scope_for_current_ec.enter_contrast_scope!
105
+ yield
106
+ ensure
107
+ scope_for_current_ec.exit_contrast_scope!
108
+ end
109
+
110
+ def with_deserialization_scope
111
+ scope_for_current_ec.enter_deserialization_scope!
112
+ ensure
113
+ scope_for_current_ec.exit_deserialization_scope!
114
+ end
115
+
116
+ def with_split_scope
117
+ scope_for_current_ec.enter_split_scope!
118
+ yield
119
+ ensure
120
+ scope_for_current_ec.exit_split_scope!
121
+ end
122
+
57
123
  # TODO: RUBY-572
58
124
  #
59
125
  # Current behavior is to no-op if we're not "in a request context".