@@ -25,13 +25,10 @@ module Spife {
2525 TaggedTemplateExpr template ;
2626
2727 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 ( ) )
3532 }
3633
3734 private string getRoutePattern ( ) {
@@ -184,13 +181,13 @@ module Spife {
184181 /**
185182 * An access to a user-controlled Spife context input.
186183 */
187- private class ContextInputAccess extends Http:: RequestInputAccess {
184+ private class ContextInputAccess extends Http:: RequestInputAccess instanceof DataFlow :: MethodCallNode {
188185 ContextSource request ;
189186 string kind ;
190187
191188 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
194191 kind = "path"
195192 }
196193
@@ -202,7 +199,7 @@ module Spife {
202199 /**
203200 * An access to a header on a Spife request.
204201 */
205- private class RequestHeaderAccess extends Http:: RequestHeaderAccess {
202+ private class RequestHeaderAccess extends Http:: RequestHeaderAccess instanceof DataFlow :: PropRead {
206203 RouteHandler rh ;
207204
208205 RequestHeaderAccess ( ) {
@@ -211,7 +208,7 @@ module Spife {
211208 }
212209
213210 override string getAHeaderName ( ) {
214- result = this . ( DataFlow :: PropRead ) .getPropertyName ( ) .toLowerCase ( )
211+ result = super .getPropertyName ( ) .toLowerCase ( )
215212 }
216213
217214 override RouteHandler getRouteHandler ( ) { result = rh }
@@ -223,7 +220,7 @@ module Spife {
223220 * A Spife response source, that is, the response variable used by a
224221 * route handler.
225222 */
226- private class ReplySource extends Http:: Servers:: ResponseSource {
223+ private class ReplySource extends Http:: Servers:: ResponseSource instanceof DataFlow :: CallNode {
227224 ReplySource ( ) {
228225 // const reply = require("@npm/spife/reply")
229226 // reply(resp)
@@ -232,14 +229,12 @@ module Spife {
232229 this = API:: moduleImport ( [ "@npm/spife/reply" , "spife/reply" ] ) .getAMember ( ) .getACall ( )
233230 }
234231
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
239234 t .start ( )
240235 or
241236 exists ( DataFlow:: TypeTracker t2 |
242- result = this .reachesHandlerReturn ( headerCall , t2 ) .track ( t2 , t )
237+ result = this .reachesHandlerReturn ( t2 ) .track ( t2 , t )
243238 )
244239 }
245240
@@ -249,7 +244,7 @@ module Spife {
249244 override RouteHandler getRouteHandler ( ) {
250245 exists ( RouteHandler handler |
251246 handler .( DataFlow:: FunctionNode ) .getAReturn ( ) .getALocalSource ( ) =
252- this .reachesHandlerReturn ( this , DataFlow:: TypeTracker:: end ( ) ) and
247+ this .reachesHandlerReturn ( DataFlow:: TypeTracker:: end ( ) ) and
253248 result = handler
254249 )
255250 }
@@ -258,14 +253,15 @@ module Spife {
258253 /**
259254 * An HTTP header defined in a Spife response.
260255 */
261- private class HeaderDefinition extends Http:: ExplicitHeaderDefinition , DataFlow:: MethodCallNode {
262- ReplySource reply ;
256+ private class HeaderDefinition extends Http:: ExplicitHeaderDefinition , DataFlow:: MethodCallNode instanceof ReplySource {
263257
264258 HeaderDefinition ( ) {
265259 // 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+ )
269265 }
270266
271267 override predicate definesHeaderValue ( string headerName , DataFlow:: Node headerValue ) {
@@ -276,7 +272,7 @@ module Spife {
276272
277273 override DataFlow:: Node getNameNode ( ) { result = this .getArgument ( 1 ) }
278274
279- override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
275+ override RouteHandler getRouteHandler ( ) { result = this .getRouteHandler ( ) }
280276 }
281277
282278 /**
@@ -297,11 +293,8 @@ module Spife {
297293 /**
298294 * Gets a reference to the multiple headers object that is to be set.
299295 */
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 ( )
305298 }
306299
307300 override predicate definesHeaderValue ( string headerName , DataFlow:: Node headerValue ) {
@@ -312,9 +305,7 @@ module Spife {
312305 }
313306
314307 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 ( )
318309 }
319310
320311 override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
@@ -324,8 +315,7 @@ module Spife {
324315 * A header produced by a route handler with no explicit declaration of a Content-Type.
325316 */
326317 private class ContentTypeRouteHandlerHeader extends Http:: ImplicitHeaderDefinition ,
327- DataFlow:: FunctionNode {
328- ContentTypeRouteHandlerHeader ( ) { this instanceof RouteHandler }
318+ DataFlow:: FunctionNode instanceof RouteHandler {
329319
330320 override predicate defines ( string headerName , string headerValue ) {
331321 headerName = "content-type" and headerValue = "application/json"
@@ -337,20 +327,18 @@ module Spife {
337327 /**
338328 * An HTTP cookie defined in a Spife HTTP response.
339329 */
340- private class CookieDefinition extends Http:: CookieDefinition , DataFlow:: MethodCallNode {
341- ReplySource reply ;
330+ private class CookieDefinition extends Http:: CookieDefinition , DataFlow:: MethodCallNode instanceof ReplySource {
342331
343332 CookieDefinition ( ) {
344333 // 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"
347335 }
348336
349337 override DataFlow:: Node getNameArgument ( ) { result = this .getArgument ( 1 ) }
350338
351339 override DataFlow:: Node getValueArgument ( ) { result = this .getArgument ( 2 ) }
352340
353- override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
341+ override RouteHandler getRouteHandler ( ) { result = this .getRouteHandler ( ) }
354342 }
355343
356344 /**
@@ -360,14 +348,15 @@ module Spife {
360348 RouteHandler rh ;
361349
362350 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 ( ) =
365354 [ "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
367356 rh = reply .getRouteHandler ( )
368357 )
369358 or
370- this = rh .( DataFlow :: FunctionNode ) . getAReturn ( )
359+ this = rh .getAReturn ( )
371360 }
372361
373362 override RouteHandler getRouteHandler ( ) { result = rh }
@@ -394,8 +383,11 @@ module Spife {
394383 ReplySource reply ;
395384
396385 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+ )
399391 }
400392
401393 /**
@@ -407,28 +399,23 @@ module Spife {
407399 /**
408400 * An invocation of the `redirect` method of an HTTP response object.
409401 */
410- private class RedirectInvocation extends Http:: RedirectInvocation , DataFlow:: MethodCallNode {
411- ReplySource reply ;
402+ private class RedirectInvocation extends Http:: RedirectInvocation , DataFlow:: MethodCallNode instanceof ReplySource {
412403
413404 RedirectInvocation ( ) {
414- this = reply .ref ( ) .( DataFlow:: MethodCallNode ) and
415- this .getMethodName ( ) = "redirect"
405+ this .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "redirect"
416406 }
417407
418408 override DataFlow:: Node getUrlArgument ( ) { result = this .getAnArgument ( ) }
419409
420- override RouteHandler getRouteHandler ( ) { result = reply .getRouteHandler ( ) }
410+ override RouteHandler getRouteHandler ( ) { result = this .getRouteHandler ( ) }
421411 }
422412
423413 /**
424414 * A call to `reply.template('template', { ... })`, seen as a template instantiation.
425415 */
426- private class TemplateCall extends Templating:: TemplateInstantiation:: Range , DataFlow:: CallNode {
416+ private class TemplateCall extends Templating:: TemplateInstantiation:: Range , DataFlow:: MethodCallNode instanceof ReplySource {
427417 TemplateCall ( ) {
428- exists ( ReplySource reply |
429- reply .ref ( ) .( DataFlow:: MethodCallNode ) .getMethodName ( ) = "template" and
430- this = reply .ref ( )
431- )
418+ this .getMethodName ( ) = "template"
432419 }
433420
434421 override DataFlow:: SourceNode getOutput ( ) { result = this }
0 commit comments