@@ -107,4 +107,69 @@ private module RestFramework {
107
107
108
108
override string getFramework ( ) { result = "Django (rest_framework)" }
109
109
}
110
+
111
+ // ---------------------------------------------------------------------------
112
+ // request modeling
113
+ // ---------------------------------------------------------------------------
114
+ /**
115
+ * A parameter that will receive a `rest_framework.request.Request` instance when a
116
+ * request handler is invoked.
117
+ */
118
+ private class RestFrameworkRequestHandlerRequestParam extends Request:: InstanceSource ,
119
+ RemoteFlowSource:: Range , DataFlow:: ParameterNode {
120
+ RestFrameworkRequestHandlerRequestParam ( ) {
121
+ // rest_framework.views.APIView subclass
122
+ exists ( RestFrameworkApiViewClass vc |
123
+ this .getParameter ( ) =
124
+ vc .getARequestHandler ( ) .( PrivateDjango:: DjangoRouteHandler ) .getRequestParam ( )
125
+ )
126
+ or
127
+ // annotated with @api_view decorator
128
+ exists ( PrivateDjango:: DjangoRouteHandler rh | rh instanceof RestFrameworkFunctionBasedView |
129
+ this .getParameter ( ) = rh .getRequestParam ( )
130
+ )
131
+ }
132
+
133
+ override string getSourceType ( ) { result = "rest_framework.request.HttpRequest" }
134
+ }
135
+
136
+ /**
137
+ * Provides models for the `rest_framework.request.Request` class
138
+ *
139
+ * See https://www.django-rest-framework.org/api-guide/requests/.
140
+ */
141
+ module Request {
142
+ /** Gets a reference to the `rest_framework.request.Request` class. */
143
+ private API:: Node classRef ( ) {
144
+ result = API:: moduleImport ( "rest_framework" ) .getMember ( "request" ) .getMember ( "Request" )
145
+ }
146
+
147
+ /**
148
+ * A source of instances of `rest_framework.request.Request`, extend this class to model new instances.
149
+ *
150
+ * This can include instantiations of the class, return values from function
151
+ * calls, or a special parameter that will be set when functions are called by an external
152
+ * library.
153
+ *
154
+ * Use the predicate `Request::instance()` to get references to instances of `rest_framework.request.Request`.
155
+ */
156
+ abstract class InstanceSource extends PrivateDjango:: django:: http:: request:: HttpRequest:: InstanceSource {
157
+ }
158
+
159
+ /** A direct instantiation of `rest_framework.request.Request`. */
160
+ private class ClassInstantiation extends InstanceSource , DataFlow:: CallCfgNode {
161
+ ClassInstantiation ( ) { this = classRef ( ) .getACall ( ) }
162
+ }
163
+
164
+ /** Gets a reference to an instance of `rest_framework.request.Request`. */
165
+ private DataFlow:: TypeTrackingNode instance ( DataFlow:: TypeTracker t ) {
166
+ t .start ( ) and
167
+ result instanceof InstanceSource
168
+ or
169
+ exists ( DataFlow:: TypeTracker t2 | result = instance ( t2 ) .track ( t2 , t ) )
170
+ }
171
+
172
+ /** Gets a reference to an instance of `rest_framework.request.Request`. */
173
+ DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
174
+ }
110
175
}
0 commit comments