Sha256: 6bba15977a6386d6e2e5db870af2424f453c5274c09203bb43d22fdfb2e24748

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

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

require 'contrast/components/interface'

module Contrast
  module Extension
    module Assess
      # This Class provides us with a way to invoke Hash propagation for those
      # methods which are too complex to fit into one of the standard
      # Contrast::Agent::Assess::Policy::Propagator molds.
      class HashPropagator
        include Contrast::Components::Interface
        access_component :logging
        class << self
          def cs__duplicate_and_freeze object
            return object unless object.is_a?(String) && !object.cs__frozen?
            return object unless Contrast::Agent::Assess::Tracker.tracked?(object)

            # Copy the object, then freeze it, so that it looks the same
            # externally, but will have our finalizer on it.
            object.dup&.cs__freeze
          rescue StandardError
            # we'll rescue this error, but we can't log it here as that will
            # result in a seg fault
            object
          end

          def instrument_hash_track
            @_instrument_hash_track ||= begin
              require 'cs__assess_hash/cs__assess_hash'
              true
            end
          rescue StandardError, LoadError => e
            logger.error('Error loading hash track patch', e)
            false
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-4.4.1 lib/contrast/extension/assess/hash.rb
contrast-agent-4.4.0 lib/contrast/extension/assess/hash.rb
contrast-agent-4.3.2 lib/contrast/extension/assess/hash.rb
contrast-agent-4.3.1 lib/contrast/extension/assess/hash.rb
contrast-agent-4.3.0 lib/contrast/extension/assess/hash.rb