Sha256: 6fd27aebfea0f3aaadedc561f8fc88ec8a107029b69d6e6073c42a6118a52470

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

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

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

9 entries across 9 versions & 1 rubygems

Version Path
contrast-agent-4.4.1 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.4.0 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.3.2 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.3.1 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.3.0 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.2.0 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.1.0 lib/contrast/extension/protect/kernel.rb
contrast-agent-4.0.0 lib/contrast/extension/protect/kernel.rb
contrast-agent-3.16.0 lib/contrast/extension/protect/kernel.rb