# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Agent module Assess module Policy module Propagator # Propagation that results in all the tags of the source being # applied to the totality of the target. The target's preexisting # tags are unaffected beyond any merging of overlapping tags. class Splat < Contrast::Agent::Assess::Policy::Propagator::Base class << self def propagate propagation_node, preshift, target tracked_inputs = [] propagation_node.sources.each do |source| case source when Contrast::Utils::ObjectShare::OBJECT_KEY tracked_inputs << preshift.object if preshift.object.cs__tracked? else arg = preshift.args[source] if arg.is_a?(String) tracked_inputs << arg if arg.cs__tracked? elsif Contrast::Utils::DuckUtils.iterable_hash?(arg) arg.each_pair do |key, value| tracked_inputs << key if tracked_value?(key) tracked_inputs << value if tracked_value?(value) end elsif Contrast::Utils::DuckUtils.iterable_enumerable?(arg) arg.each do |value| tracked_inputs << value if tracked_value?(value) end end end end splat_tags(tracked_inputs, target) target.cs__properties.cleanup_tags end def splat_tags tracked_inputs, target return if tracked_inputs.empty? tracked_inputs.each do |input| unless input == target input.cs__properties.events.each do |event| target.cs__properties.events << event end end input.cs__splat_tags(target) end end end end end end end end end