-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBeego.qll
More file actions
178 lines (148 loc) · 6.27 KB
/
Beego.qll
File metadata and controls
178 lines (148 loc) · 6.27 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Provides classes for working with remote flow sources, sinks and taint propagators
* from the `github.com/beego/beego` package.
*/
overlay[local?]
module;
import go
import semmle.go.security.Xss
private import semmle.go.security.SafeUrlFlowCustomizations
// Some TaintTracking::FunctionModel subclasses remain because varargs functions don't work with Models-as-Data sumamries yet.
/**
* Provides classes for working with remote flow sources, sinks and taint propagators
* from the [Beego](https://github.com/beego/beego) package.
*/
module Beego {
/** Gets the v1 module path `github.com/astaxie/beego` or `github.com/beego/beego`. */
string v1modulePath() { result = ["github.com/astaxie/beego", "github.com/beego/beego"] }
/** Gets the v2 module path `github.com/beego/beego/v2` */
string v2modulePath() { result = "github.com/beego/beego/v2" }
/** Gets the path for the root package of beego. */
string packagePath() {
result = package(v1modulePath(), "")
or
result = package(v2modulePath(), "server/web")
}
/** Gets the path for the context package of beego. */
string contextPackagePath() {
result = package(v1modulePath(), "context")
or
result = package(v2modulePath(), "server/web/context")
}
/** Gets the path for the utils package of beego. */
string utilsPackagePath() {
result = package(v1modulePath(), "utils")
or
result = package(v2modulePath(), "core/utils")
}
/** `BeegoInput` sources that are safe to use for redirection. */
private class BeegoInputSafeUrlSource extends SafeUrlFlow::Source {
BeegoInputSafeUrlSource() {
exists(Method m | m.hasQualifiedName(contextPackagePath(), "BeegoInput", ["URI", "URL"]) |
this = m.getACall().getResult(0)
)
}
}
private class BeegoOutputInstance extends Http::ResponseWriter::Range {
SsaWithFields v;
BeegoOutputInstance() {
this = v.getBaseVariable().getSourceVariable() and
v.getType().(PointerType).getBaseType().hasQualifiedName(contextPackagePath(), "BeegoOutput")
}
override DataFlow::Node getANode() { result = v.similar().getAUse().getASuccessor*() }
/** Gets a header object that corresponds to this HTTP response. */
DataFlow::MethodCallNode getAHeaderObject() {
result.getTarget().getName() = ["ContentType", "Header"] and
this.getANode() = result.getReceiver()
}
}
private class BeegoHeaderWrite extends Http::HeaderWrite::Range, DataFlow::MethodCallNode {
string methodName;
BeegoHeaderWrite() {
this.getTarget().hasQualifiedName(contextPackagePath(), "BeegoOutput", methodName) and
methodName in ["ContentType", "Header"]
}
override DataFlow::Node getName() { methodName = "Header" and result = this.getArgument(0) }
override string getHeaderName() {
result = Http::HeaderWrite::Range.super.getHeaderName()
or
methodName = "ContentType" and result = "content-type"
}
override DataFlow::Node getValue() {
if methodName = "ContentType"
then result = this.getArgument(0)
else result = this.getArgument(1)
}
override Http::ResponseWriter getResponseWriter() {
result.(BeegoOutputInstance).getAHeaderObject() = this
}
}
private class BeegoResponseBody extends Http::ResponseBody::Range {
DataFlow::MethodCallNode call;
string methodName;
BeegoResponseBody() {
exists(Method m | m.hasQualifiedName(contextPackagePath(), "BeegoOutput", methodName) |
call = m.getACall() and
this = call.getArgument(0)
) and
methodName in ["Body", "JSON", "JSONP", "ServeFormatted", "XML", "YAML"]
}
override Http::ResponseWriter getResponseWriter() { result.getANode() = call.getReceiver() }
override string getAContentType() {
// Super-method provides content-types for `Body`, which requires us to search
// for `ContentType` and `Header` calls against the same `BeegoOutput` instance
result = super.getAContentType()
or
// Specifically describe methods that set the content-type and body in one operation:
result = "application/json" and methodName = "JSON"
or
result = "application/javascript" and methodName = "JSONP"
or
// Actually ServeFormatted can serve JSON, XML or YAML depending on the incoming
// `Accept` header, but the important bit is this method cannot serve text/html.
result = "application/json" and methodName = "ServeFormatted"
or
result = "text/xml" and methodName = "XML"
or
result = "application/x-yaml" and methodName = "YAML"
}
}
private class ControllerResponseBody extends Http::ResponseBody::Range {
string name;
ControllerResponseBody() {
exists(Method m | m.hasQualifiedName(packagePath(), "Controller", name) |
name = "CustomAbort" and this = m.getACall().getArgument(1)
or
name = "SetData" and this = m.getACall().getArgument(0)
)
}
override Http::ResponseWriter getResponseWriter() { none() }
override string getAContentType() {
// Actually SetData can serve JSON, XML or YAML depending on the incoming
// `Accept` header, but the important bit is this method cannot serve text/html.
result = "application/json" and name = "SetData"
// CustomAbort doesn't specify a content type, so we assume anything could happen.
}
}
private class ContextResponseBody extends Http::ResponseBody::Range {
ContextResponseBody() {
exists(Method m, string name | m.hasQualifiedName(contextPackagePath(), "Context", name) |
name = "Abort" and this = m.getACall().getArgument(1)
or
name = "WriteString" and this = m.getACall().getArgument(0)
)
}
override Http::ResponseWriter getResponseWriter() { none() }
// Neither method is likely to be used with well-typed data such as JSON output,
// because there are better methods to do this. Assume the Content-Type could
// be anything.
override string getAContentType() { none() }
}
private class UtilsTaintPropagators extends TaintTracking::FunctionModel {
UtilsTaintPropagators() { this.hasQualifiedName(utilsPackagePath(), "GetDisplayString") }
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
input.isParameter(_) and
output.isResult(0)
}
}
}