@@ -157,39 +157,65 @@ module Express {
157
157
predicate isUseCall ( ) { this .getMethodName ( ) = "use" }
158
158
159
159
/**
160
+ * DEPRECATED: Use `getRouteHandlerNode` instead.
160
161
* Gets the `n`th handler registered by this setup, with 0 being the first.
161
162
*
162
163
* This differs from `getARouteHandler` in that the argument expression is
163
164
* returned, not its dataflow source.
164
165
*/
165
- Expr getRouteHandlerExpr ( int index ) {
166
- // TODO: DataFlow::Node
166
+ deprecated Expr getRouteHandlerExpr ( int index ) { result = getRouteHandlerNode ( index ) .asExpr ( ) }
167
+
168
+ /**
169
+ * Gets the `n`th handler registered by this setup, with 0 being the first.
170
+ *
171
+ * This differs from `getARouteHandler` in that the argument expression is
172
+ * returned, not its dataflow source.
173
+ */
174
+ DataFlow:: Node getRouteHandlerNode ( int index ) {
167
175
// The first argument is a URI pattern if it is a string. If it could possibly be
168
176
// a function, we consider it to be a route handler, otherwise a URI pattern.
169
177
exists ( AnalyzedNode firstArg | firstArg = this .getArgument ( 0 ) .analyze ( ) |
170
178
if firstArg .getAType ( ) = TTFunction ( )
171
- then result = this .getArgument ( index ) . asExpr ( )
179
+ then result = this .getArgument ( index )
172
180
else (
173
- index >= 0 and result = this .getArgument ( index + 1 ) . asExpr ( )
181
+ index >= 0 and result = this .getArgument ( index + 1 )
174
182
)
175
183
)
176
184
}
177
185
178
- /** Gets an argument that represents a route handler being registered. */
179
- Expr getARouteHandlerExpr ( ) { result = this .getRouteHandlerExpr ( _) }
186
+ /**
187
+ * DEPRECATED: Use `getARouteHandlerNode` instead.
188
+ * Gets an argument that represents a route handler being registered.
189
+ */
190
+ deprecated Expr getARouteHandlerExpr ( ) { result = this .getRouteHandlerExpr ( _) }
180
191
181
- /** Gets the last argument representing a route handler being registered. */
182
- Expr getLastRouteHandlerExpr ( ) {
192
+ /**
193
+ * Gets an argument that represents a route handler being registered.
194
+ */
195
+ DataFlow:: Node getARouteHandlerNode ( ) { result = this .getRouteHandlerNode ( _) }
196
+
197
+ /**
198
+ * DEPRECATED: Use `getLastRouteHandlerExpr` instead.
199
+ * Gets the last argument representing a route handler being registered.
200
+ */
201
+ deprecated Expr getLastRouteHandlerExpr ( ) {
183
202
result = max ( int i | | this .getRouteHandlerExpr ( i ) order by i )
184
203
}
185
204
205
+ /**
206
+ * Gets the last argument representing a route handler being registered.
207
+ */
208
+ DataFlow:: Node getLastRouteHandlerNode ( ) {
209
+ result = max ( int i | | this .getRouteHandlerNode ( i ) order by i )
210
+ }
211
+
186
212
override DataFlow:: SourceNode getARouteHandler ( ) {
187
213
result = this .getARouteHandler ( DataFlow:: TypeBackTracker:: end ( ) )
188
214
}
189
215
190
216
private DataFlow:: SourceNode getARouteHandler ( DataFlow:: TypeBackTracker t ) {
191
217
t .start ( ) and
192
- result = this .getARouteHandlerExpr ( ) . flow ( ) .getALocalSource ( )
218
+ result = this .getARouteHandlerNode ( ) .getALocalSource ( )
193
219
or
194
220
exists ( DataFlow:: TypeBackTracker t2 , DataFlow:: SourceNode succ |
195
221
succ = this .getARouteHandler ( t2 )
@@ -284,10 +310,11 @@ module Express {
284
310
* a function that flows into such an argument.
285
311
*/
286
312
class RouteHandlerExpr extends Expr {
313
+ // TODO: DataFlow::Node
287
314
RouteSetup setup ;
288
315
int index ;
289
316
290
- RouteHandlerExpr ( ) { this = setup .getRouteHandlerExpr ( index ) }
317
+ RouteHandlerExpr ( ) { this = setup .getRouteHandlerNode ( index ) . asExpr ( ) }
291
318
292
319
/**
293
320
* Gets the setup call that registers this route handler.
@@ -310,7 +337,7 @@ module Express {
310
337
*/
311
338
predicate isLastHandler ( ) {
312
339
not setup .isUseCall ( ) and
313
- not exists ( setup .getRouteHandlerExpr ( index + 1 ) )
340
+ not exists ( setup .getRouteHandlerNode ( index + 1 ) )
314
341
}
315
342
316
343
/**
@@ -339,7 +366,7 @@ module Express {
339
366
index = 0 and
340
367
result = setup .getRouter ( ) .getMiddlewareStackAt ( setup .asExpr ( ) .getAPredecessor ( ) )
341
368
or
342
- index > 0 and result = setup .getRouteHandlerExpr ( index - 1 )
369
+ index > 0 and result = setup .getRouteHandlerNode ( index - 1 ) . asExpr ( )
343
370
or
344
371
// Outside the router's original container, use the flow-insensitive model of its middleware stack.
345
372
// Its state is not tracked to CFG nodes outside its original container.
@@ -920,11 +947,14 @@ module Express {
920
947
* If `node` is not in the same container where `router` was defined, the predicate has no result.
921
948
*/
922
949
Express:: RouteHandlerExpr getMiddlewareStackAt ( ControlFlowNode node ) {
950
+ // TODO: DataFlow::Node?
923
951
if
924
952
exists ( Express:: RouteSetup setup | node = setup .asExpr ( ) and setup .getRouter ( ) = this |
925
953
setup .isUseCall ( )
926
954
)
927
- then result = node .( AST:: ValueNode ) .flow ( ) .( Express:: RouteSetup ) .getLastRouteHandlerExpr ( )
955
+ then
956
+ result =
957
+ node .( AST:: ValueNode ) .flow ( ) .( Express:: RouteSetup ) .getLastRouteHandlerNode ( ) .asExpr ( )
928
958
else result = this .getMiddlewareStackAt ( node .getAPredecessor ( ) )
929
959
}
930
960
0 commit comments