Sha256: 474f8e4a6ff507f08225ce6a996dcb461e187572b30b9888899cf19a9f64137e

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# 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'
cs__scoped_require 'contrast/utils/data_store_util'

module Contrast
  module CoreExtensions
    module Protect
      # 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 NotImplementedError, 'This is abstract, override it.'
        end

        def name
          raise NotImplementedError, '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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-3.11.0 lib/contrast/extensions/ruby_core/protect/rule_applicator.rb