@@ -9,23 +9,32 @@ import semmle.javascript.frameworks.HTTP
9
9
* Provides classes for working with [Spife](https://github.com/npm/spife) applications.
10
10
*/
11
11
module Spife {
12
+ private class TaggedTemplateEntryPoint extends API:: EntryPoint {
13
+ TaggedTemplateEntryPoint ( ) { this = "TaggedTemplateEntryPoint" }
14
+
15
+ override DataFlow:: SourceNode getASource ( ) { result .asExpr ( ) instanceof TaggedTemplateExpr }
16
+ }
17
+
12
18
/**
13
19
* A call to a Spife method that sets up a route.
14
20
*/
15
- private class RouteSetup extends DataFlow :: CallNode , Http:: Servers:: StandardRouteSetup {
21
+ private class RouteSetup extends API :: CallNode , Http:: Servers:: StandardRouteSetup {
16
22
TaggedTemplateExpr template ;
17
23
18
24
RouteSetup ( ) {
19
- this .getCalleeNode ( ) .asExpr ( ) = template and
20
- API:: moduleImport ( [ "@npm/spife/routing" , "spife/routing" ] )
21
- .asSource ( )
22
- .flowsToExpr ( template .getTag ( ) )
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
+ )
23
32
}
24
33
25
34
private string getRoutePattern ( ) {
26
35
// Concatenate the constant parts of the expression
27
36
result =
28
- strictconcat ( Expr e , int i |
37
+ concat ( Expr e , int i |
29
38
e = template .getTemplate ( ) .getElement ( i ) and exists ( e .getStringValue ( ) )
30
39
|
31
40
e .getStringValue ( ) order by i
@@ -44,22 +53,20 @@ module Spife {
44
53
)
45
54
}
46
55
47
- DataFlow:: Node getHandlerByName ( string name ) {
48
- result = DataFlow:: parameterNode ( this .getACallee ( ) .getParameter ( 0 ) ) .getAPropertyRead ( name )
49
- }
56
+ API:: Node getHandlerByName ( string name ) { result = this .getParameter ( 0 ) .getMember ( name ) }
50
57
51
- DataFlow :: Node getHandlerByRoute ( string method , string path ) {
58
+ API :: Node getHandlerByRoute ( string method , string path ) {
52
59
exists ( string handlerName |
53
60
this .hasLine ( method , path , handlerName ) and
54
61
result = this .getHandlerByName ( handlerName )
55
62
)
56
63
}
57
64
58
65
override DataFlow:: SourceNode getARouteHandler ( ) {
59
- result = this .getHandlerByRoute ( _, _) .getALocalSource ( ) .( DataFlow:: FunctionNode )
66
+ result = this .getHandlerByRoute ( _, _) .getAValueReachingSink ( ) .( DataFlow:: FunctionNode )
60
67
or
61
68
exists ( DataFlow:: MethodCallNode validation |
62
- validation = this .getHandlerByRoute ( _, _) .getALocalSource ( ) and
69
+ validation = this .getHandlerByRoute ( _, _) .getAValueReachingSink ( ) and
63
70
result = validation .getArgument ( 1 ) .getAFunctionValue ( )
64
71
)
65
72
}
0 commit comments