Sha256: e11dab05b302c4bc22c149befd8c28fffcbb5ff669f5c2b83ddd20907c587942

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 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/components/interface'

module Contrast
  module Extension
    module Protect
      # This Module functions as our patch into the Kernel class for Protect,
      # allowing us to track activity as it crosses spawned processes.
      module Kernel
        class << self
          include Contrast::Components::Interface
          access_component :contrast_service

          def build_wrapper
            lambda {
              proc_start
              yield
              # AtExitHook handles sending any messages generated in the new forked process
            }
          end

          def proc_start
            context = Contrast::Agent::REQUEST_TRACKER.current
            return unless context

            context.reset_activity
          end

          def instrument
            @_instrument ||= begin
                                               cs__scoped_require 'cs__protect_kernel/cs__protect_kernel'
                                               true
                                             end
          rescue StandardError, LoadError => e
            logger.error('Error loading kernel protect patch', e)
            false
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contrast-agent-3.13.2 lib/contrast/extension/protect/kernel.rb
contrast-agent-3.13.1 lib/contrast/extension/protect/kernel.rb
contrast-agent-3.13.0 lib/contrast/extension/protect/kernel.rb
contrast-agent-3.12.2 lib/contrast/extension/protect/kernel.rb
contrast-agent-3.12.1 lib/contrast/extension/protect/kernel.rb
contrast-agent-3.12.0 lib/contrast/extension/protect/kernel.rb