@@ -2024,18 +2024,8 @@ private module Django {
2024
2024
result = djangoRouteHandlerFunctionTracker ( DataFlow:: TypeTracker:: end ( ) , func )
2025
2025
}
2026
2026
2027
- /** A django View class defined in project code. */
2028
- class DjangoViewClassDef extends Class {
2029
- DjangoViewClassDef ( ) { this .getABase ( ) = django:: views:: generic:: View:: subclassRef ( ) .asExpr ( ) }
2030
-
2031
- /** Gets a function that could handle incoming requests, if any. */
2032
- Function getARequestHandler ( ) {
2033
- // TODO: This doesn't handle attribute assignment. Should be OK, but analysis is not as complete as with
2034
- // points-to and `.lookup`, which would handle `post = my_post_handler` inside class def
2035
- result = this .getAMethod ( ) and
2036
- result .getName ( ) = HTTP:: httpVerbLower ( )
2037
- }
2038
-
2027
+ /** A class that might be a django View class. */
2028
+ class PossibleDjangoViewClass extends Class {
2039
2029
/** Gets a reference to this class. */
2040
2030
private DataFlow:: Node getARef ( DataFlow:: TypeTracker t ) {
2041
2031
t .start ( ) and
@@ -2070,6 +2060,37 @@ private module Django {
2070
2060
DataFlow:: Node asViewResult ( ) { result = asViewResult ( DataFlow:: TypeTracker:: end ( ) ) }
2071
2061
}
2072
2062
2063
+ /** A class that we consider a django View class. */
2064
+ abstract class DjangoViewClass extends PossibleDjangoViewClass {
2065
+ /** Gets a function that could handle incoming requests, if any. */
2066
+ Function getARequestHandler ( ) {
2067
+ // TODO: This doesn't handle attribute assignment. Should be OK, but analysis is not as complete as with
2068
+ // points-to and `.lookup`, which would handle `post = my_post_handler` inside class def
2069
+ result = this .getAMethod ( ) and
2070
+ result .getName ( ) = HTTP:: httpVerbLower ( )
2071
+ }
2072
+ }
2073
+
2074
+ /**
2075
+ * A class that is used in a route-setup, with `<class>.as_view()`, therefore being
2076
+ * considered a django View class.
2077
+ */
2078
+ class DjangoViewClassFromRouteSetup extends DjangoViewClass {
2079
+ DjangoViewClassFromRouteSetup ( ) {
2080
+ exists ( DjangoRouteSetup setup | setup .getViewArg ( ) = this .asViewResult ( ) )
2081
+ }
2082
+ }
2083
+
2084
+ /**
2085
+ * A class that has a super-type which is a django View class, therefore also
2086
+ * becoming a django View class.
2087
+ */
2088
+ class DjangoViewClassFromSuperClass extends DjangoViewClass {
2089
+ DjangoViewClassFromSuperClass ( ) {
2090
+ this .getABase ( ) = django:: views:: generic:: View:: subclassRef ( ) .asExpr ( )
2091
+ }
2092
+ }
2093
+
2073
2094
/**
2074
2095
* A function that is a django route handler, meaning it handles incoming requests
2075
2096
* with the django framework.
@@ -2078,7 +2099,7 @@ private module Django {
2078
2099
DjangoRouteHandler ( ) {
2079
2100
exists ( DjangoRouteSetup route | route .getViewArg ( ) = djangoRouteHandlerFunctionTracker ( this ) )
2080
2101
or
2081
- any ( DjangoViewClassDef vc ) .getARequestHandler ( ) = this
2102
+ any ( DjangoViewClass vc ) .getARequestHandler ( ) = this
2082
2103
}
2083
2104
2084
2105
/** Gets the index of the request parameter. */
@@ -2102,7 +2123,7 @@ private module Django {
2102
2123
final override DjangoRouteHandler getARequestHandler ( ) {
2103
2124
djangoRouteHandlerFunctionTracker ( result ) = getViewArg ( )
2104
2125
or
2105
- exists ( DjangoViewClassDef vc |
2126
+ exists ( DjangoViewClass vc |
2106
2127
getViewArg ( ) = vc .asViewResult ( ) and
2107
2128
result = vc .getARequestHandler ( )
2108
2129
)
@@ -2113,7 +2134,7 @@ private module Django {
2113
2134
private class DjangoViewClassHandlerWithoutKnownRoute extends HTTP:: Server:: RequestHandler:: Range ,
2114
2135
DjangoRouteHandler {
2115
2136
DjangoViewClassHandlerWithoutKnownRoute ( ) {
2116
- exists ( DjangoViewClassDef vc | vc .getARequestHandler ( ) = this ) and
2137
+ exists ( DjangoViewClass vc | vc .getARequestHandler ( ) = this ) and
2117
2138
not exists ( DjangoRouteSetup setup | setup .getARequestHandler ( ) = this )
2118
2139
}
2119
2140
0 commit comments