44
55import javascript
66import semmle.javascript.frameworks.HTTP
7+ private import DataFlow
78
89/**
910 * Provides classes for working with [Spife](https://github.com/npm/spife) applications.
1011 */
1112module Spife {
12- private class TaggedTemplateEntryPoint extends API:: EntryPoint {
13- TaggedTemplateEntryPoint ( ) { this = "TaggedTemplateEntryPoint" }
14-
15- override DataFlow:: SourceNode getASource ( ) { result .asExpr ( ) instanceof TaggedTemplateExpr }
16- }
17-
1813 /**
1914 * A call to a Spife method that sets up a route.
2015 */
21- private class RouteSetup extends API :: CallNode , Http:: Servers:: StandardRouteSetup {
16+ private class RouteSetup extends DataFlow :: CallNode , Http:: Servers:: StandardRouteSetup {
2217 TaggedTemplateExpr template ;
2318
2419 RouteSetup ( ) {
25- exists ( CallExpr templateCall |
26- this .getCalleeNode ( ) .asExpr ( ) = template and
27- API:: moduleImport ( [ "@npm/spife/routing" , "spife/routing" ] )
28- .asSource ( )
29- .flowsToExpr ( template .getTag ( ) ) and
30- templateCall .getAChild ( ) = template
31- )
20+ this .getCalleeNode ( ) .asExpr ( ) = template and
21+ API:: moduleImport ( [ "@npm/spife/routing" , "spife/routing" ] )
22+ .asSource ( )
23+ .flowsToExpr ( template .getTag ( ) )
3224 }
3325
3426 private string getRoutePattern ( ) {
3527 // Concatenate the constant parts of the expression
3628 result =
37- concat ( Expr e , int i |
29+ strictconcat ( Expr e , int i |
3830 e = template .getTemplate ( ) .getElement ( i ) and exists ( e .getStringValue ( ) )
3931 |
4032 e .getStringValue ( ) order by i
@@ -53,20 +45,33 @@ module Spife {
5345 )
5446 }
5547
56- API:: Node getHandlerByName ( string name ) { result = this .getParameter ( 0 ) .getMember ( name ) }
48+ DataFlow:: SourceNode getHandlerDefinitions ( TypeBackTracker t ) {
49+ t .start ( ) and
50+ result = this .getArgument ( 0 ) .getALocalSource ( )
51+ or
52+ exists ( TypeBackTracker t2 | result = getHandlerDefinitions ( t2 ) .backtrack ( t2 , t ) )
53+ }
54+
55+ DataFlow:: SourceNode getHandlerDefinitions ( ) {
56+ result = getHandlerDefinitions ( TypeBackTracker:: end ( ) )
57+ }
58+
59+ DataFlow:: SourceNode getHandlerByName ( string name ) {
60+ result = getHandlerDefinitions ( ) .getAPropertySource ( name )
61+ }
5762
58- API :: Node getHandlerByRoute ( string method , string path ) {
63+ DataFlow :: SourceNode getHandlerByRoute ( string method , string path ) {
5964 exists ( string handlerName |
6065 this .hasLine ( method , path , handlerName ) and
6166 result = this .getHandlerByName ( handlerName )
6267 )
6368 }
6469
6570 override DataFlow:: SourceNode getARouteHandler ( ) {
66- result = this .getHandlerByRoute ( _, _) .getAValueReachingSink ( ) .( DataFlow:: FunctionNode )
71+ result = this .getHandlerByRoute ( _, _) .getALocalSource ( ) .( DataFlow:: FunctionNode )
6772 or
6873 exists ( DataFlow:: MethodCallNode validation |
69- validation = this .getHandlerByRoute ( _, _) .getAValueReachingSink ( ) and
74+ validation = this .getHandlerByRoute ( _, _) .getALocalSource ( ) and
7075 result = validation .getArgument ( 1 ) .getAFunctionValue ( )
7176 )
7277 }
0 commit comments