Skip to content

Commit fc59b10

Browse files
committed
Python: Autoformat (4 spaces) django library
1 parent f4e0abd commit fc59b10

File tree

7 files changed

+67
-196
lines changed

7 files changed

+67
-196
lines changed
Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
11
import python
22
import semmle.python.security.injection.Sql
33

4-
/** A taint kind representing a django cursor object.
4+
/**
5+
* A taint kind representing a django cursor object.
56
*/
67
class DjangoDbCursor extends DbCursor {
7-
8-
DjangoDbCursor() {
9-
this = "django.db.connection.cursor"
10-
}
11-
8+
DjangoDbCursor() { this = "django.db.connection.cursor" }
129
}
1310

14-
private Value theDjangoConnectionObject() {
15-
result = Value::named("django.db.connection")
16-
}
11+
private Value theDjangoConnectionObject() { result = Value::named("django.db.connection") }
1712

18-
/** A kind of taint source representing sources of django cursor objects.
13+
/**
14+
* A kind of taint source representing sources of django cursor objects.
1915
*/
2016
class DjangoDbCursorSource extends DbConnectionSource {
21-
2217
DjangoDbCursorSource() {
2318
exists(AttrNode cursor |
24-
this.(CallNode).getFunction()= cursor and
19+
this.(CallNode).getFunction() = cursor and
2520
cursor.getObject("cursor").pointsTo(theDjangoConnectionObject())
2621
)
2722
}
2823

29-
override string toString() {
30-
result = "django.db.connection.cursor"
31-
}
32-
33-
override predicate isSourceOf(TaintKind kind) {
34-
kind instanceof DjangoDbCursor
35-
}
24+
override string toString() { result = "django.db.connection.cursor" }
3625

26+
override predicate isSourceOf(TaintKind kind) { kind instanceof DjangoDbCursor }
3727
}
3828

39-
40-
ClassValue theDjangoRawSqlClass() {
41-
result = Value::named("django.db.models.expressions.RawSQL")
42-
}
29+
ClassValue theDjangoRawSqlClass() { result = Value::named("django.db.models.expressions.RawSQL") }
4330

