Skip to content

Commit 41f16aa

Browse files
committed
Python: Autoformat (4 spaces) bottle library
1 parent 12c4903 commit 41f16aa

File tree

4 files changed

+31
-103
lines changed

4 files changed

+31
-103
lines changed

python/ql/src/semmle/python/web/bottle/General.qll

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ import semmle.python.web.Http
33
import semmle.python.types.Extensions
44

55
/** The bottle module */
6-
ModuleValue theBottleModule() {
7-
result = Module::named("bottle")
8-
}
6+
ModuleValue theBottleModule() { result = Module::named("bottle") }
97

108
/** The bottle.Bottle class */
11-
ClassValue theBottleClass() {
12-
result = theBottleModule().attr("Bottle")
13-
}
9+
ClassValue theBottleClass() { result = theBottleModule().attr("Bottle") }
1410

15-
/** Holds if `route` is routed to `func`
11+
/**
12+
* Holds if `route` is routed to `func`
1613
* by decorating `func` with `app.route(route)` or `route(route)`
1714
*/
1815
predicate bottle_route(CallNode route_call, ControlFlowNode route, Function func) {
1916
exists(CallNode decorator_call, string name |
2017
route_call.getFunction().(AttrNode).getObject(name).pointsTo().getClass() = theBottleClass() or
2118
route_call.getFunction().pointsTo(theBottleModule().attr(name))
22-
|
19+
|
2320
(name = "route" or name = httpVerbLower()) and
2421
decorator_call.getFunction() = route_call and
2522
route_call.getArg(0) = route and
@@ -28,10 +25,7 @@ predicate bottle_route(CallNode route_call, ControlFlowNode route, Function func
2825
}
2926

3027
class BottleRoute extends ControlFlowNode {
31-
32-
BottleRoute() {
33-
bottle_route(this, _, _)
34-
}
28+
BottleRoute() { bottle_route(this, _, _) }
3529

3630
string getUrl() {
3731
exists(StrConst url |
@@ -40,9 +34,7 @@ class BottleRoute extends ControlFlowNode {
4034
)
4135
}
4236

43-
Function getFunction() {
44-
bottle_route(this, _, result)
45-
}
37+
Function getFunction() { bottle_route(this, _, result) }
4638

4739
Parameter getNamedArgument() {
4840
exists(string name, Function func |
@@ -52,5 +44,3 @@ class BottleRoute extends ControlFlowNode {
5244
)
5345
}
5446
}
55-
56-
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
/** Provides class representing the `bottle.redirect` function.
1+
/**
2+
* Provides class representing the `bottle.redirect` function.
23
* This module is intended to be imported into a taint-tracking query
34
* to extend `TaintSink`.
45
*/
5-
import python
66

7+
import python
78
import semmle.python.security.TaintTracking
89
import semmle.python.security.strings.Basic
910
import semmle.python.web.bottle.General
1011

11-
FunctionValue bottle_redirect() {
12-
result = theBottleModule().attr("redirect")
13-
}
12+
FunctionValue bottle_redirect() { result = theBottleModule().attr("redirect") }
1413

1514
/**
1615
* Represents an argument to the `bottle.redirect` function.
1716
*/
1817
class BottleRedirect extends TaintSink {
19-
20-
override string toString() {
21-
result = "bottle.redirect"
22-
}
18+
override string toString() { result = "bottle.redirect" }
2319

2420
BottleRedirect() {
2521
exists(CallNode call |
@@ -28,8 +24,5 @@ class BottleRedirect extends TaintSink {
2824
)
2925
}
3026

31-
override predicate sinks(TaintKind kind) {
32-
kind instanceof StringKind
33-
}
34-
27+
override predicate sinks(TaintKind kind) { kind instanceof StringKind }
3528
}
Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import python
2-
3-
42
import semmle.python.security.TaintTracking
53
import semmle.python.security.strings.Untrusted
64
import semmle.python.web.Http
75
import semmle.python.web.bottle.General
86

9-
private Value theBottleRequestObject() {
10-
result = theBottleModule().attr("request")
11-
}
7+
private Value theBottleRequestObject() { result = theBottleModule().attr("request") }
128

139
class BottleRequestKind extends TaintKind {
14-
15-
BottleRequestKind() {
16-
this = "bottle.request"
17-
}
10+
BottleRequestKind() { this = "bottle.request" }
1811

1912
override TaintKind getTaintOfAttribute(string name) {
2013
result instanceof BottleFormsDict and
@@ -26,34 +19,23 @@ class BottleRequestKind extends TaintKind {
2619
result.(DictKind).getValue() instanceof FileUpload and
2720
name = "files"
2821
}
29-
3022
}
3123

3224
private class RequestSource extends TaintSource {
25+
RequestSource() { this.(ControlFlowNode).pointsTo(theBottleRequestObject()) }
3326

34-
RequestSource() {
35-
this.(ControlFlowNode).pointsTo(theBottleRequestObject())
36-
}
37-
38-
override predicate isSourceOf(TaintKind kind) {
39-
kind instanceof BottleRequestKind
40-
}
41-
27+
override predicate isSourceOf(TaintKind kind) { kind instanceof BottleRequestKind }
4228
}
4329

44-
4530
class BottleFormsDict extends TaintKind {
46-
47-
BottleFormsDict() {
48-
this = "bottle.FormsDict"
49-
}
31+
BottleFormsDict() { this = "bottle.FormsDict" }
5032

5133
override TaintKind getTaintForFlowStep(ControlFlowNode fromnode, ControlFlowNode tonode) {
5234
/* Cannot use `getTaintOfAttribute(name)` as it wouldn't bind `name` */
5335
exists(string name |
54-
fromnode = tonode.(AttrNode).getObject(name) and
36+
fromnode = tonode.(AttrNode).getObject(name) and
5537
result instanceof UntrustedStringKind
56-
|
38+
|
5739
name != "get" and name != "getunicode" and name != "getall"
5840
)
5941
}
@@ -67,10 +49,7 @@ class BottleFormsDict extends TaintKind {
6749
}
6850

6951
class FileUpload extends TaintKind {
70-
71-
FileUpload() {
72-
this = "bottle.FileUpload"
73-
}
52+
FileUpload() { this = "bottle.FileUpload" }
7453

7554
override TaintKind getTaintOfAttribute(string name) {
7655
name = "filename" and result instanceof UntrustedStringKind
@@ -79,37 +58,23 @@ class FileUpload extends TaintKind {
7958
or
8059
name = "file" and result instanceof UntrustedFile
8160
}
82-
8361
}
8462

8563
class UntrustedFile extends TaintKind {
86-
8764
UntrustedFile() { this = "Untrusted file" }
88-
8965
}
9066

9167
//
9268
// TO DO.. File uploads -- Should check about file uploads for other frameworks as well.
9369
// Move UntrustedFile to shared ___location
9470
//
95-
96-
9771
/** Parameter to a bottle request handler function */
9872
class BottleRequestParameter extends TaintSource {
99-
10073
BottleRequestParameter() {
101-
exists(BottleRoute route |
102-
route.getNamedArgument() = this.(ControlFlowNode).getNode()
103-
)
104-
}
105-
106-
override predicate isSourceOf(TaintKind kind) {
107-
kind instanceof UntrustedStringKind
74+
exists(BottleRoute route | route.getNamedArgument() = this.(ControlFlowNode).getNode())
10875
}
10976

110-
override string toString() {
111-
result = "bottle handler function argument"
112-
}
77+
override predicate isSourceOf(TaintKind kind) { kind instanceof UntrustedStringKind }
11378

79+
override string toString() { result = "bottle handler function argument" }
11480
}
115-
Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,45 @@
11
import python
2-
32
import semmle.python.security.TaintTracking
43
import semmle.python.security.strings.Untrusted
54
import semmle.python.web.Http
65
import semmle.python.web.bottle.General
76

8-
9-
/** A bottle.Response object
7+
/**
8+
* A bottle.Response object
109
* This isn't really a "taint", but we use the value tracking machinery to
1110
* track the flow of response objects.
1211
*/
1312
class BottleResponse extends TaintKind {
14-
15-
BottleResponse() {
16-
this = "bottle.response"
17-
}
18-
13+
BottleResponse() { this = "bottle.response" }
1914
}
2015

21-
private Value theBottleResponseObject() {
22-
result = theBottleModule().attr("response")
23-
}
16+
private Value theBottleResponseObject() { result = theBottleModule().attr("response") }
2417

2518
class BottleResponseBodyAssignment extends HttpResponseTaintSink {
26-
2719
BottleResponseBodyAssignment() {
2820
exists(DefinitionNode lhs |
2921
lhs.getValue() = this and
3022
lhs.(AttrNode).getObject("body").pointsTo(theBottleResponseObject())
3123
)
3224
}
3325

34-
override predicate sinks(TaintKind kind) {
35-
kind instanceof StringKind
36-
}
37-
26+
override predicate sinks(TaintKind kind) { kind instanceof StringKind }
3827
}
3928

4029
class BottleHandlerFunctionResult extends HttpResponseTaintSink {
41-
4230
BottleHandlerFunctionResult() {
4331
exists(BottleRoute route, Return ret |
4432
ret.getScope() = route.getFunction() and
4533
ret.getValue().getAFlowNode() = this
4634
)
4735
}
4836

49-
override predicate sinks(TaintKind kind) {
50-
kind instanceof StringKind
51-
}
52-
53-
override string toString() {
54-
result = "bottle handler function result"
55-
}
37+
override predicate sinks(TaintKind kind) { kind instanceof StringKind }
5638

39+
override string toString() { result = "bottle handler function result" }
5740
}
5841

5942
class BottleCookieSet extends CookieSet, CallNode {
60-
6143
BottleCookieSet() {
6244
any(BottleResponse r).taints(this.getFunction().(AttrNode).getObject("set_cookie"))
6345
}
@@ -67,6 +49,4 @@ class BottleCookieSet extends CookieSet, CallNode {
6749
override ControlFlowNode getKey() { result = this.getArg(0) }
6850

6951
override ControlFlowNode getValue() { result = this.getArg(1) }
70-
7152
}
72-

0 commit comments

Comments
 (0)