Sha256: 4b49f2232e41ff05a5c140feb062c34a6acbaedf9841c8f7653eb85bc0ac862d

Contents?: true

Size: 1.87 KB

Versions: 16

Compression:

Stored size: 1.87 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/assess/policy/policy'
require 'contrast/agent/patching/policy/patcher'
require 'contrast/agent/patching/policy/method_policy'
require 'contrast/agent/patching/policy/module_policy'
require 'contrast/components/logger'
require 'contrast/components/scope'

module Contrast
  module Agent
    module Assess
      module Policy
        # This is how we patch into our customer's code. It provides a way to
        # track which classes we need to patch into and, once we've woven,
        # provides a map for which methods our renamed functions need to call
        # and how.
        module Patcher
          extend Contrast::Components::Logger::InstanceMethods
          extend Contrast::Components::Scope::InstanceMethods

          class << self
            def policy
              Contrast::Agent::Assess::Policy::Policy.instance
            end

            def patcher
              Contrast::Agent::Patching::Policy::Patcher
            end

            # Some of the methods we care about, especially those used as dynamic
            # sources, are truly dynamic, in that they do not exist on class
            # load. These methods only exist once a module or class eval has been
            # called. This hook is provided so that patches to those methods can
            # pass us execution flow once a new method has been made available.
            def patch_assess_on_eval mod
              return unless ::Contrast::ASSESS.enabled?
              return if in_contrast_scope?

              patcher.patch_specific_module(mod)
            rescue StandardError => e
              logger.warn('Unable to patch assess during eval', e, module: mod.cs__name)
            end
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
contrast-agent-7.5.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.4.1 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.4.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.3.2 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.3.1 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.3.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.2.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.1.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.0.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.15.3 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.15.2 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.15.1 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.15.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.14.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.13.0 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-6.12.0 lib/contrast/agent/assess/policy/patcher.rb