Sha256: c62e37252c7411275b32b5f0e9c64b6f53b00be20612076cde371b30043ff698

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

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

require 'contrast/components/logger'

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::Logger::InstanceMethods

        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
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-4.14.1 lib/contrast/extension/assess/hash.rb
contrast-agent-4.14.0 lib/contrast/extension/assess/hash.rb
contrast-agent-4.13.1 lib/contrast/extension/assess/hash.rb
contrast-agent-4.13.0 lib/contrast/extension/assess/hash.rb
contrast-agent-4.12.0 lib/contrast/extension/assess/hash.rb
contrast-agent-4.11.0 lib/contrast/extension/assess/hash.rb
contrast-agent-4.10.0 lib/contrast/extension/assess/hash.rb