# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/components/logger' 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 include Contrast::Components::Logger::InstanceMethods # @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 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 begin validate rescue ArgumentError => e logger.error('FindingEventStack validation failed with: ', e) return end { 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 raise(ArgumentError, "#{ self } did not have a proper hash. Unable to continue.") unless file && !file.empty? end end end end end