contrast-agent 3.16.0 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) 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 +2 -3
  6. data/lib/contrast/agent/assess/contrast_event.rb +49 -130
  7. data/lib/contrast/agent/assess/contrast_object.rb +51 -0
  8. data/lib/contrast/agent/assess/events/source_event.rb +4 -9
  9. data/lib/contrast/agent/assess/policy/patcher.rb +4 -3
  10. data/lib/contrast/agent/assess/policy/policy_node.rb +31 -59
  11. data/lib/contrast/agent/assess/policy/policy_scanner.rb +17 -6
  12. data/lib/contrast/agent/assess/policy/preshift.rb +3 -3
  13. data/lib/contrast/agent/assess/policy/propagation_method.rb +13 -19
  14. data/lib/contrast/agent/assess/policy/propagation_node.rb +12 -24
  15. data/lib/contrast/agent/assess/policy/propagator/append.rb +1 -2
  16. data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -2
  17. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  18. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
  19. data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -2
  20. data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -2
  21. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
  22. data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -2
  23. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -2
  24. data/lib/contrast/agent/assess/policy/propagator/remove.rb +2 -4
  25. data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -2
  26. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -2
  27. data/lib/contrast/agent/assess/policy/propagator/select.rb +3 -4
  28. data/lib/contrast/agent/assess/policy/propagator/splat.rb +2 -4
  29. data/lib/contrast/agent/assess/policy/propagator/split.rb +73 -117
  30. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +11 -11
  31. data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -7
  32. data/lib/contrast/agent/assess/policy/source_method.rb +2 -14
  33. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +5 -8
  34. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
  35. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  36. data/lib/contrast/agent/assess/property/tagged.rb +21 -15
  37. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +3 -2
  38. data/lib/contrast/agent/assess/rule/redos.rb +1 -1
  39. data/lib/contrast/agent/assess/tracker.rb +16 -18
  40. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +7 -0
  41. data/lib/contrast/agent/inventory.rb +15 -0
  42. data/lib/contrast/agent/inventory/dependencies.rb +50 -0
  43. data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
  44. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
  45. data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
  46. data/lib/contrast/agent/middleware.rb +51 -3
  47. data/lib/contrast/agent/patching/policy/method_policy.rb +1 -1
  48. data/lib/contrast/agent/patching/policy/patch.rb +6 -0
  49. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +47 -1
  50. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
  51. data/lib/contrast/agent/protect/policy/rule_applicator.rb +53 -0
  52. data/lib/contrast/agent/protect/rule/base.rb +63 -14
  53. data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -28
  54. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -4
  55. data/lib/contrast/agent/protect/rule/deserialization.rb +4 -1
  56. data/lib/contrast/agent/protect/rule/no_sqli.rb +3 -3
  57. data/lib/contrast/agent/protect/rule/sqli.rb +3 -3
  58. data/lib/contrast/agent/protect/rule/xxe.rb +32 -11
  59. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +10 -6
  60. data/lib/contrast/agent/reaction_processor.rb +1 -1
  61. data/lib/contrast/agent/request_handler.rb +1 -1
  62. data/lib/contrast/agent/response.rb +5 -5
  63. data/lib/contrast/agent/rewriter.rb +3 -3
  64. data/lib/contrast/agent/scope.rb +81 -55
  65. data/lib/contrast/agent/static_analysis.rb +14 -8
  66. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  67. data/lib/contrast/agent/version.rb +1 -1
  68. data/lib/contrast/api/decorators.rb +3 -0
  69. data/lib/contrast/api/decorators/address.rb +0 -1
  70. data/lib/contrast/api/decorators/application_update.rb +1 -1
  71. data/lib/contrast/api/decorators/library.rb +54 -0
  72. data/lib/contrast/api/decorators/library_usage_update.rb +31 -0
  73. data/lib/contrast/api/decorators/trace_event.rb +19 -31
  74. data/lib/contrast/api/decorators/trace_event_object.rb +11 -3
  75. data/lib/contrast/api/decorators/trace_event_signature.rb +27 -5
  76. data/lib/contrast/api/decorators/user_input.rb +2 -1
  77. data/lib/contrast/common_agent_configuration.rb +2 -1
  78. data/lib/contrast/components/agent.rb +6 -5
  79. data/lib/contrast/components/assess.rb +36 -0
  80. data/lib/contrast/components/config.rb +29 -37
  81. data/lib/contrast/components/interface.rb +30 -6
  82. data/lib/contrast/components/inventory.rb +6 -1
  83. data/lib/contrast/components/scope.rb +72 -6
  84. data/lib/contrast/components/settings.rb +6 -3
  85. data/lib/contrast/config/assess_configuration.rb +2 -1
  86. data/lib/contrast/config/inventory_configuration.rb +2 -2
  87. data/lib/contrast/extension/assess/array.rb +2 -3
  88. data/lib/contrast/extension/assess/erb.rb +1 -3
  89. data/lib/contrast/extension/assess/exec_trigger.rb +1 -4
  90. data/lib/contrast/extension/assess/fiber.rb +2 -3
  91. data/lib/contrast/extension/assess/hash.rb +4 -2
  92. data/lib/contrast/extension/assess/kernel.rb +1 -2
  93. data/lib/contrast/extension/assess/marshal.rb +34 -26
  94. data/lib/contrast/extension/assess/regexp.rb +3 -8
  95. data/lib/contrast/extension/assess/string.rb +1 -2
  96. data/lib/contrast/framework/base_support.rb +51 -53
  97. data/lib/contrast/framework/manager.rb +3 -2
  98. data/lib/contrast/framework/rack/patch/session_cookie.rb +2 -2
  99. data/lib/contrast/framework/rack/support.rb +2 -1
  100. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -1
  101. data/lib/contrast/framework/rails/patch/assess_configuration.rb +1 -1
  102. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  103. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +1 -1
  104. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +1 -1
  105. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +1 -1
  106. data/lib/contrast/framework/rails/support.rb +5 -1
  107. data/lib/contrast/framework/sinatra/support.rb +3 -2
  108. data/lib/contrast/logger/application.rb +1 -4
  109. data/lib/contrast/utils/duck_utils.rb +1 -1
  110. data/lib/contrast/utils/heap_dump_util.rb +1 -1
  111. data/lib/contrast/utils/inventory_util.rb +0 -7
  112. data/lib/contrast/utils/object_share.rb +3 -3
  113. data/lib/contrast/utils/preflight_util.rb +1 -1
  114. data/lib/contrast/utils/prevent_serialization.rb +1 -1
  115. data/lib/contrast/utils/resource_loader.rb +1 -1
  116. data/lib/contrast/utils/sha256_builder.rb +2 -14
  117. data/lib/contrast/utils/string_utils.rb +1 -1
  118. data/lib/contrast/utils/tag_util.rb +9 -13
  119. data/resources/assess/policy.json +9 -9
  120. data/resources/deadzone/policy.json +150 -0
  121. data/resources/protect/policy.json +12 -0
  122. data/ruby-agent.gemspec +10 -6
  123. data/service_executables/VERSION +1 -1
  124. data/service_executables/linux/contrast-service +0 -0
  125. data/service_executables/mac/contrast-service +0 -0
  126. metadata +76 -27
  127. data/lib/contrast/utils/boolean_util.rb +0 -30
  128. data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -21,7 +21,6 @@ module Contrast
