# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Components module Agent # A wrapper build around the Common Agent Configuration project to allow # for access of the values contained in its # parent_configuration_spec.yaml. # Specifically, this allows for querying the state of the Agent. class Interface include Contrast::Components::ComponentBase include Contrast::Components::Interface access_component :config def enabled? !!@enabled end def disabled? !enabled? end def enable! @enabled = true end def disable! @enabled = false end def unavailable? !enabled? end def ready? state.agent_ready? end def patch_interpolation? interpolation_patch_possible? end def rewrite_interpolation? !interpolation_patch_possible? end def interpolation_enabled? !Contrast::Utils::BooleanUtil.false?(CONFIG.root.agent.ruby.interpolate) end def report_custom_code_sysfile_access? Contrast::Agent::FeatureState.instance.report_custom_code_sysfile_access? end # TODO: RUBY-564 Move instrumentation to a new component that handles # one-time agent initialization procedures. SHARED_LIBRARIES = %w[contrast/core_extensions/thread contrast/rails_extensions/rack contrast/rails_extensions/buffer contrast/sinatra_extensions/assess/cookie].cs__freeze def run_instrumentation Contrast::Agent::FeatureState.instance.tap do |settings| SHARED_LIBRARIES.each { |lib| settings.instrument lib } end Contrast::Agent::Patching::Policy::Patcher.patch # This acts as a catch up for everything we didn't see get loaded enable_tracepoint # This handles all class loads & required instrumentation going forward end def enable_tracepoint Contrast::Agent::TracePointHook.enable! end protected def interpolation_patch_possible? Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') end end COMPONENT_INTERFACE = Interface.new end end end