Skip to content

Commit b760b1f

Browse files
committed
Python: Django: Don't require viewFunction to mark as route
It's very nice to be able to see all the DjangoRoutes even if we don't know the function that is used to handle the request, at least for debugging.
1 parent 2da1503 commit b760b1f

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import semmle.python.web.Http
66
// a FunctionValue, so we can't use `FunctionValue.getArgumentForCall`
77
// https://github.com/django/django/blob/master/django/urls/conf.py#L76
88
abstract class DjangoRoute extends CallNode {
9-
abstract FunctionValue getViewFunction();
9+
FunctionValue getViewFunction() {
10+
result = this.getArg(1).pointsTo()
11+
or
12+
result = this.getArgByName("view").pointsTo()
13+
}
1014

1115
abstract string getANamedArgument();
1216

@@ -25,14 +29,12 @@ class DjangoRouteRegex extends RegexString {
2529

2630
class DjangoRegexRoute extends DjangoRoute {
2731
ControlFlowNode route;
28-
FunctionValue view;
2932

3033
DjangoRegexRoute() {
3134
exists(FunctionValue route_maker |
32-
// Django 1.x
35+
// Django 1.x: https://docs.djangoproject.com/en/1.11/ref/urls/#django.conf.urls.url
3336
Value::named("django.conf.urls.url") = route_maker and
34-
route_maker.getArgumentForCall(this, 0) = route and
35-
route_maker.getArgumentForCall(this, 1).pointsTo(view)
37+
route_maker.getArgumentForCall(this, 0) = route
3638
)
3739
or
3840
// Django 2.x and 3.x: https://docs.djangoproject.com/en/3.0/ref/urls/#re-path
@@ -41,16 +43,9 @@ class DjangoRegexRoute extends DjangoRoute {
4143
route = this.getArg(0)
4244
or
4345
route = this.getArgByName("route")
44-
) and
45-
(
46-
this.getArg(1).pointsTo(view)
47-
or
48-
this.getArgByName("view").pointsTo(view)
4946
)
5047
}
5148

52-
override FunctionValue getViewFunction() { result = view }
53-
5449
ControlFlowNode getRouteArg() { result = route }
5550

5651
override string getANamedArgument() {
@@ -69,7 +64,6 @@ class DjangoRegexRoute extends DjangoRoute {
6964

7065
class DjangoPathRoute extends DjangoRoute {
7166
ControlFlowNode route;
72-
FunctionValue view;
7367

7468
DjangoPathRoute() {
7569
// Django 2.x and 3.x: https://docs.djangoproject.com/en/3.0/ref/urls/#path
@@ -78,16 +72,9 @@ class DjangoPathRoute extends DjangoRoute {
7872
route = this.getArg(0)
7973
or
8074
route = this.getArgByName("route")
81-
) and
82-
(
83-
this.getArg(1).pointsTo(view)
84-
or
85-
this.getArgByName("view").pointsTo(view)
8675
)
8776
}
8877

89-
override FunctionValue getViewFunction() { result = view }
90-
9178
override string getANamedArgument() {
9279
// regexp taken from django:
9380
// https://github.com/django/django/blob/7d1bf29977bb368d7c28e7c6eb146db3b3009ae7/django/urls/resolvers.py#L199

0 commit comments

Comments
 (0)