Sha256: dbdc4c16fdd20da1bcd6eb0c2703a678a83707325dceaf16edc00ec046fe038e

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/logger'
require 'contrast/components/scope'
require 'contrast/agent/reporting/reporter'
require 'contrast/agent/reporting/masker/masker'

module Contrast
  module Agent
    # This class is instantiated when we receive a request and the agent is enabled to process that request. It holds
    # the ruleset that we perform filtering operations on (currently prefilter and postfilter).
    class RequestHandler
      include Contrast::Components::Logger::InstanceMethods

      attr_reader :ruleset, :context

      # @param context [Contrast::Agent::RequestContext] the context of the request for which this handler applies
      def initialize context
        @context = context
        @ruleset = ::Contrast::AGENT.ruleset
      end

      # reports events[Contrast::Agent::Reporting::ObservedRoute] to TS
      # Other ReportingEvents are handled through batching in the middleware
      #
      def report_observed_route
        return unless (reporter = Contrast::Agent.reporter)

        reporter.send_event(context.observed_route) if Contrast::ROUTES_SENT.sendable?(context.observed_route)
      end

      # If the response is streaming, we should only perform filtering on our stream safe rules
      def stream_safe_postfilter
        stream_safe_ruleset = ruleset.select(&:stream_safe?)
        postfilter_ruleset = Contrast::Agent::RuleSet.new(stream_safe_ruleset)
        postfilter_ruleset.postfilter
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contrast-agent-6.11.0 lib/contrast/agent/request_handler.rb
contrast-agent-6.10.0 lib/contrast/agent/request_handler.rb
contrast-agent-6.9.0 lib/contrast/agent/request_handler.rb