Sha256: eec892afcf6e4f612102dfcaf73e3447b9d80000f5dfc15bb431edb152958f38

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 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.
            #
            # @param mod [Module]
            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

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/assess/policy/patcher.rb
contrast-agent-7.6.0 lib/contrast/agent/assess/policy/patcher.rb