contrast-agent 6.15.2 → 6.15.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2f94b8a7a87febf8c10b58cf5133081a6dc3183c158ad59c202921efc23753e
4
- data.tar.gz: 2e3fff601596655f725a4bea7a8b6f309a5f702557cfb009ad82b1d424da8d40
3
+ metadata.gz: bb55239bd37c7b0d2c3adc47d2e47ff25e331694b9be68522a29f8e4ce8c1220
4
+ data.tar.gz: 41a5a677403dd10c0dcd67673b32e32aa8f8ad04a82d963891f95ceaa25b46a1
5
5
  SHA512:
6
- metadata.gz: cd0a28ee1a7331401a4709e1aec63a44b272d9d93ba9e6dcebd47270078165b42e3955fe8d938311b10cae4ec60cfaa92d9bee088b3a6056a2461fb00c6a4ab8
7
- data.tar.gz: ba7ab7bebd769fd3057533da348a260e208bb622fe50aab3d0e68f8709413579bac258588680f04a65aa68ff4f5dbf0a2038d56fde7fd2ef2892a095e0e8e388
6
+ metadata.gz: 94aaa0a8ed0b9fb08fb5c206bee3695cd1cc1f3a8b7752fa8c52abfb563a4e58fac60162ab13c4f06ceb785532ae1a76b93dcc8f348e99d29b112b265a88051b
7
+ data.tar.gz: 658421a2a8558bac001eb707340f0bc763012d06b9fdcfe1137fb3ceff6f53966d7cc9af9bced07f08411b5e44af1ad5c4f5805b54abaae0ad71dcc81011fbb9
@@ -33,8 +33,8 @@ module Contrast
33
33
  # Parse the given controller and route from a Rack based application framework in order to create an instance
34
34
  # of this class
35
35
  #
36
- # @param final_controller [Grape::API, Sinatra::Base] the controller responsible for the definition of the
37
- # entrypoint of the route actively being executed
36
+ # @param final_controller [Class<Grape::API>, Class<Sinatra::Base>] the controller responsible for the
37
+ # definition of the entrypoint of the route actively being executed
38
38
  # @param method [String] the HTTP request method of the route actively being executed
39
39
  # @param route_pattern [Grape::Router::Route, Mustermann::Sinatra] the pattern to which the url maps
40
40
  # @param url [String] the literal url of the route actively being executed
@@ -135,6 +135,8 @@ module Contrast
135
135
  @observed_route = Contrast::Agent::Reporting::ObservedRoute.new
136
136
  reporting_route = Contrast::Agent.framework_manager.get_route_information(@request)
137
137
  append_to_observed_route(reporting_route)
138
+ rescue StandardError => e
139
+ logger.error('Unable to determine current route', e)
138
140
  end
139
141
  end
140
142
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Contrast
5
5
  module Agent
6
- VERSION = '6.15.2'
6
+ VERSION = '6.15.3'
7
7
  end
8
8
  end
@@ -67,30 +67,39 @@ module Contrast
67
67
  # Given the current request - return a RouteCoverage object
68
68
 
69
69
  # @param request [Contrast::Agent::Request] a contrast tracked request.
70
- # @param controller [::Sinatra::Base] optionally use this controller instead of global ::Sinatra::Base.
70
+ # @param _controller [::Sinatra::Base] optionally use this controller instead of global ::Sinatra::Base.
71
71
  # @return [Contrast::Agent::Reporting::RouteCoverage, nil] a Dtm describing the route
72
72
  # matched to the request if a match was found.
73
- def current_route_coverage request, controller = ::Sinatra::Base, full_route = nil
74
- return unless sinatra_controller?(controller)
75
-
73
+ def current_route_coverage request, _controller = ::Sinatra::Base, full_route = nil
76
74
  method = request.env[::Rack::REQUEST_METHOD] # GET, PUT, POST, etc...
77
-
75
+ route = _cleaned_route(request)
78
76
  # Find route match--checking superclasses if necessary.
