lib/contrast/extension/assess/fiber.rb in contrast-agent-4.8.0 vs lib/contrast/extension/assess/fiber.rb in contrast-agent-4.9.0
- old
+ new
@@ -1,10 +1,11 @@
# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true
require 'contrast/agent/assess/policy/propagation_node'
-require 'contrast/components/interface'
+require 'contrast/components/logger'
+require 'contrast/components/scope'
# In order to instrument some difficult methods like String#gsub, as it
# returns an enumerator, we need to instrument methods on Fiber.
# Specifically, we instrument 'rb_fiber_yield' and 'rb_fiber_new' in
# order to track what happens within Enumerator#next.
@@ -14,13 +15,13 @@
# This Class provides us with a way to invoke Regexp propagation for those
# methods which are too complex to fit into one of the standard
# Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
# Fiber Class or exposing our methods there.
class FiberPropagator
- include Contrast::Components::Interface
+ extend Contrast::Components::Logger::InstanceMethods
+ extend Contrast::Components::Scope::InstanceMethods
- access_component :analysis, :logging, :scope
# we use funchook to patch rb_fiber_new the initialize method is not exposed by Ruby core
FIBER_NEW_NODE_HASH = {
'class_name' => 'Fiber',
'instance_method' => true,
@@ -51,11 +52,11 @@
private_constant :FIBER_YIELD_NODE_HASH
private_constant :FIBER_YIELD_NODE
class << self
def track_rb_fiber_yield fiber, _method, results
- return unless ASSESS.enabled?
+ return unless ::Contrast::ASSESS.enabled?
# results will be nil if StopIteration was raised,
# otherwise an Array of the yielded arguments
return unless results.cs__is_a?(Array)
@@ -70,10 +71,10 @@
rescue Exception => e # rubocop:disable Lint/RescueException
logger.error('Unable to propagate during Fiber#yield', e)
end
def track_rb_fiber_new fiber, _enum, _enum_method, underlying, _underlying_method
- return unless ASSESS.enabled?
+ return unless ::Contrast::ASSESS.enabled?
return unless underlying.is_a?(String) && !underlying.empty?
with_contrast_scope do
properties = Contrast::Agent::Assess::Tracker.properties!(fiber)
return unless properties