21
21
  module ClassMethods
22
22
  include Contrast::Components::Interface
23
23
  access_component :logging
24
-
25
24
  # receiver is memoized because it is the address/host/port of the server, once we
26
25
  # resolve this for the first time, it shouldn't change
27
26
  #
@@ -44,7 +44,7 @@ module Contrast
44
44
  msg = new
45
45
  msg.append_route_coverage_data(Contrast::Agent.framework_manager.find_route_discovery_data)
46
46
  msg.append_platform_version(Contrast::Agent.framework_manager.platform_version)
47
- msg.append_library_update(Contrast::Utils::GemfileReader.instance.library_pb_list)
47
+ msg.append_library_update(Contrast::Agent::Inventory::DependencyAnalysis.instance.library_pb_list)
48
48
  msg
49
49
  end
50
50
  end
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/utils/string_utils'
5
+ require 'contrast/utils/sha256_builder'
6
+ require 'yaml'
7
+
8
+ module Contrast
9
+ module Api
10
+ module Decorators
11
+ # Used to decorate the Library protobuf model to handle Gem::Specification translation
12
+ module Library
13
+ def self.included klass
14
+ klass.extend(ClassMethods)
15
+ end
16
+
17
+ # Used to add class methods to the Library class on inclusion of the decorator
18
+ module ClassMethods
19
+ def build digest, gem_specification
20
+ 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))
25
+ msg.external_ms = date_to_ms(gem_specification.date)
26
+ msg.internal_ms = msg.external_ms
27
+ msg.url = Contrast::Utils::StringUtils.force_utf8(gem_specification.homepage)
28
+ msg.class_count = file_count(gem_specification.full_gem_path.to_s)
29
+ msg.used_class_count = 0
30
+ msg
31
+ end
32
+
33
+ # These are all the code files that are located in the Gem directory loaded
34
+ # by the current environment; this includes more than Ruby files
35
+ def file_count path
36
+ Contrast::Utils::Sha256Builder.instance.files(path).length
37
+ end
38
+
39
+ def build_manifest spec
40
+ Contrast::Utils::StringUtils.force_utf8(spec.to_yaml.to_s)
41
+ rescue StandardError
42
+ nil
43
+ end
44
+
45
+ def date_to_ms date
46
+ (date.to_f * 1000.0).to_i
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ Contrast::Api::Dtm::Library.include(Contrast::Api::Decorators::Library)
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/utils/string_utils'
5
+
6
+ module Contrast
7
+ module Api
8
+ module Decorators
9
+ # Used to decorate the LibraryUsageUpdate protobuf
10
+ module LibraryUsageUpdate
11
+ def self.included klass
12
+ klass.extend(ClassMethods)
13
+ end
14
+
15
+ # Used to add class methods to the LibraryUsageUpdate class on inclusion of the decorator
16
+ module ClassMethods
17
+ def build digest, files
18
+ msg = new
19
+ msg.hash_code = Contrast::Utils::StringUtils.force_utf8(digest)
20
+ files.each do |required_file|
21
+ msg.class_names[required_file] = true
22
+ end
23
+ msg
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ Contrast::Api::Dtm::LibraryUsageUpdate.include(Contrast::Api::Decorators::LibraryUsageUpdate)
@@ -15,44 +15,30 @@ module Contrast
15
15
 
