Class: Contrast::Agent::Reporting::FindingEvent

Inherits:
ReportableHash show all
Defined in:
lib/contrast/agent/reporting/reporting_events/finding_event.rb

Overview

This is the new FindingEvent class which will include all the needed information for the new reporting system to relay this information in the Finding/Trace messages. These FindingEvents are used by TeamServer to construct the vulnerability information for the assess feature. They represent the operation the application underwent that transformed data during the dataflow.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ReportableHash

#event_json, #valid?

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initialize(event_data = nil, source_type = nil, source_name = nil) ⇒ Contrast::Agent::Reporting::FindingEvent

Creates new FindingEvent.



99
100
101
102
103
104
105
106
107
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 99

def initialize event_data = nil, source_type = nil, source_name = nil
  @event_sources = []
  @stack = []
  @time = Contrast::Utils::Timer.now_ms
  @thread = Thread.current.object_id.to_s
  @event_id = Contrast::Agent::Reporting::FindingEvent.next_atomic_id
  initialize_routine(event_data, source_type, source_name)
  super()
end

Instance Attribute Details

#actionSymbol (readonly)



31
32
33
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 31

def action
  @action
end

#argsArray<Contrast::Agent::Assess::ContrastObject, nil> (readonly)



36
37
38
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 36

def args
  @args
end

#codenil (readonly)



38
39
40
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 38

def code
  @code
end

#event_idInteger (readonly)



40
41
42
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 40

def event_id
  @event_id
end

#event_sourcesArray<Contrast::Agent::Reporting::EventSource> (readonly)



42
43
44
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 42

def event_sources
  @event_sources
end

#field_namenil (readonly)



48
49
50
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 48

def field_name
  @field_name
end

#objectContrast::Agent::Assess::ContrastObject (readonly)



55
56
57
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 55

def object
  @object
end

#parent_object_idsArray<Contrast::Agent::Reporting::FindingEventParentObject> (readonly)



58
59
60
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 58

def parent_object_ids
  @parent_object_ids
end

#policy_nodeContrast::Agent::Assess::Policy::PolicyNode (readonly)



60
61
62
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 60

def policy_node
  @policy_node
end

#propertiesArray<Contrast::Agent::Reporting::FindingEventProperty> (readonly)



62
63
64
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 62

def properties
  @properties
end

#reportable_argsArray<Contrast::Agent::Reporting::FindingEventObject> (readonly)



33
34
35
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 33

def reportable_args
  @reportable_args
end

#reportable_objectContrast::Agent::Reporting::FindingEventObject (readonly)



50
51
52
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 50

def reportable_object
  @reportable_object
end

#reportable_retContrast::Agent::Reporting::FindingEventObject (readonly)



64
65
66
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 64

def reportable_ret
  @reportable_ret
end

#reportable_tagsString (readonly)



74
75
76
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 74

def reportable_tags
  @reportable_tags
end

#requestContrast::Agent::Request? (readonly)



52
53
54
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 52

def request
  @request
end

#retContrast::Agent::Assess::ContrastObject (readonly)



66
67
68
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 66

def ret
  @ret
end

#signatureContrast::Agent::Reporting::FindingEventSignature (readonly)



68
69
70
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 68

def signature
  @signature
end

#sourceString (readonly)



70
71
72
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 70

def source
  @source
end

#source_nameString? (readonly)



46
47
48
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 46

def source_name
  @source_name
end

#source_typeString? (readonly)



44
45
46
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 44

def source_type
  @source_type
end

#stackArray<Contrast::Agent::Reporting::FindingEventStack> (readonly)



72
73
74
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 72

def stack
  @stack
end

#stack_traceArray<String> (readonly)



89
90
91
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 89

def stack_trace
  @stack_trace
end

#tagsHash<Contrast::Agent::Assess::Tag> (readonly)



76
77
78
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 76

def tags
  @tags
end

#taint_rangesArray<Contrast::Agent::Reporting::FindingEventTaintRange> (readonly)



79
80
81
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 79

def taint_ranges
  @taint_ranges
end

#targetString (readonly)



81
82
83
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 81

def target
  @target
end

#threadString (readonly)



83
84
85
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 83

def thread
  @thread
end

#timeInteger (readonly)



85
86
87
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 85

def time
  @time
end

#typeString (readonly)



87
88
89
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 87

def type
  @type
end

Class Method Details

.from_source(source) ⇒ Array<Contrast::Agent::Reporting::FindingEvent>

Find all the events leading up to the given source and return an array of FindingEvents



159
160
161
162
163
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 159

def from_source source
  return unless source && (props = Contrast::Agent::Assess::Tracker.properties(source))

  build_events([], props.event) if props.event
end

.next_atomic_idObject



140
141
142
143
144
145
146
147
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 140

def self.next_atomic_id
  @atomic_mutex.synchronize do
    @atomic_id += 1
    # Rollover things
  rescue StandardError
    @atomic_id = 1
  end
end

Instance Method Details

#initialize_routine(event_data, source_type = nil, source_name = nil) ⇒ Object

Init routine to find parents events, capture stack trace and retrieve object, args, ret and properties.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 116

def initialize_routine event_data, source_type = nil, source_name = nil
  return unless event_data&.cs__is_a?(Contrast::Agent::Assess::Events::EventData)

  # Initialize source event:
  if event_data.policy_node.cs__class == Contrast::Agent::Assess::Policy::SourceNode
    build_source_event(source_type, source_name)
  end

  @policy_node = event_data.policy_node
  @tags = Contrast::Agent::Assess::Tracker.properties(event_data.tagged)&.get_tags
  find_parent_events!(event_data.policy_node, event_data.object, event_data.ret, event_data.args)
  snapshot!(event_data.object, event_data.ret, event_data.args)
  display_params!
  capture_stacktrace!
  stack!
  properties!
  # following methods must be called after snapshot!
  dataflow!
  @signature = Contrast::Agent::Reporting::FindingEventSignature.new(policy_node, args, ret)
end

#parent_eventsArray<Contrast::Agent::Reporting::FindingEvent>



150
151
152
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 150

def parent_events
  @_parent_events ||= []
end

#to_controlled_hashHash

Convert the instance variables on the class, and other information, into the identifiers required for TeamServer to process the JSON form of this message.

Raises:

  • (ArgumentError)


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 189

def to_controlled_hash # rubocop:disable Metrics/AbcSize
  validate
  {
      action: action,
      args: reportable_args.map(&:to_controlled_hash),
      # code: code, # Unused by our agent
      objectId: event_id,
      eventSources: event_sources.map(&:to_controlled_hash),
      # fieldName: field_name, # Unused by our agent
      object: reportable_object.to_controlled_hash,
      parentObjectIds: parent_object_ids.map(&:to_controlled_hash),
      properties: properties.map(&:to_controlled_hash),
      ret: reportable_ret&.to_controlled_hash,
      signature: signature.to_controlled_hash,
      source: source || '',
      stack: stack.map(&:to_controlled_hash),
      tags: reportable_tags.join(','),
      taintRanges: taint_ranges.map(&:to_controlled_hash),
      target: target || '',
      thread: thread,
      time: time,
      type: type
  }
end

#validateObject

Raises:

  • (ArgumentError)


215
216
217
218
# File 'lib/contrast/agent/reporting/reporting_events/finding_event.rb', line 215

def validate
  validate_base
  validate_dataflow
end