-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy path05_ResponseSendArgumentWithAliasing.ql
More file actions
68 lines (58 loc) · 2.16 KB
/
05_ResponseSendArgumentWithAliasing.ql
File metadata and controls
68 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import javascript
/** Gets a data flow node that represents an instance of `swagger-node`. */
DataFlow::Node swaggerInstance() {
result = DataFlow::moduleImport("swagger-node-express")
or
result.getAPredecessor() = swaggerInstance()
or
result.(DataFlow::CallNode).getACallee().getAReturnedExpr() = swaggerInstance().asExpr()
or
result.(DataFlow::MethodCallNode).calls(swaggerInstance(), "createNew")
}
/** An Express route handler installed via `swagger-node`. */
class SwaggerRouteHandler extends Express::RouteHandler, DataFlow::FunctionNode {
SwaggerRouteHandler() {
exists(DataFlow::MethodCallNode addGet, DataFlow::ObjectLiteralNode resource |
addGet.calls(swaggerInstance(), "addGet") and
resource = addGet.getArgument(0).getALocalSource() and
this = resource.getAPropertySource("action")
)
}
override SimpleParameter getRouteHandlerParameter(string kind) {
kind = "request" and result = getParameter(0).getParameter()
or
kind = "response" and result = getParameter(1).getParameter()
}
override HTTP::HeaderDefinition getAResponseHeader(string name) { none() }
}
/** Holds if `name` may be an alias for the `send` method on `res`. */
predicate sendMethodName(HTTP::Servers::ResponseSource res, string name) {
name = "send"
or
exists (DataFlow::PropWrite pw |
res.flowsTo(pw.getBase()) and
pw.getPropertyName() = name and
sendMethodRef(pw.getRhs(), res)
)
}
/** Holds if `pr` may be an access to the `send` method on `res`. */
predicate sendMethodRef(DataFlow::PropRead pr, HTTP::Servers::ResponseSource res) {
res.flowsTo(pr.getBase()) and
sendMethodName(res, pr.getPropertyName())
}
/** Recognize potentially aliased calls to `send`. */
class PotentiallyAliasedResponseSendArgument extends HTTP::ResponseSendArgument {
HTTP::RouteHandler rh;
PotentiallyAliasedResponseSendArgument() {
exists (DataFlow::CallNode call, HTTP::Servers::ResponseSource res |
sendMethodRef(call.getCalleeNode(), res) and
rh = res.getRouteHandler() and
this = call.getArgument(0).asExpr()
)
}
override HTTP::RouteHandler getRouteHandler() {
result = rh
}
}
from PotentiallyAliasedResponseSendArgument arg
select arg