16
16
  # Wrapper around build_event_object for the args array. Handles
17
17
  # tainting the correct argument.
18
- def build_event_args contrast_event, taint_target
18
+ def build_event_args! contrast_event, taint_target
19
19
  contrast_event.args.each_index do |idx|
20
20
  truncate_arg = taint_target != idx
21
21
  event_arg = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.args[idx], truncate_arg)
22
22
  args << event_arg
23
23
  end
24
+ self
24
25
  end
25
26
 
26
- # TeamServer only supports one object's taint ranges at a time.
27
- # We'll find the taint ranges for the target and return those
28
- def build_taint_ranges contrast_event, taint_target
27
+ # TeamServer only supports one object's taint ranges at a time. We keep
28
+ # those tags on the event directly, so we just need to convert them to
29
+ # their DTM form in order to report this.
30
+ #
31
+ # @param contrast_event [Contrast::Agent::AssessContrastEvent]
32
+ def build_taint_ranges! contrast_event
29
33
  # If there's no taint_target, this isn't a dataflow trace, but a
30
34
  # trigger one
31
- return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless taint_target
35
+ return self unless contrast_event&.tags
32
36
 
33
- properties = case taint_target
34
- when Contrast::Utils::ObjectShare::OBJECT_KEY
35
- Contrast::Agent::Assess::Tracker.properties(contrast_event.object)
36
- when Contrast::Utils::ObjectShare::RETURN_KEY
37
- Contrast::Agent::Assess::Tracker.properties(contrast_event.ret)
38
- else
39
- target = contrast_event.args[taint_target]
40
- if target.is_a?(Hash)
41
- if contrast_event.policy_node&.targets&.any?
42
- Contrast::Agent::Assess::Tracker.properties(target[contrast_event.policy_node.targets[0]])
43
- else
44
- Contrast::Agent::Assess::Tracker.properties(target[contrast_event.policy_node.sources[0]])
45
- end
46
- else
47
- Contrast::Agent::Assess::Tracker.properties(target)
48
- end
49
- end
50
- return unless properties.tracked?
51
-
52
- self.taint_ranges += properties.tags_to_dtm
37
+ self.taint_ranges += Contrast::Api::Dtm::TraceTaintRange.build_for_event(contrast_event.tags)
38
+ self
53
39
  end
54
40
 
55
- def build_parent_ids contrast_event
41
+ def build_parent_ids! contrast_event
56
42
  contrast_event&.parent_events&.each do |event|
57
43
  next unless event
58
44
 
@@ -60,12 +46,14 @@ module Contrast
60
46
  parent.id = event.event_id.to_i
61
47
  parent_object_ids << parent
62
48
  end
49
+ self
63
50
  end
64
51
 
65
- def build_stack contrast_event
52
+ def build_stack! contrast_event
66
53
  # We delayed doing this as long as possible b/c it's expensive
67
54
  stack_dtms = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
68
55
  self.stack += stack_dtms
56
+ self
69
57
  end
70
58
 
71
59
  # Class methods for TraceEvent
@@ -85,10 +73,10 @@ module Contrast
85
73
  event_dtm.object = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.object, truncate_obj)
86
74
  truncate_ret = Contrast::Utils::ObjectShare::RETURN_KEY != taint_target
87
75
  event_dtm.ret = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.ret, truncate_ret)
