Skip to content

Commit 8aa4d82

Browse files
committed
JS: Rename RouteHandlerInput->RouteHandlerParameter
1 parent 218b746 commit 8aa4d82

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ module Routing {
285285
}
286286

287287
/**
288-
* Gets a node whose value can be accessed via the given access path on `n`th route handler input,
288+
* Gets a node whose value can be accessed via the given access path on the `n`th route handler parameter,
289289
* from any route handler that follows after this one.
290290
*
291291
* For example, in the context of Express, the `app` object is available as `req.app`:
@@ -774,20 +774,16 @@ module Routing {
774774
/**
775775
* Gets the `i`th parameter of this route handler.
776776
*
777-
* This is equivalent to `getParameter(i)` but returns a `RouteHandlerInput`.
778-
*
779-
* To find all references to this parameter, use `getInput(n).ref()`.
777+
* To find all references to this parameter, use `getParameter(n).ref()`.
780778
*/
781-
final RouteHandlerInput getInput(int n) { result = function.getParameter(n) }
779+
final RouteHandlerParameter getParameter(int n) { result = function.getParameter(n) }
782780

783781
/**
784782
* Gets a parameter of this route handler.
785783
*
786-
* This is equivalent to `getAParameter()` but returns a `RouteHandlerInput`.
787-
*
788-
* To find all references to a parameter, use `getAnInput().ref()`.
784+
* To find all references to a parameter, use `getAParameter().ref()`.
789785
*/
790-
final RouteHandlerInput getAnInput() { result = function.getAParameter() }
786+
final RouteHandlerParameter getAParameter() { result = function.getAParameter() }
791787

792788
/** Gets the function implementing this route handler. */
793789
DataFlow::FunctionNode getFunction() { result = function }
@@ -802,11 +798,11 @@ module Routing {
802798
* if the default behavior is inadequate for that framework.
803799
*/
804800
DataFlow::CallNode getAContinuationInvocation() {
805-
result = getAnInput().ref().getAnInvocation() and
801+
result = getAParameter().ref().getAnInvocation() and
806802
result.getNumArgument() = 0
807803
or
808804
result.(DataFlow::MethodCallNode).getMethodName() = "then" and
809-
result.getArgument(0) = getAnInput().ref().getALocalUse()
805+
result.getArgument(0) = getAParameter().ref().getALocalUse()
810806
}
811807
}
812808

@@ -820,18 +816,18 @@ module Routing {
820816
/**
821817
* A parameter to a route handler function.
822818
*/
823-
class RouteHandlerInput extends DataFlow::ParameterNode {
824-
RouteHandlerInput() { this = any(RouteHandler h).getFunction().getAParameter() }
819+
class RouteHandlerParameter extends DataFlow::ParameterNode {
820+
RouteHandlerParameter() { this = any(RouteHandler h).getFunction().getAParameter() }
825821

826-
/** Gets a data flow node referring to this route handler input. */
822+
/** Gets a data flow node referring to this route handler parameter. */
827823
private DataFlow::SourceNode ref(DataFlow::TypeTracker t) {
828824
t.start() and
829825
result = this
830826
or
831827
exists(DataFlow::TypeTracker t2 | result = ref(t2).track(t2, t))
832828
}
833829

834-
/** Gets a data flow node referring to this route handler input. */
830+
/** Gets a data flow node referring to this route handler parameter. */
835831
DataFlow::SourceNode ref() { result = ref(DataFlow::TypeTracker::end()) }
836832

837833
/**
@@ -840,7 +836,7 @@ module Routing {
840836
final RouteHandler getRouteHandler() { result.getFunction().getAParameter() = this }
841837

842838
/**
843-
* Gets a node that is stored in the given access path on this route handler input, either
839+
* Gets a node that is stored in the given access path on this route handler parameter, either
844840
* during execution of this router handler, or in one of the preceding ones.
845841
*/
846842
pragma[inline]
@@ -854,7 +850,7 @@ module Routing {
854850
}
855851

856852
/**
857-
* Gets a value that flows into the given access path of the `n`th route handler input at `base`.
853+
* Gets a value that flows into the given access path of the `n`th route handler parameter of `base`.
858854
*
859855
* For example,
860856
* ```js
@@ -874,7 +870,7 @@ module Routing {
874870
private DataFlow::Node getAnAccessPathRhs(Node base, int n, string path) {
875871
// Assigned in the body of a route handler function, whi
876872
exists(RouteHandler handler | base = handler |
877-
result = AccessPath::getAnAssignmentTo(handler.getInput(n).ref(), path) and
873+
result = AccessPath::getAnAssignmentTo(handler.getParameter(n).ref(), path) and
878874
exists(handler.getAContinuationInvocation())
879875
)
880876
or
@@ -890,7 +886,7 @@ module Routing {
890886
}
891887

892888
/**
893-
* Gets a value that refers to the given access path of the `n`th route handler input at `base`
889+
* Gets a value that refers to the given access path of the `n`th route handler parameter of `base`.
894890
*
895891
* For example,
896892
* ```js
@@ -902,7 +898,7 @@ module Routing {
902898
* of `handler2`.
903899
*/
904900
private DataFlow::SourceNode getAnAccessPathRead(RouteHandler base, int n, string path) {
905-
result = AccessPath::getAReferenceTo(base.getInput(n).ref(), path) and
901+
result = AccessPath::getAReferenceTo(base.getParameter(n).ref(), path) and
906902
not AccessPath::DominatingPaths::hasDominatingWrite(result)
907903
}
908904

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ module Express {
10381038
override DataFlow::Node getTemplateParamsNode() { result = this.getArgument(1) }
10391039

10401040
override DataFlow::Node getTemplateParamForValue(string accessPath) {
1041-
result = res.(Routing::RouteHandlerInput).getValueFromAccessPath("locals." + accessPath)
1041+
result = res.(Routing::RouteHandlerParameter).getValueFromAccessPath("locals." + accessPath)
10421042
}
10431043

10441044
override DataFlow::SourceNode getOutput() { result = this.getCallback(2).getParameter(1) }

javascript/ql/src/Security/CWE-352/MissingCsrfMiddleware.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ string cookieProperty() { result = "session" or result = "cookies" or result = "
2121
*/
2222
predicate isRouteHandlerUsingCookies(Routing::RouteHandler handler) {
2323
exists(DataFlow::PropRef value |
24-
value = handler.getAnInput().ref().getAPropertyRead(cookieProperty()).getAPropertyReference() and
24+
value = handler.getAParameter().ref().getAPropertyRead(cookieProperty()).getAPropertyReference() and
2525
// Ignore accesses to values that are part of a CSRF or captcha check
2626
not value.getPropertyName().regexpMatch("(?i).*(csrf|xsrf|captcha).*") and
2727
// Ignore calls like `req.session.save()`
@@ -124,7 +124,7 @@ private Routing::RouteHandler getAHandlerSettingCsrfCookie() {
124124
* Or by the response parameter setting a CSRF related cookie.
125125
*/
126126
predicate isCsrfProtectionRouteHandler(Routing::RouteHandler handler) {
127-
handler.getAnInput() = nodeLeadingToCsrfWriteOrCheck(DataFlow::TypeBackTracker::end())
127+
handler.getAParameter() = nodeLeadingToCsrfWriteOrCheck(DataFlow::TypeBackTracker::end())
128128
or
129129
handler = getAHandlerSettingCsrfCookie()
130130
}

0 commit comments

Comments
 (0)