Skip to content

Commit 4ba3190

Browse files
author
Alvaro Muñoz
committed
Replace API::Node with DataFlow::Node for Spife's RouteSetup
1 parent 469d7f5 commit 4ba3190

File tree

1 file changed

+16
-6
lines changed
  • javascript/ql/lib/semmle/javascript/frameworks

1 file changed

+16
-6
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Spife.qll

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Spife {
1212
/**
1313
* A call to a Spife method that sets up a route.
1414
*/
15-
private class RouteSetup extends API::CallNode, Http::Servers::StandardRouteSetup {
15+
private class RouteSetup extends DataFlow::CallNode, Http::Servers::StandardRouteSetup {
1616
TaggedTemplateExpr template;
1717

1818
RouteSetup() {
@@ -44,20 +44,22 @@ module Spife {
4444
)
4545
}
4646

47-
API::Node getHandlerByName(string name) { result = this.getParameter(0).getMember(name) }
47+
DataFlow::Node getHandlerByName(string name) {
48+
result = DataFlow::parameterNode(this.getACallee().getParameter(0)).getAPropertyRead(name)
49+
}
4850

49-
API::Node getHandlerByRoute(string method, string path) {
51+
DataFlow::Node getHandlerByRoute(string method, string path) {
5052
exists(string handlerName |
5153
this.hasLine(method, path, handlerName) and
5254
result = this.getHandlerByName(handlerName)
5355
)
5456
}
5557

5658
override DataFlow::SourceNode getARouteHandler() {
57-
result = this.getHandlerByRoute(_, _).getAValueReachingSink().(DataFlow::FunctionNode)
59+
result = this.getHandlerByRoute(_, _).getALocalSource().(DataFlow::FunctionNode)
5860
or
5961
exists(DataFlow::MethodCallNode validation |
60-
validation = this.getHandlerByRoute(_, _).getAValueReachingSink() and
62+
validation = this.getHandlerByRoute(_, _).getALocalSource() and
6163
result = validation.getArgument(1).getAFunctionValue()
6264
)
6365
}
@@ -90,7 +92,7 @@ module Spife {
9092
/**
9193
* A function that looks like a Spife route handler.
9294
*
93-
* For example, this could be the function `function(req, res, next){...}`.
95+
* For example, this could be the function `function(request, context){...}`.
9496
*/
9597
class RouteHandlerCandidate extends Http::RouteHandlerCandidate {
9698
RouteHandlerCandidate() {
@@ -139,22 +141,30 @@ module Spife {
139141
string kind;
140142

141143
RequestInputAccess() {
144+
// req.body
142145
this = rh.getARequestSource().ref().getAPropertyRead("body") and
143146
kind = "body"
144147
or
148+
// req.query['foo']
145149
this = rh.getARequestSource().ref().getAPropertyRead("query").getAPropertyRead() and
146150
kind = "parameter"
147151
or
152+
// req.raw
148153
this = rh.getARequestSource().ref().getAPropertyRead("raw") and
149154
kind = "raw"
150155
or
156+
// req.url
157+
// req.urlObject
151158
this = rh.getARequestSource().ref().getAPropertyRead(["url", "urlObject"]) and
152159
kind = "url"
153160
or
161+
// req.cookie('foo')
162+
// req.cookies()
154163
this = rh.getARequestSource().ref().getAMethodCall() and
155164
this.(DataFlow::MethodCallNode).getMethodName() = ["cookie", "cookies"] and
156165
kind = "cookie"
157166
or
167+
// req.validatedBody.get('foo')
158168
exists(DataFlow::PropRead validated, DataFlow::MethodCallNode get |
159169
rh.getARequestSource().ref().getAPropertyRead() = validated and
160170
validated.getPropertyName().matches("validated%") and

0 commit comments

Comments
 (0)