4431
/**
4532
* A sink of taint on calls to `django.db.models.expressions.RawSQL`. This
4633
* allows arbitrary SQL statements to be executed, which is a security risk.
4734
*/
48-
4935
class DjangoRawSqlSink extends SqlInjectionSink {
5036
DjangoRawSqlSink() {
5137
exists(CallNode call |
@@ -54,12 +40,7 @@ class DjangoRawSqlSink extends SqlInjectionSink {
5440
)
5541
}
5642

57-
override predicate sinks(TaintKind kind) {
58-
kind instanceof ExternalStringKind
59-
}
43+
override predicate sinks(TaintKind kind) { kind instanceof ExternalStringKind }
6044

61-
override string toString() {
62-
result = "django.db.models.expressions.RawSQL(sink,...)"
63-
}
45+
override string toString() { result = "django.db.models.expressions.RawSQL(sink,...)" }
6446
}
65-
Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import python
2-
32
import semmle.python.security.TaintTracking
43
import semmle.python.security.strings.Basic
54
import semmle.python.web.Http
65
import semmle.python.security.injection.Sql
76

87
/** A django model class */
98
class DjangoModel extends ClassValue {
10-
11-
DjangoModel() {
12-
Value::named("django.db.models.Model") = this.getASuperType()
13-
}
14-
9+
DjangoModel() { Value::named("django.db.models.Model") = this.getASuperType() }
1510
}
1611

1712
/** A "taint" for django database tables */
1813
class DjangoDbTableObjects extends TaintKind {
19-
20-
DjangoDbTableObjects() {
21-
this = "django.db.models.Model.objects"
22-
}
14+
DjangoDbTableObjects() { this = "django.db.models.Model.objects" }
2315

2416
override TaintKind getTaintOfMethodResult(string name) {
2517
result = this and
@@ -53,102 +45,72 @@ class DjangoDbTableObjects extends TaintKind {
5345

5446
/** Django model objects, which are sources of django database table "taint" */
5547
class DjangoModelObjects extends TaintSource {
56-
5748
DjangoModelObjects() {
5849
this.(AttrNode).isLoad() and this.(AttrNode).getObject("objects").pointsTo(any(DjangoModel m))
5950
}
6051

61-
override predicate isSourceOf(TaintKind kind) {
62-
kind instanceof DjangoDbTableObjects
63-
}
64-
65-
override string toString() {
66-
result = "django.db.models.Model.objects"
67-
}
52+
override predicate isSourceOf(TaintKind kind) { kind instanceof DjangoDbTableObjects }
6853

54+
override string toString() { result = "django.db.models.Model.objects" }
6955
}
7056

7157
/** A write to a field of a django model, which is a vulnerable to external data. */
7258
class DjangoModelFieldWrite extends SqlInjectionSink {
73-
7459
DjangoModelFieldWrite() {
7560
exists(AttrNode attr, DjangoModel model |
7661
this = attr and attr.isStore() and attr.getObject(_).pointsTo(model)
7762
)
7863
}
7964

80-
override predicate sinks(TaintKind kind) {
81-
kind instanceof ExternalStringKind
82-
}
83-
84-
override string toString() {
85-
result = "django model field write"
86-
}
65+
override predicate sinks(TaintKind kind) { kind instanceof ExternalStringKind }
8766

67+
override string toString() { result = "django model field write" }
8868
}
8969

9070
/** A direct reference to a django model object, which is vulnerable to external data. */
9171
class DjangoModelDirectObjectReference extends TaintSink {
92-
9372
DjangoModelDirectObjectReference() {
94-
exists(CallNode objects_get_call, ControlFlowNode objects |
95-
this = objects_get_call.getAnArg() |
73+
exists(CallNode objects_get_call, ControlFlowNode objects | this = objects_get_call.getAnArg() |
9674
objects_get_call.getFunction().(AttrNode).getObject("get") = objects and
9775
any(DjangoDbTableObjects objs).taints(objects)
9876
)
9977
}
10078

101-
override predicate sinks(TaintKind kind) {
102-
kind instanceof ExternalStringKind
103-
}
79+
override predicate sinks(TaintKind kind) { kind instanceof ExternalStringKind }
10480

105-
override string toString() {
106-
result = "django model object reference"
107-
}
81+
override string toString() { result = "django model object reference" }
10882
}
10983

11084
/**
111-
* A call to the `raw` method on a django model. This allows a raw SQL query
85+
* A call to the `raw` method on a django model. This allows a raw SQL query
11286
* to be sent to the database, which is a security risk.
11387
*/
11488
class DjangoModelRawCall extends SqlInjectionSink {
115-
11689
DjangoModelRawCall() {
117-
exists(CallNode raw_call, ControlFlowNode queryset |
118-
this = raw_call.getArg(0) |
90+
exists(CallNode raw_call, ControlFlowNode queryset | this = raw_call.getArg(0) |
11991
raw_call.getFunction().(AttrNode).getObject("raw") = queryset and
12092
any(DjangoDbTableObjects objs).taints(queryset)
12193
)
12294
}
12395

124-
override predicate sinks(TaintKind kind) {
125-
kind instanceof ExternalStringKind
126-
}
96+
override predicate sinks(TaintKind kind) { kind instanceof ExternalStringKind }
12797

128-
override string toString() {
129-
result = "django.models.QuerySet.raw(sink,...)"
130-
}
98+
override string toString() { result = "django.models.QuerySet.raw(sink,...)" }
13199
}
132100

133101
/**
134-
* A call to the `extra` method on a django model. This allows a raw SQL query
102+
* A call to the `extra` method on a django model. This allows a raw SQL query
135103
* to be sent to the database, which is a security risk.
136104
*/
137105
class DjangoModelExtraCall extends SqlInjectionSink {
138-
139106
DjangoModelExtraCall() {
140-
exists(CallNode extra_call, ControlFlowNode queryset |
141-
this = extra_call.getArg(0) |
107+
exists(CallNode extra_call, ControlFlowNode queryset | this = extra_call.getArg(0) |
142108
extra_call.getFunction().(AttrNode).getObject("extra") = queryset and
143109
any(DjangoDbTableObjects objs).taints(queryset)
144110
)
145111
}
146112

147-
override predicate sinks(TaintKind kind) {
148-
kind instanceof ExternalStringKind
149-
}
113+
override predicate sinks(TaintKind kind) { kind instanceof ExternalStringKind }
150114

151-
override string toString() {
152-
result = "django.models.QuerySet.extra(sink,...)"
153-
}
115+
override string toString() { result = "django.models.QuerySet.extra(sink,...)" }
154116
}
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
/** Provides class representing the `django.redirect` function.
1+
/**
2+
* Provides class representing the `django.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
private import semmle.python.web.django.Shared
1011
private import semmle.python.web.Http
1112

12-
1313
/**
1414
* Represents an argument to the `django.redirect` function.
1515
*/
1616
class DjangoRedirect extends HttpRedirectTaintSink {
17-
18-
override string toString() {
19-
result = "django.redirect"
20-
}
17+
override string toString() { result = "django.redirect" }
2118

2219
DjangoRedirect() {
2320
exists(CallNode call |
2421
redirect().getACall() = call and
25-
this = call.getAnArg()
22+
this = call.getAnArg()
2623
)
2724
}
28-
2925
}

0 commit comments

Comments
 (0)