-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBottle.qll
More file actions
187 lines (150 loc) · 6.3 KB
/
Bottle.qll
File metadata and controls
187 lines (150 loc) · 6.3 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
179
180
181
182
183
184
185
186
187
/**
* Provides classes modeling security-relevant aspects of the `bottle` PyPI package.
* See https://bottlepy.org/docs/dev/.
*/
private import python
private import semmle.python.Concepts
private import semmle.python.ApiGraphs
private import semmle.python.dataflow.new.RemoteFlowSources
private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
private import semmle.python.frameworks.Stdlib
/**
* INTERNAL: Do not use.
*
* Provides models for the `bottle` PyPI package.
* See https://bottlepy.org/docs/dev/.
*/
module Bottle {
/** Gets a reference to the `bottle` module. */
API::Node bottle() { result = API::moduleImport("bottle") }
/** Provides models for the `bottle` module. */
module BottleModule {
/**
* Provides models for Bottle applications.
*/
module App {
/** Gets a reference to a Bottle application (an instance of `bottle.Bottle`) */
API::Node app() { result = bottle().getMember(["Bottle", "app"]).getReturn() }
}
/** Provides models for functions that are possible "views" */
module View {
/**
* A Bottle view callable, that handles incoming requests.
*/
class ViewCallable extends Function {
ViewCallable() { this = any(BottleRouteSetup rs).getARequestHandler() }
}
/** Get methods that represent a route in Bottle */
string routeMethods() { result = ["route", "get", "post", "put", "delete", "patch"] }
private class BottleRouteSetup extends Http::Server::RouteSetup::Range, DataFlow::CallCfgNode {
BottleRouteSetup() {
this =
[
App::app().getMember(routeMethods()).getACall(),
bottle().getMember(routeMethods()).getACall()
]
}
override DataFlow::Node getUrlPatternArg() {
result in [this.getArg(0), this.getArgByName("route")]
}
override string getFramework() { result = "Bottle" }
override Parameter getARoutedParameter() { none() }
override Function getARequestHandler() { result.getADecorator().getAFlowNode() = node }
}
}
/** Provides models for the `bottle.response` module */
module Response {
/** Gets a reference to the `bottle.response` module or instantiation of Bottle Response class. */
API::Node response() {
result = [bottle().getMember("response"), bottle().getMember("Response").getReturn()]
}
/** A response returned by a view callable. */
class BottleReturnResponse extends Http::Server::HttpResponse::Range {
BottleReturnResponse() {
this.asCfgNode() = any(View::ViewCallable vc).getAReturnValueFlowNode()
}
override DataFlow::Node getBody() { result = this }
override DataFlow::Node getMimetypeOrContentTypeArg() { none() }
override string getMimetypeDefault() { result = "text/html" }
}
/**
* A call to the `bottle.BaseResponse.set_header` or `bottle.BaseResponse.add_header` method.
*
* See https://bottlepy.org/docs/dev/api.html#bottle.BaseResponse.set_header
*/
class BottleResponseHandlerSetHeaderCall extends Http::Server::ResponseHeaderWrite::Range,
DataFlow::MethodCallNode
{
BottleResponseHandlerSetHeaderCall() {
this = response().getMember(["set_header", "add_header"]).getACall()
}
override DataFlow::Node getNameArg() {
result in [this.getArg(0), this.getArgByName("name")]
}
override DataFlow::Node getValueArg() {
result in [this.getArg(1), this.getArgByName("value")]
}
override predicate nameAllowsNewline() { none() }
override predicate valueAllowsNewline() { none() }
}
}
/** Provides models for the `bottle.request` module */
module Request {
/** Gets a reference to the `bottle.request` module. */
API::Node request() { result = bottle().getMember("request") }
private class Request extends RemoteFlowSource::Range {
Request() { this = request().asSource() }
override string getSourceType() { result = "bottle.request" }
}
/**
* Taint propagation for `bottle.request`.
*
* See https://bottlepy.org/docs/dev/api.html#bottle.request
*/
private class InstanceTaintSteps extends InstanceTaintStepsHelper {
InstanceTaintSteps() { this = "bottle.request" }
override DataFlow::Node getInstance() { result = request().getAValueReachableFromSource() }
override string getAttributeName() {
result in [
"headers", "query", "forms", "params", "json", "url", "body", "fullpath",
"query_string"
]
}
override string getMethodName() { none() }
override string getAsyncMethodName() { none() }
}
}
/** Provides models for the `bottle.headers` module */
module Headers {
/** Gets a reference to the `bottle.headers` module. */
API::Node headers() { result = bottle().getMember("response").getMember("headers") }
/** A dict-like write to a response header. */
class HeaderWriteSubscript extends Http::Server::ResponseHeaderWrite::Range, DataFlow::Node {
DataFlow::Node name;
DataFlow::Node value;
HeaderWriteSubscript() {
exists(SubscriptNode subscript |
this.asCfgNode() = subscript and
value.asCfgNode() = subscript.(DefinitionNode).getValue() and
name.asCfgNode() = subscript.getIndex() and
subscript.getObject() = headers().asSource().asCfgNode()
)
}
override DataFlow::Node getNameArg() { result = name }
override DataFlow::Node getValueArg() { result = value }
override predicate nameAllowsNewline() { none() }
override predicate valueAllowsNewline() { none() }
}
}
/** Provides models for functions that construct templates. */
module Templates {
/** A call to `bottle.template`or `bottle.SimpleTemplate`. */
private class BottleTemplateConstruction extends TemplateConstruction::Range, API::CallNode {
BottleTemplateConstruction() {
this = API::moduleImport("bottle").getMember(["template", "SimpleTemplate"]).getACall()
}
override DataFlow::Node getSourceArg() { result = this.getArg(0) }
}
}
}
}