# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/components/logger' require 'contrast/utils/duck_utils' require 'contrast/agent/reporting/reporting_events/reporting_event' module Contrast module Agent module Reporting # This is the new FindingEventStack class which will include all the needed information for the new reporting # system to relay this information in the Finding/Trace messages. These FindingEventStack are used by TeamServer # to construct the vulnerability information for the assess feature. They represent the callstack at the time # that each FindingEvent was generated. class FindingEventStack < Contrast::Agent::Reporting::ReportingEvent # @return [String] unused attr_reader :eval # @return [String] the stack frame to show in TeamServer; the value of an entry in #caller attr_reader :file # @return [String] unused attr_reader :line_number # @return [String] unused attr_reader :method # @return [String] unused attr_reader :signature # @return [String] unused attr_reader :type AGENT_CLASS_MARKER = '/lib/contrast/' # To play nice with the way that TeamServer is rendering these values, we only populate the file_name field with # exactly what we want them to display. # # @param file_name [String] the caller location this stack frame represents. def initialize file_name @file = file_name super() end # Convert the instance variables on the class, and other information, into the identifiers required for # TeamServer to process the JSON form of this message. # # @return [Hash] # @raise [ArgumentError] def to_controlled_hash validate { file: file # eval: eval, # This is unused by the Ruby agent # line_number: line_number, # This is unused by the Ruby agent # method: method, # This is unused by the Ruby agent # signature: signature, # This is unused by the Ruby agent # type: type # This is unused by the Ruby agent } end def validate return unless Contrast::Utils::DuckUtils.empty_duck?(file) raise(ArgumentError, "#{ self } did not have a proper file. Unable to continue.") end end end end end