Sha256: cf40c6154423a69ed7ad6966835ed07c3f8a29b13e4da22e0f96a8edb1325379

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

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

require 'contrast/agent/protect/rule/base'
require 'contrast/agent/reporting/input_analysis/input_type'
require 'contrast/agent/reporting/input_analysis/score_level'
require 'contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification'

module Contrast
  module Agent
    module Protect
      module Rule
        # The Ruby implementation of the Protect Unsafe File Upload rule.
        # The unsafe-file-upload rule can trigger the following results:
        # BLOCKED in Blocking mode and SUSPICIOUS in Monitor mode.
        class UnsafeFileUpload < Contrast::Agent::Protect::Rule::Base
          include Contrast::Agent::Reporting::InputType

          NAME = 'unsafe-file-upload'
          BLOCK_MESSAGE = 'Unsafe file upload rule triggered. Request blocked.'
          APPLICABLE_USER_INPUTS = [MULTIPART_NAME, MULTIPART_FIELD_NAME].cs__freeze

          def rule_name
            NAME
          end

          def applicable_user_inputs
            APPLICABLE_USER_INPUTS
          end

          # Return the specific blocking message for this rule.
          #
          # @return [String] the reason for the raised security exception.
          def block_message
            BLOCK_MESSAGE
          end

          # Unsafe File Upload input classification
          #
          # @return [module<Contrast::Agent::Protect::Rule::UnsafeFileUploadInputClassification>]
          def classification
            @_classification ||= Contrast::Agent::Protect::Rule::UnsafeFileUploadInputClassification.cs__freeze
          end

          private

          # @param context [Contrast::Agent::RequestContext]
          # @return [Boolean]
          def prefilter? context
            return false unless context
            return false unless enabled?

            true
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload.rb
contrast-agent-7.6.0 lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload.rb
contrast-agent-7.5.0 lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload.rb
contrast-agent-7.4.1 lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload.rb