# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true cs__scoped_require 'contrast/components/interface' module Contrast module Agent module Protect module Policy # This Module is the base of our Protect Applicators. It lays out the # form of the Applicator, which will override specific implementations # in order to properly invoke its Rule. module RuleApplicator include Contrast::Components::Interface access_component :analysis, :logging def apply_rule method, exception, properties, object, args invoke(method, exception, properties, object, args) rescue Contrast::SecurityException => e raise e rescue StandardError => e logger.error('Error applying protect rule', e, module: object.cs__class.cs__name, method: method, rule: name) end protected def invoke _method, _exception, _properties, _object, _args raise NoMethodError, 'This is abstract, override it.' end def name raise NoMethodError, 'This is abstract, override it.' end def rule PROTECT.rule name end def skip_analysis? context = Contrast::Agent::REQUEST_TRACKER.current return true unless context&.app_loaded? return true unless rule&.enabled? false end end end end end end