Sha256: a8c3a24ea03a3213886daa6284d3b6a410cebbb68cb0478794c4ddf5be658ee7

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 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/agent/reporting/reporting_events/application_defend_attack_activity'

module Contrast
  module Agent
    module Reporting
      # This is the new AttackerActivity class which will includes the attacker information discovered during this
      # activity period.
      class ApplicationDefendAttackerActivity
        attr_reader :attackers

        class << self
          def convert attack_result_dtm
            activity = new
            activity.attach_data attack_result_dtm
            activity
          end
        end

        def initialize
          @protection_rules = {}
          @request = Contrast::Agent::REQUEST_TRACKER.current.activity.http_request
          @event_type = :application_defend_attacker_activity
          super
        end

        def to_controlled_hash
          {
              protectionRules: process_protection_rules,
              source: {
                  ip: @request.sender.ip,
                  xForwardedFor: @request.request_headers['X-Forwarded-For']
              }
          }
        end

        # @param attack_result [Contrast::Agent::Reporting::AttackResult]
        def attach_data attack_result
          attack_activity = Contrast::Agent::Reporting::ApplicationDefendAttackActivity.convert(attack_result)
          @protection_rules[attack_result.rule_id] = attack_activity
        end

        def process_protection_rules
          arr = []
          @protection_rules.each_pair do |k, v|
            arr << { k => v&.to_controlled_hash }
          end
          arr
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-6.1.0 lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb