@@ -133,10 +133,42 @@ private module Django {
133133 }
134134 }
135135
136- private class DjangoPathRouteSetup extends HTTP:: Server:: RouteSetup:: Range , DataFlow:: CfgNode {
136+ /**
137+ * Gets a reference to the Function `func`.
138+ *
139+ * The idea is that this function should be used as a route handler when setting up a
140+ * route, but currently it just tracks all functions, since we can't do type-tracking
141+ * backwards yet (TODO).
142+ */
143+ private DataFlow:: Node djangoRouteHandlerFunctionTracker ( DataFlow:: TypeTracker t , Function func ) {
144+ t .start ( ) and
145+ result = DataFlow:: exprNode ( func .getDefinition ( ) )
146+ or
147+ exists ( DataFlow:: TypeTracker t2 |
148+ result = djangoRouteHandlerFunctionTracker ( t2 , func ) .track ( t2 , t )
149+ )
150+ }
151+
152+ /**
153+ * Gets a reference to the Function `func`.
154+ *
155+ * The idea is that this function should be used as a route handler when setting up a
156+ * route, but currently it just tracks all functions, since we can't do type-tracking
157+ * backwards yet (TODO).
158+ */
159+ private DataFlow:: Node djangoRouteHandlerFunctionTracker ( Function func ) {
160+ result = djangoRouteHandlerFunctionTracker ( DataFlow:: TypeTracker:: end ( ) , func )
161+ }
162+
163+ /**
164+ * A call to `django.urls.path`.
165+ *
166+ * See https://docs.djangoproject.com/en/3.0/ref/urls/#path
167+ */
168+ private class DjangoUrlsPathCall extends HTTP:: Server:: RouteSetup:: Range , DataFlow:: CfgNode {
137169 override CallNode node ;
138170
139- DjangoPathRouteSetup ( ) { node .getFunction ( ) = django:: urls:: path ( ) .asCfgNode ( ) }
171+ DjangoUrlsPathCall ( ) { node .getFunction ( ) = django:: urls:: path ( ) .asCfgNode ( ) }
140172
141173 override string getUrlPattern ( ) {
142174 exists ( StrConst str , ControlFlowNode urlPatternArg |
@@ -148,15 +180,25 @@ private module Django {
148180 )
149181 }
150182
151- override Function getARouteHandler ( ) { none ( ) }
183+ override Function getARouteHandler ( ) {
184+ exists ( DataFlow:: Node viewArg |
185+ viewArg .asCfgNode ( ) in [ node .getArg ( 1 ) , node .getArgByName ( "view" ) ] and
186+ djangoRouteHandlerFunctionTracker ( result ) = viewArg
187+ )
188+ }
152189
153190 override Parameter getARoutedParameter ( ) { none ( ) }
154191 }
155192
156- private class DjangoRePathRouteSetup extends HTTP:: Server:: RouteSetup:: Range , DataFlow:: CfgNode {
193+ /**
194+ * A call to `django.urls.re_path`.
195+ *
196+ * See https://docs.djangoproject.com/en/3.0/ref/urls/#re_path
197+ */
198+ private class DjangoUrlsRePathCall extends HTTP:: Server:: RouteSetup:: Range , DataFlow:: CfgNode {
157199 override CallNode node ;
158200
159- DjangoRePathRouteSetup ( ) { node .getFunction ( ) = django:: urls:: re_path ( ) .asCfgNode ( ) }
201+ DjangoUrlsRePathCall ( ) { node .getFunction ( ) = django:: urls:: re_path ( ) .asCfgNode ( ) }
160202
161203 override string getUrlPattern ( ) {
162204 exists ( StrConst str , ControlFlowNode urlPatternArg |
@@ -168,7 +210,12 @@ private module Django {
168210 )
169211 }
170212
171- override Function getARouteHandler ( ) { none ( ) }
213+ override Function getARouteHandler ( ) {
214+ exists ( DataFlow:: Node viewArg |
215+ viewArg .asCfgNode ( ) in [ node .getArg ( 1 ) , node .getArgByName ( "view" ) ] and
216+ djangoRouteHandlerFunctionTracker ( result ) = viewArg
217+ )
218+ }
172219
173220 override Parameter getARoutedParameter ( ) { none ( ) }
174221 }
0 commit comments