JS: Use type info to recognize routers

This commit is contained in:
Asger F
2019-09-03 17:36:54 +01:00
parent c06fd451d6
commit 744f0b1aa3

View File

@@ -39,16 +39,23 @@ module Express {
router.flowsTo(e)
}
/**
* Holds if `e` may refer to a router object.
*/
private predicate isRouter(Expr e) {
isRouter(e, _)
or
e.getType().hasUnderlyingType("express-serve-static-core", "Router")
}
/**
* An expression that refers to a route.
*/
class RouteExpr extends MethodCallExpr {
RouterDefinition router;
RouteExpr() { isRouter(this) }
RouteExpr() { isRouter(this, router) }
/** Gets the router from which this route was created. */
RouterDefinition getRouter() { result = router }
/** Gets the router from which this route was created, if it is known. */
RouterDefinition getRouter() { isRouter(this, result) }
}
/**
@@ -68,10 +75,8 @@ module Express {
* A call to an Express router method that sets up a route.
*/
class RouteSetup extends HTTP::Servers::StandardRouteSetup, MethodCallExpr {
RouterDefinition router;
RouteSetup() {
isRouter(getReceiver(), router) and
isRouter(getReceiver()) and
getMethodName() = routeSetupMethodName()
}
@@ -79,7 +84,7 @@ module Express {
string getPath() { getArgument(0).mayHaveStringValue(result) }
/** Gets the router on which handlers are being registered. */
RouterDefinition getRouter() { result = router }
RouterDefinition getRouter() { isRouter(getReceiver(), result) }
/** Holds if this is a call `use`, such as `app.use(handler)`. */
predicate isUseCall() { getMethodName() = "use" }