Class: Contrast::Extension::Assess::EvalTrigger

Inherits:
Object
  • Object
show all
Includes:
Components::Interface
Defined in:
lib/contrast/extension/assess/eval_trigger.rb,
ext/cs__assess_module/cs__assess_module.c,
ext/cs__assess_basic_object/cs__assess_basic_object.c

Overview

This Module allows us to track calls to the BasicObject#eval method, which violates the design of most methods we track in that we have to apply the trigger in a custom patch over one of the generic triggers in TriggerMethod.

Class Method Summary collapse

Methods included from Components::Interface

included

Class Method Details

.apply_trigger(obj, source, ret, clazz, method) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/contrast/extension/assess/eval_trigger.rb', line 26

def apply_trigger obj, source, ret, clazz, method
  current_context = Contrast::Agent::REQUEST_TRACKER.current
  return unless current_context

  # Since we know this is the source of the trigger, we can do some
  # optimization here and return when it is not tracked
  return unless Contrast::Utils::Assess::TrackingUtil.tracked?(source)

  # source might not be all the args passed in, but it is the one we care
  # about. we could pass in all the args in the last param here if it
  # becomes an issue in rendering on TS
  Contrast::Agent::Assess::Policy::TriggerMethod.apply_eval_trigger(
      current_context,
      trigger_node(clazz, method),
      source,
      obj,
      ret,
      source)
end

.eval_trigger_check(obj, source, ret, method) ⇒ Object



22
23
24
# File 'lib/contrast/extension/assess/eval_trigger.rb', line 22

def eval_trigger_check obj, source, ret, method
  apply_trigger(obj, source, ret, 'Module', method)
end

.instance_eval_trigger_check(obj, source, ret) ⇒ Object



18
19
20
# File 'lib/contrast/extension/assess/eval_trigger.rb', line 18

def instance_eval_trigger_check obj, source, ret
  apply_trigger(obj, source, ret, 'BasicObject', :instance_eval)
end

.instrument_basic_object_trackObject



46
47
48
49
50
51
52
53
54
# File 'lib/contrast/extension/assess/eval_trigger.rb', line 46

def instrument_basic_object_track
  @_instrument_basic_object_track ||= begin
    require 'cs__assess_basic_object/cs__assess_basic_object'
    true
  end
rescue StandardError, LoadError => e
  logger.error('Error loading basic object track patch', e)
  false
end

.instrument_module_trackObject



56
57
58
59
60
61
62
63
64
# File 'lib/contrast/extension/assess/eval_trigger.rb', line 56

def instrument_module_track
  @_instrument_module_track ||= begin
    require 'cs__assess_module/cs__assess_module'
    true
  end
rescue StandardError, LoadError => e
  logger.error('Error loading module track patch', e)
  false
end