79
- final_controller, route_pattern = _route_recurse(controller, method, _cleaned_route(request))
80
- return unless final_controller && route_pattern
77
+ sinatra_controllers.each do |potential_controller|
78
+ next unless sinatra_controller?(potential_controller)
79
+
80
+ next if potential_controller.nil? || potential_controller.cs__class == NilClass
81
81
 
82
- full_route ||= request.env[::Rack::PATH_INFO]
82
+ route_patterns = potential_controller.routes.fetch(method) { [] }.
83
+ map(&:first)
84
+ route_pattern = route_patterns.find do |matcher|
85
+ matcher.params(route) # ::Mustermann::Sinatra match.
86
+ end
87
+ next unless route_pattern
83
88
 
84
- new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
85
- new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
86
- new_route_coverage
89
+ full_route ||= request.env[::Rack::PATH_INFO]
90
+ new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
91
+ new_route_coverage.attach_rack_based_data(potential_controller, method, route_pattern, full_route)
92
+ return new_route_coverage
93
+ end
94
+ nil
87
95
  end
88
96
 
89
97
  # Search object space for sinatra controllers--any class that subclasses ::Sinatra::Base.
90
98
  #
91
- # @return [Array<::Sinatra::Base>] sinatra controlelrs
99
+ # @return [Array<Class<::Sinatra::Base>>] sinatra controlelrs
92
100
  def sinatra_controllers
93
- [::Sinatra::Base] + ObjectSpace.each_object(Class).select { |clazz| sinatra_controller?(clazz) }
101
+ @_sinatra_controllers ||=
102
+ [::Sinatra::Base] + ObjectSpace.each_object(Class).select { |clazz| sinatra_controller?(clazz) }
94
103
  end
95
104
 
96
105
  def retrieve_request env
@@ -112,31 +121,6 @@ module Contrast
112
121
 
113
122
  private
114
123
 
115
- # Given a controller and a route to match against, find the route_pattern and class that will serve the
116
- # route. This is recursive as Sinatra's routing is recursive from subclass to super.
117
- #
118
- # @param controller [Sinatra::Base, #routes] a Sinatra application.
119
- # @param method [::Rack::REQUEST_METHOD] GET, POST, PUT, etc...
120
- # @param route [String] the relative route passed from Rack.
121
- # @return [Array[Sinatra::Base, Mustermann::Sinatra], nil] Either the controller that
122
- # will handle the route along with the route pattern or nil if no match.
123
- def _route_recurse controller, method, route
124
- return if controller.nil? || controller.cs__class == NilClass
125
-
126
- route_patterns = controller.routes.fetch(method) { [] }.
127
- map(&:first)
128
- route_pattern = route_patterns&.find do |matcher|
129
- matcher.params(route) # ::Mustermann::Sinatra match.
130
- end
131
-
132
- return controller, route_pattern if route_pattern
133
-
134
- # Check routes defined in superclass if present.
135
- return unless controller.superclass&.instance_variable_get(:@routes)
136
-
137
- _route_recurse(controller.superclass, method, route)
138
- end
139
-
140
124
  # Get route and do some cleanup matching that of Sinatra::Base#process_route.
141
125
  #
142
126
  # @param request [Contrast::Agent::Request] a contrast tracked request.
@@ -44,14 +44,15 @@ module Contrast
44
44
  update(route.signature)
45
45
  if (observation = route.observations[0])
46
46
  update(observation.verb)
47
+ else
48
+ update(request.request_method)
47
49
  end
48
- return
49
- end
50
-
51
- return unless request ||= context&.request
50
+ else
51
+ return unless request ||= context&.request
52
52
 
53
- update(request.normalized_uri) # the normalized URL used to access the method in the route.
54
- update(request.request_method) # The HTTP method used in the request
53
+ update(request.normalized_uri) # the normalized URL used to access the method in the route.
54
+ update(request.request_method)
55
+ end
55
56
  end
56
57
 
57
58
  # Update to CRC checksum the event source name and source type.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrast-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.15.2
4
+ version: 6.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - galen.palmer@contrastsecurity.com
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2023-02-22 00:00:00.000000000 Z
16
+ date: 2023-02-23 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler