Sha256: ddde0e95046690ad7d8a2c5cb9599a9a32236c94900bc86cd1bed359ca0c39c6

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

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

cs__scoped_require 'contrast/utils/prevent_serialization'
cs__scoped_require 'contrast/agent/assess/properties'

module Contrast
  module Agent
    module Assess
      # This is just a wrapper around Properties so that if they are on a frozen
      # object, they are left mutable for us.
      class Insulator
        # Return a new delegator with a properties method, used to track
        # properties in a manner that won't be serialized.
        #
        # @return [SimpleDelegator<Object>]
        def self.generate
          delegator = SimpleDelegator.new(nil)
          delegator.extend(Contrast::Utils::PreventPsychSerialization)
          delegator
        end

        # Return the frozen properties delegator, which is a
        #
        # @return [SimpleDelegator<Object>]
        def self.generate_frozen
          @_generate_frozen ||= begin
                                  delegator = SimpleDelegator.new(nil)
                                  delegator.extend(Contrast::Utils::PreventPsychSerialization)
                                  delegator
                                end
        end
      end
    end
  end
end

# Our patch of the SimpleDelegator class, allowing us to leverage its
# marshal_dump and marshal_load methods to hide our properties on an object so
# that they will not be dumped or loaded.
# We do this to prevent polluting data that may run on applications that are no
# longer instrumented with Contrast
class SimpleDelegator
  # rubocop:disable Naming/MemoizedInstanceVariableName
  def properties
    @delegate_properties ||= Contrast::Agent::Assess::Properties.new
  end
  # rubocop:enable Naming/MemoizedInstanceVariableName
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-3.13.2 lib/contrast/agent/assess/insulator.rb
contrast-agent-3.13.1 lib/contrast/agent/assess/insulator.rb
contrast-agent-3.13.0 lib/contrast/agent/assess/insulator.rb
contrast-agent-3.12.2 lib/contrast/agent/assess/insulator.rb
contrast-agent-3.12.1 lib/contrast/agent/assess/insulator.rb
contrast-agent-3.12.0 lib/contrast/agent/assess/insulator.rb
contrast-agent-3.11.0 lib/contrast/agent/assess/insulator.rb