Class: Contrast::Extension::Assess::MarshalPropagator

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

Overview

This is our patch of the Array class required to handle propagation Disclaimer: there may be a better way, but we’re in a ‘get it work’ state. Hopefully, we’ll be in a ‘get it right’ state soon. This module is used for our Marshal#load patches

Class Method Summary collapse

Methods included from Components::Interface

included

Class Method Details

.cs__load_trigger_check(source, ret) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/contrast/extension/assess/marshal.rb', line 19

def cs__load_trigger_check source, ret
  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::Agent::Assess::Tracker.tracked?(source)

  args = [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.build_finding(
      current_context,
      trigger_node('Marshal', :load),
      source,
      self,
      ret,
      args)
  properties = Contrast::Agent::Assess::Tracker.properties(ret)
  properties.copy_from(source, ret)

  node = Contrast::Agent::Assess::Policy::Policy.instance.find_propagator_node('Marshal', :load, false)
  properties.build_event(node, ret, self, ret, args)
rescue StandardError => e
  logger.error('Unable to determine if a trigger occurred in Marshal.load', e)
end

.instrument_marshal_loadObject



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

def instrument_marshal_load
  @_instrument_marshal_load ||= begin
    require 'cs__assess_marshal_module/cs__assess_marshal_module'
    true
  end
rescue StandardError, LoadError => e
  logger.error('Error loading marshal load patch', e)
  false
end

.trigger_node(clazz, method) ⇒ Object



57
58
59
60
61
62
# File 'lib/contrast/extension/assess/marshal.rb', line 57

def trigger_node clazz, method
  triggers = Contrast::Agent::Assess::Policy::Policy.instance.triggers
  return unless triggers

  triggers.find { |node| node.class_name == clazz && node.method_name == method }
end