88
- event_dtm.build_event_args(contrast_event, taint_target)
89
- event_dtm.build_parent_ids(contrast_event)
90
- event_dtm.build_taint_ranges(contrast_event, taint_target)
91
- event_dtm.build_stack(contrast_event)
76
+ event_dtm.build_event_args!(contrast_event, taint_target)
77
+ event_dtm.build_parent_ids!(contrast_event)
78
+ event_dtm.build_taint_ranges!(contrast_event)
79
+ event_dtm.build_stack!(contrast_event)
92
80
  event_dtm.object_id = contrast_event.event_id.to_i
93
81
  event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret, contrast_event.policy_node, contrast_event.args)
94
82
  event_dtm
@@ -29,13 +29,21 @@ module Contrast
29
29
  ELLIPSIS = '...'
30
30
  UNTRUNCATED_PORTION_LENGTH = 25
31
31
  TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + ELLIPSIS.length
32
- def build object, truncate
32
+
33
+ # Convert the given Object into a Contrast::Api::Dtm::TraceEventObject
34
+ #
35
+ # @param contrast_object [Contrast::Agent::Assess::ContrastObject, nil]
36
+ # the thing to convert, if any
37
+ # @param truncate [Boolean] if the converted object can/should be
38
+ # truncated.
39
+ # @return [Contrast::Api::Dtm::TraceEventObject]
40
+ def build contrast_object, truncate
33
41
  event_object = new
34
42
  with_contrast_scope do
35
- obj_string = Contrast::Utils::StringUtils.force_utf8(object)
43
+ obj_string = Contrast::Utils::StringUtils.force_utf8(contrast_object&.object)
36
44
  obj_string = truncate(obj_string) if truncate && obj_string.length > TRUNCATION_LENGTH
37
45
  event_object.value = Base64.encode64(obj_string)
38
- event_object.tracked = Contrast::Utils::Assess::TrackingUtil.tracked?(object)
46
+ event_object.tracked = contrast_object&.tracked?
39
47
  end
40
48
  event_object
41
49
  end
@@ -17,27 +17,49 @@ module Contrast
17
17
 
18
18
  # Class methods for TraceEventSignature
19
19
  module ClassMethods
20
+ # Convert the given composites into components that TeamServer can
21
+ # understand in order to build a representation of the method
22
+ # invoked.
23
+ #
24
+ # @param ret_obj [Contrast::Agent::Assess::ContrastObject, nil] the
25
+ # return value of the method call.
26
+ # @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode]
27
+ # the policy which pertains to the method invoked.
28
+ # @param args [Array<Contrast::Agent::Assess::ContrastObject>, nil]
29
+ # @return [Contrast::Api::Dtm::TraceEventSignature]
20
30
  def build ret_obj, policy_node, args
21
31
  signature = new
22
- return_type = ret_obj ? ret_obj.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
23
- signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
32
+ signature.return_type = Contrast::Utils::StringUtils.force_utf8(type_name(ret_obj))
24
33
  signature.class_name = Contrast::Utils::StringUtils.force_utf8(policy_node.class_name)
25
34
  signature.method_name = Contrast::Utils::StringUtils.force_utf8(policy_node.method_name)
26
35
  if args
27
36
  args&.each do |arg|
28
- arg_type = arg ? arg.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
29
- signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
37
+ signature.arg_types << Contrast::Utils::StringUtils.force_utf8(type_name(arg))
30
38
  end
31
39
  end
32
40
  signature.constructor = policy_node.method_name == :new
33
41
  # if there's a ret, then this method isn't nil. not 100% full proof since you can
34
42
  # return nil, but this is the best we've got currently.
35
- signature.void_method = ret_obj.nil?
43
+ signature.void_method = ret_obj.nil? || ret_obj.object.nil?
36
44
  # 8 is STATIC in Java... we have to placate them for now
37
45
  # it has been requested that flags be removed since it isn't used
38
46
  signature.flags = 8 unless policy_node.instance_method?
39
47
  signature
40
48
  end
49
+
50
+ private
51
+
52
+ # While Ruby signatures do not require neither a return type and can
53
+ # return anything depending on inputs, code paths, etc, nor constant
54
+ # parameter types, TeamServer was designed with strongly typed
55
+ # languages (Java) in mind, so we need types in our signatures.
56
+ #
57
+ # @param contrast_object [Contrast::Agent::Assess::ContrastObject, nil]
58
+ # the object to find the type of
59
+ # @return [String] the name of the module of the ret_obj, or `nil`
60
+ def type_name contrast_object
61
+ contrast_object ? contrast_object.object_type : Contrast::Utils::ObjectShare::NIL_STRING
62
+ end
41
63
  end
42
64
  end
43
65
  end
@@ -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
 
@@ -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