@@ -1676,7 +1676,7 @@ private module Django {
16761676 DjangoViewClassDef ( ) { this .getABase ( ) = django:: views:: generic:: View:: subclassRef ( ) .asExpr ( ) }
16771677
16781678 /** Gets a function that could handle incoming requests, if any. */
1679- DjangoRouteHandler getARouteHandler ( ) {
1679+ DjangoRouteHandler getARequestHandler ( ) {
16801680 // TODO: This doesn't handle attribute assignment. Should be OK, but analysis is not as complete as with
16811681 // points-to and `.lookup`, which would handle `post = my_post_handler` inside class def
16821682 result = this .getAMethod ( ) and
@@ -1725,7 +1725,7 @@ private module Django {
17251725 DjangoRouteHandler ( ) {
17261726 exists ( djangoRouteHandlerFunctionTracker ( this ) )
17271727 or
1728- any ( DjangoViewClassDef vc ) .getARouteHandler ( ) = this
1728+ any ( DjangoViewClassDef vc ) .getARequestHandler ( ) = this
17291729 }
17301730
17311731 /** Gets the index of the request parameter. */
@@ -1746,16 +1746,33 @@ private module Django {
17461746 /** Gets the data-flow node that is used as the argument for the view handler. */
17471747 abstract DataFlow:: Node getViewArg ( ) ;
17481748
1749- final override DjangoRouteHandler getARouteHandler ( ) {
1749+ final override DjangoRouteHandler getARequestHandler ( ) {
17501750 djangoRouteHandlerFunctionTracker ( result ) = getViewArg ( )
17511751 or
17521752 exists ( DjangoViewClassDef vc |
17531753 getViewArg ( ) = vc .asViewResult ( ) and
1754- result = vc .getARouteHandler ( )
1754+ result = vc .getARequestHandler ( )
17551755 )
17561756 }
17571757 }
17581758
1759+ /** A request handler defined in a django view class, that has no known route. */
1760+ private class DjangoViewClassHandlerWithoutKnownRoute extends HTTP:: Server:: RequestHandler:: Range ,
1761+ DjangoRouteHandler {
1762+ DjangoViewClassHandlerWithoutKnownRoute ( ) {
1763+ exists ( DjangoViewClassDef vc | vc .getARequestHandler ( ) = this ) and
1764+ not exists ( DjangoRouteSetup setup | setup .getARequestHandler ( ) = this )
1765+ }
1766+
1767+ override Parameter getARoutedParameter ( ) {
1768+ // Since we don't know the URL pattern, we simply mark all parameters as a routed
1769+ // parameter. This should give us more RemoteFlowSources but could also lead to
1770+ // more FPs. If this turns out to be the wrong tradeoff, we can always change our mind.
1771+ result in [ this .getArg ( _) , this .getArgByName ( _) ] and
1772+ not result = any ( int i | i <= this .getRequestParamIndex ( ) | this .getArg ( i ) )
1773+ }
1774+ }
1775+
17591776 /**
17601777 * Gets the regex that is used by django to find routed parameters when using `django.urls.path`.
17611778 *
@@ -1787,14 +1804,14 @@ private module Django {
17871804 // If we don't know the URL pattern, we simply mark all parameters as a routed
17881805 // parameter. This should give us more RemoteFlowSources but could also lead to
17891806 // more FPs. If this turns out to be the wrong tradeoff, we can always change our mind.
1790- exists ( DjangoRouteHandler routeHandler | routeHandler = this .getARouteHandler ( ) |
1807+ exists ( DjangoRouteHandler routeHandler | routeHandler = this .getARequestHandler ( ) |
17911808 not exists ( this .getUrlPattern ( ) ) and
17921809 result in [ routeHandler .getArg ( _) , routeHandler .getArgByName ( _) ] and
17931810 not result = any ( int i | i <= routeHandler .getRequestParamIndex ( ) | routeHandler .getArg ( i ) )
17941811 )
17951812 or
17961813 exists ( string name |
1797- result = this .getARouteHandler ( ) .getArgByName ( name ) and
1814+ result = this .getARequestHandler ( ) .getArgByName ( name ) and
17981815 exists ( string match |
17991816 match = this .getUrlPattern ( ) .regexpFind ( pathRoutedParameterRegex ( ) , _, _) and
18001817 name = match .regexpCapture ( pathRoutedParameterRegex ( ) , 2 )
@@ -1809,14 +1826,14 @@ private module Django {
18091826 // If we don't know the URL pattern, we simply mark all parameters as a routed
18101827 // parameter. This should give us more RemoteFlowSources but could also lead to
18111828 // more FPs. If this turns out to be the wrong tradeoff, we can always change our mind.
1812- exists ( DjangoRouteHandler routeHandler | routeHandler = this .getARouteHandler ( ) |
1829+ exists ( DjangoRouteHandler routeHandler | routeHandler = this .getARequestHandler ( ) |
18131830 not exists ( this .getUrlPattern ( ) ) and
18141831 result in [ routeHandler .getArg ( _) , routeHandler .getArgByName ( _) ] and
18151832 not result = any ( int i | i <= routeHandler .getRequestParamIndex ( ) | routeHandler .getArg ( i ) )
18161833 )
18171834 or
18181835 exists ( DjangoRouteHandler routeHandler , DjangoRouteRegex regex |
1819- routeHandler = this .getARouteHandler ( ) and
1836+ routeHandler = this .getARequestHandler ( ) and
18201837 regex .getRouteSetup ( ) = this
18211838 |
18221839 // either using named capture groups (passed as keyword arguments) or using
@@ -1888,10 +1905,13 @@ private module Django {
18881905 // ---------------------------------------------------------------------------
18891906 // HttpRequest taint modeling
18901907 // ---------------------------------------------------------------------------
1891- class DjangoRouteHandlerRequestParam extends django:: http:: request:: HttpRequest:: InstanceSource ,
1908+ /** A parameter that will receive the django `HttpRequest` instance when a request handler is invoked. */
1909+ private class DjangoRequestHandlerRequestParam extends django:: http:: request:: HttpRequest:: InstanceSource ,
18921910 RemoteFlowSource:: Range , DataFlow:: ParameterNode {
1893- DjangoRouteHandlerRequestParam ( ) {
1894- this .getParameter ( ) = any ( DjangoRouteSetup setup ) .getARouteHandler ( ) .getRequestParam ( )
1911+ DjangoRequestHandlerRequestParam ( ) {
1912+ this .getParameter ( ) = any ( DjangoRouteSetup setup ) .getARequestHandler ( ) .getRequestParam ( )
1913+ or
1914+ this .getParameter ( ) = any ( DjangoViewClassHandlerWithoutKnownRoute setup ) .getRequestParam ( )
18951915 }
18961916
18971917 override string getSourceType ( ) { result = "django.http.request.HttpRequest" }
0 commit comments