lib/contrast/agent/assess/policy/propagation_node.rb in contrast-agent-6.2.0 vs lib/contrast/agent/assess/policy/propagation_node.rb in contrast-agent-6.3.0

- old
+ new

@@ -1,10 +1,11 @@ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/agent/assess/policy/policy_node' require 'contrast/api/decorators/trace_taint_range_tags' +require 'contrast/components/logger' module Contrast module Agent module Assess module Policy @@ -12,10 +13,12 @@ # Ruby object, allowing for dynamic patching over hardcoded patching, # specifically for those methods which result in the transformation of # untrusted data (indicate points in the application where user # controlled input is modified). class PropagationNode < PolicyNode + include Contrast::Components::Logger::InstanceMethods + JSON_ACTION = 'action' JSON_UNTAGS = 'untags' JSON_PATCH_CLASS = 'patch_class' JSON_PATCH_METHOD = 'patch_method' @@ -39,10 +42,13 @@ @untags = Set.new(propagation_hash[JSON_UNTAGS]) @patch_class = propagation_hash[JSON_PATCH_CLASS] @patch_method = propagation_hash[JSON_PATCH_METHOD] @patch_method = @patch_method.to_sym if @patch_method validate + rescue ArgumentError => e + logger.error('Propagation Node Initialization failed with: ', e) + nil end def node_class @_node_class ||= tagger? ? TAGGER : PROPAGATOR end @@ -54,10 +60,11 @@ tagger? ? :TYPE_TAG : :TYPE_PROPAGATION end # Standard validation + TS trace version two rules: # Must have source, target, and action + # @raise[ArgumentError] raises if any of the required propagation node field is not valid, or is missing def validate super raise(ArgumentError, "Propagator #{ id } did not have a proper action. Unable to create.") unless action if @action == 'CUSTOM' @@ -76,9 +83,10 @@ end end validate_untags end + # @raise[ArgumentError] raises if any of the tags is invalid def validate_untags return unless untags untags.each do |tag| unless Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag)