@@ -25,13 +25,10 @@ module Spife {
25
25
TaggedTemplateExpr template ;
26
26
27
27
RouteSetup ( ) {
28
- exists ( CallExpr templateCall |
29
- this .getCalleeNode ( ) .asExpr ( ) = template and
30
- API:: moduleImport ( [ "@npm/spife/routing" , "spife/routing" ] )
31
- .asSource ( )
32
- .flowsToExpr ( template .getTag ( ) ) and
33
- templateCall .getAChild ( ) = template
34
- )
28
+ this .getCalleeNode ( ) .asExpr ( ) = template and
29
+ API:: moduleImport ( [ "@npm/spife/routing" , "spife/routing" ] )
30
+ .asSource ( )
31
+ .flowsToExpr ( template .getTag ( ) )
35
32
}
36
33
37
34
private string getRoutePattern ( ) {
@@ -184,13 +181,13 @@ module Spife {
184
181
/**
185
182
* An access to a user-controlled Spife context input.
186
183
*/
187
- private class ContextInputAccess extends Http:: RequestInputAccess {
184
+ private class ContextInputAccess extends Http:: RequestInputAccess instanceof DataFlow :: MethodCallNode {
188
185
ContextSource request ;
189
186
string kind ;
190
187
191
188
ContextInputAccess ( ) {
192
- request .ref ( ) .flowsTo ( this . ( DataFlow :: MethodCallNode ) .getReceiver ( ) ) and
193
- this . ( DataFlow :: MethodCallNode ) .getMethodName ( ) = "get" and
189
+ request .ref ( ) .flowsTo ( super .getReceiver ( ) ) and
190
+ super .getMethodName ( ) = "get" and
194
191
kind = "path"
195
192
}
196
193
@@ -202,7 +199,7 @@ module Spife {
202
199
/**
203
200
* An access to a header on a Spife request.
204
201
*/
205
- private class RequestHeaderAccess extends Http:: RequestHeaderAccess {
202
+ private class RequestHeaderAccess extends Http:: RequestHeaderAccess instanceof DataFlow :: PropRead {
206
203
RouteHandler rh ;
207
204
208
205
RequestHeaderAccess ( ) {
@@ -211,7 +208,7 @@ module Spife {
211
208
}
212
209
213
210
override string getAHeaderName ( ) {
214
- result = this . ( DataFlow :: PropRead ) .getPropertyName ( ) .toLowerCase ( )
211
+ result = super .getPropertyName ( ) .toLowerCase ( )
215
212
}
216
213
217
214
override RouteHandler getRouteHandler ( ) { result = rh }
@@ -223,7 +220,7 @@ module Spife {
223
220
* A Spife response source, that is, the response variable used by a
224
221
* route handler.
225
222
*/
226
- private class ReplySource extends Http:: Servers:: ResponseSource {
223
+ private class ReplySource extends Http:: Servers:: ResponseSource instanceof DataFlow :: CallNode {
227
224
ReplySource ( ) {
228
225
// const reply = require("@npm/spife/reply")
229
226
// reply(resp)
@@ -232,14 +229,12 @@ module Spife {
232
229
this = API:: moduleImport ( [ "@npm/spife/reply" , "spife/reply" ] ) .getAMember ( ) .getACall ( )
233
230
}
234
231
235
- private DataFlow:: SourceNode reachesHandlerReturn (
236
- DataFlow:: CallNode headerCall , DataFlow:: TypeTracker t
237
- ) {
238
- result = headerCall and
232
+ private DataFlow:: SourceNode reachesHandlerReturn ( DataFlow:: TypeTracker t ) {
233
+ result = this and
239
234
t .start ( )
240
235
or
241
236
exists ( DataFlow:: TypeTracker t2 |
242
- result = this .reachesHandlerReturn ( headerCall , t2 ) .track ( t2 , t )
237
+ result = this .reachesHandlerReturn ( t2 ) .track ( t2 , t )
243
238
)
244
239
}
245
240
@@ -249,7 +244,7 @@ module Spife {
249
244
override RouteHandler getRouteHandler ( ) {
250
245
exists ( RouteHandler handler |
251
246
handler .( DataFlow:: FunctionNode ) .getAReturn ( ) .getALocalSource ( ) =
252
- this .reachesHandlerReturn ( this , DataFlow:: TypeTracker:: end ( ) ) and
247
+ this .reachesHandlerReturn ( DataFlow:: TypeTracker:: end ( ) ) and
253
248
result = handler
254
249
)
255
250
}
@@ -258,14 +253,15 @@ module Spife {
258
253
/**
259
254
* An HTTP header defined in a Spife response.
260
255
*/
261
- private class HeaderDefinition extends Http:: ExplicitHeaderDefinition , DataFlow:: MethodCallNode {
262
- ReplySource reply ;
256
+ private class HeaderDefinition extends Http:: ExplicitHeaderDefinition , DataFlow:: MethodCallNode instanceof ReplySource {
263
257
264
258
HeaderDefinition ( ) {
265
259
// reply.header(RESPONSE, 'Cache-Control', 'no-cache')
266
- reply .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "header" and
267
- reply .ref ( ) .( DataFlow:: MethodCallNode ) .getNumArgument ( ) = 3 and
268
- this = reply
260
+ exists ( DataFlow:: MethodCallNode call |
261
+ this .ref ( ) = call and
262
+ call .getMethodName ( ) = "header" and
263
+ call .getNumArgument ( ) = 3
264
+ )
269
265
}
270
266
271
267
override predicate definesHeaderValue ( string headerName , DataFlow:: Node headerValue ) {
@@ -276,7 +272,7 @@ module Spife {
276
272
277
273
override DataFlow:: Node getNameNode ( ) { result = this .getArgument ( 1 ) }
278
274
279
- override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
275
+ override RouteHandler getRouteHandler ( ) { result = this .getRouteHandler ( ) }
280
276
}
281
277
282
278
/**
@@ -297,11 +293,8 @@ module Spife {
297
293
/**
298
294
* Gets a reference to the multiple headers object that is to be set.
299
295
*/
300
- private DataFlow:: SourceNode getAHeaderSource ( ) {
301
- exists ( int i |
302
- this .getArgument ( i ) .getALocalSource ( ) instanceof DataFlow:: ObjectLiteralNode and
303
- result .flowsTo ( this .getArgument ( i ) )
304
- )
296
+ private DataFlow:: ObjectLiteralNode getAHeaderSource ( ) {
297
+ result = this .getAnArgument ( ) .getALocalSource ( )
305
298
}
306
299
307
300
override predicate definesHeaderValue ( string headerName , DataFlow:: Node headerValue ) {
@@ -312,9 +305,7 @@ module Spife {
312
305
}
313
306
314
307
override DataFlow:: Node getNameNode ( ) {
315
- exists ( DataFlow:: PropWrite write | this .getAHeaderSource ( ) .getAPropertyWrite ( ) = write |
316
- result = write .getPropertyNameExpr ( ) .flow ( )
317
- )
308
+ result = this .getAHeaderSource ( ) .getAPropertyWrite ( ) .getPropertyNameExpr ( ) .flow ( )
318
309
}
319
310
320
311
override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
@@ -324,8 +315,7 @@ module Spife {
324
315
* A header produced by a route handler with no explicit declaration of a Content-Type.
325
316
*/
326
317
private class ContentTypeRouteHandlerHeader extends Http:: ImplicitHeaderDefinition ,
327
- DataFlow:: FunctionNode {
328
- ContentTypeRouteHandlerHeader ( ) { this instanceof RouteHandler }
318
+ DataFlow:: FunctionNode instanceof RouteHandler {
329
319
330
320
override predicate defines ( string headerName , string headerValue ) {
331
321
headerName = "content-type" and headerValue = "application/json"
@@ -337,20 +327,18 @@ module Spife {
337
327
/**
338
328
* An HTTP cookie defined in a Spife HTTP response.
339
329
*/
340
- private class CookieDefinition extends Http:: CookieDefinition , DataFlow:: MethodCallNode {
341
- ReplySource reply ;
330
+ private class CookieDefinition extends Http:: CookieDefinition , DataFlow:: MethodCallNode instanceof ReplySource {
342
331
343
332
CookieDefinition ( ) {
344
333
// reply.cookie(RESPONSE, 'TEST', 'FOO', {"maxAge": 1000, "httpOnly": true, "secure": true})
345
- this = reply .ref ( ) .( DataFlow:: MethodCallNode ) and
346
- this .getMethodName ( ) = "cookie"
334
+ this .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "cookie"
347
335
}
348
336
349
337
override DataFlow:: Node getNameArgument ( ) { result = this .getArgument ( 1 ) }
350
338
351
339
override DataFlow:: Node getValueArgument ( ) { result = this .getArgument ( 2 ) }
352
340
353
- override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
341
+ override RouteHandler getRouteHandler ( ) { result = this .getRouteHandler ( ) }
354
342
}
355
343
356
344
/**
@@ -360,14 +348,15 @@ module Spife {
360
348
RouteHandler rh ;
361
349
362
350
ReplyArgument ( ) {
363
- exists ( ReplySource reply |
364
- reply .ref ( ) .( DataFlow:: CallNode ) .getCalleeName ( ) =
351
+ exists ( ReplySource reply , DataFlow:: CallNode call |
352
+ reply .ref ( ) = call and
353
+ call .getCalleeName ( ) =
365
354
[ "reply" , "cookie" , "link" , "header" , "headers" , "raw" , "status" , "toStream" , "vary" ] and
366
- this = reply . ref ( ) . ( DataFlow :: CallNode ) .getArgument ( 0 ) and
355
+ this = call .getArgument ( 0 ) and
367
356
rh = reply .getRouteHandler ( )
368
357
)
369
358
or
370
- this = rh .( DataFlow :: FunctionNode ) . getAReturn ( )
359
+ this = rh .getAReturn ( )
371
360
}
372
361
373
362
override RouteHandler getRouteHandler ( ) { result = rh }
@@ -394,8 +383,11 @@ module Spife {
394
383
ReplySource reply ;
395
384
396
385
TemplateObjectInput ( ) {
397
- reply .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "template" and
398
- this = reply .ref ( ) .( DataFlow:: MethodCallNode ) .getArgument ( 1 )
386
+ exists ( DataFlow:: MethodCallNode call |
387
+ reply .ref ( ) = call and
388
+ call .getMethodName ( ) = "template" and
389
+ this = call .getArgument ( 1 )
390
+ )
399
391
}
400
392
401
393
/**
@@ -407,28 +399,23 @@ module Spife {
407
399
/**
408
400
* An invocation of the `redirect` method of an HTTP response object.
409
401
*/
410
- private class RedirectInvocation extends Http:: RedirectInvocation , DataFlow:: MethodCallNode {
411
- ReplySource reply ;
402
+ private class RedirectInvocation extends Http:: RedirectInvocation , DataFlow:: MethodCallNode instanceof ReplySource {
412
403
413
404
RedirectInvocation ( ) {
414
- this = reply .ref ( ) .( DataFlow:: MethodCallNode ) and
415
- this .getMethodName ( ) = "redirect"
405
+ this .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "redirect"
416
406
}
417
407
418
408
override DataFlow:: Node getUrlArgument ( ) { result = this .getAnArgument ( ) }
419
409
420
- override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
410
+ override RouteHandler getRouteHandler ( ) { result = this .getRouteHandler ( ) }
421
411
}
422
412
423
413
/**
424
414
* A call to `reply.template('template', { ... })`, seen as a template instantiation.
425
415
*/
426
- private class TemplateCall extends Templating:: TemplateInstantiation:: Range , DataFlow:: CallNode {
416
+ private class TemplateCall extends Templating:: TemplateInstantiation:: Range , DataFlow:: MethodCallNode instanceof ReplySource {
427
417
TemplateCall ( ) {
428
- exists ( ReplySource reply |
429
- reply .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "template" and
430
- this = reply .ref ( )
431
- )
418
+ this .getMethodName ( ) = "template"
432
419
}
433
420
434
421
override DataFlow:: SourceNode getOutput ( ) { result = this }
0 commit comments