Skip to content

Commit 400bf10

Browse files
committed
JS: Move fastify-specific route handler step into extension point
1 parent 7182056 commit 400bf10

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

javascript/ql/lib/semmle/javascript/Routing.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ module Routing {
419419
or
420420
HTTP::routeHandlerStep(result, this)
421421
or
422+
RouteHandlerTrackingStep::step(result, this)
423+
or
422424
exists(string prop |
423425
StepSummary::smallstep(result, getSourceProp(prop).getALocalUse(), StoreStep(prop))
424426
)
@@ -496,6 +498,22 @@ module Routing {
496498
}
497499
}
498500

501+
/**
502+
* An edge that should be used for tracking route handler definitions to their use-sites.
503+
*
504+
* This may be subclassed by framework models to contribute additional steps.
505+
*/
506+
class RouteHandlerTrackingStep extends Unit {
507+
/** Holds if route handlers should be propagated along the edge `pred -> succ`. */
508+
predicate step(DataFlow::Node pred, DataFlow::Node succ) { none() }
509+
}
510+
511+
private module RouteHandlerTrackingStep {
512+
predicate step(DataFlow::Node pred, DataFlow::Node succ) {
513+
any(RouteHandlerTrackingStep s).step(pred, succ)
514+
}
515+
}
516+
499517
/**
500518
* A node in the routing tree which has no parent.
501519
*/

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,14 @@ module Fastify {
404404
)
405405
}
406406
}
407+
408+
private class RouteHandlerTracking extends Routing::RouteHandlerTrackingStep {
409+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
410+
exists(DataFlow::CallNode call |
411+
call = DataFlow::moduleImport("fastify-plugin") and
412+
pred = call.getArgument(0) and
413+
succ = call
414+
)
415+
}
416+
}
407417
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,6 @@ module HTTP {
234234
or
235235
// references to class methods
236236
succ = CallGraph::callgraphStep(pred, DataFlow::TypeTracker::end())
237-
or
238-
exists(DataFlow::CallNode call |
239-
call = DataFlow::moduleImport("fastify-plugin") and
240-
pred = call.getArgument(0) and
241-
succ = call
242-
)
243237
}
244238

245239
/**

0 commit comments

Comments
 (0)