lib/contrast/framework/manager.rb in contrast-agent-3.11.0 vs lib/contrast/framework/manager.rb in contrast-agent-3.12.0

- old
+ new

@@ -1,13 +1,13 @@ # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true cs__scoped_require 'contrast/framework/view_technologies_descriptor' cs__scoped_require 'contrast/framework/platform_version' -cs__scoped_require 'contrast/framework/base_support' -cs__scoped_require 'contrast/framework/rails_support' -cs__scoped_require 'contrast/framework/sinatra_support' +cs__scoped_require 'contrast/framework/rack/support' +cs__scoped_require 'contrast/framework/rails/support' +cs__scoped_require 'contrast/framework/sinatra/support' cs__scoped_require 'contrast/components/interface' cs__scoped_require 'contrast/utils/class_util' module Contrast module Framework @@ -18,12 +18,13 @@ # Order here does matter as the first framework listed will be the first one we pull information from # Rack will be a special case that may involve updating some logic to handle only applying Rack if Rails/Sinatra # do not exist SUPPORTED_FRAMEWORKS = [ - Contrast::Framework::RailsSupport, - Contrast::Framework::SinatraSupport + Contrast::Framework::Rails::Support, + Contrast::Framework::Sinatra::Support, + Contrast::Framework::Rack::Support ].cs__freeze def initialize @_frameworks = SUPPORTED_FRAMEWORKS.map do |framework_klass| next unless enable_framework_support?(framework_klass.detection_class) @@ -32,10 +33,34 @@ framework_klass end @_frameworks.compact! end + # Patches that have to be applied as early as possible to catch calls + # that happen prior to the first Request, typically those around + # configuration. + def before_load_patches! + @_before_load_patches ||= begin + SUPPORTED_FRAMEWORKS.each(&:before_load_patches) + true + end + end + + # Return all the After Load Patches for all the Frameworks we know, even + # if that Framework hasn't been detected. + # + # @return [Set<Contrast::Agent::Patching::Policy::AfterLoadPatch>] the + # AfterLoadPatches of each framework + def find_after_load_patches + patches = Set.new + SUPPORTED_FRAMEWORKS.each do |framework| + framework_patches = framework.after_load_patches + patches.merge(framework_patches) if framework_patches && !framework_patches.empty? + end + patches + end + def find_applicable_view_technologies scan_views_for_all_frameworks end def find_route_discovery_data @@ -56,20 +81,20 @@ first_framework_result :application_name, 'root' end def app_root found = first_framework_result :application_root, nil - found || Rack::Directory.new('').root + found || ::Rack::Directory.new('').root end # If we have 0 or n > 1 frameworks, we need to use the default rack request # @param env [Hash] the various variables stored by this and other Middlewares to know the state # and values of this particular Request def retrieve_request env return @_frameworks[0].retrieve_request(env) if @_frameworks.length == 1 - Rack::Request.new(env) + ::Rack::Request.new(env) end # @param env [Hash] the various variables stored by this and other Middlewares to know the state # and values of this particular Request # @return [Boolean] true if at least one framework is streaming the response; false if none are streaming @@ -84,10 +109,10 @@ def get_route_dtm request result = nil @_frameworks.find do |framework_klass| # TODO: RUBY-763 Sinatra::Base#call patch adds the Route report - next if framework_klass == Contrast::Framework::SinatraSupport + next if framework_klass == Contrast::Framework::Sinatra::Support result = framework_klass.current_route(request) end result end