# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Components module Assess # A wrapper build around the Common Agent Configuration project to allow # for access of the values contained in its # parent_configuration_spec.yaml. # Specifically, this allows for querying the state of the Assess product. class Interface include Contrast::Components::ComponentBase include Contrast::Components::Interface access_component :config, :settings def enabled? # config overrides if forcibly set return false if forcibly_disabled? return true if forcibly_enabled? SETTINGS.assess_enabled? end def tainted_columns SETTINGS.tainted_columns end def forcibly_disabled? @_forcibly_disabled = false?(CONFIG.root.assess.enable) if @_forcibly_disabled.nil? @_forcibly_disabled end def rule_disabled? name disabled_rules.include?(name) end # The value of the stacktrace should be treated as an ENUM. We upcase it for # faster comparisons when we use it. Anything not one of the known values of # 'NONE', 'SOME', or 'ALL' is treated as 'ALL' # # @return [Symbol] the normalized value of CONFIG.root.assess.stacktraces def capture_stacktrace_value @_capture_stacktrace_value ||= case CONFIG.root.assess.stacktraces.upcase when 'NONE' :NONE when 'SOME' :SOME else :ALL end end # Consider capture_stacktrace_value along with the node type # to dertmine whether stacktraces should be captured. # # capture_stacktrace_value -> (:ALL, :NONE, :SOME) # node types (SourceNode, PolicyNode, TriggerNode, PropagationNode) # # @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode] The node in question. # @param return [Boolean] to capture or not to capture, that is the question. def capture_stacktrace? policy_node return true if capture_stacktrace_value == :ALL return false if capture_stacktrace_value == :NONE # Below here capture_stacktrace_value must be :SOME. return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::SourceNode) return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::TriggerNode) false end def scan_response? @_scan_response = !false?(CONFIG.root.assess.enable_scan_response) if @_scan_response.nil? @_scan_response end def track_frozen_sources? @_track_frozen_sources = !false?(CONFIG.root.agent.ruby.track_frozen_sources) if @_track_frozen_sources.nil? @_track_frozen_sources end def require_scan? @_require_scan = !false?(CONFIG.root.agent.ruby.require_scan) if @_require_scan.nil? @_require_scan end def tags CONFIG.root.assess&.tags end def rules SETTINGS.assess_rules end private def forcibly_enabled? @_forcibly_enabled = true?(CONFIG.root.assess.enable) if @_forcibly_enabled.nil? @_forcibly_enabled end def disabled_rules # TODO: RUBY-903 CONFIG.root.assess&.rules&.disabled_rules || SETTINGS.disabled_assess_rules || [] end end COMPONENT_INTERFACE = Interface.new end end end