@@ -17,10 +17,12 @@ private import semmle.python.frameworks.internal.SelfRefMixin
17
17
private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
18
18
19
19
/**
20
+ * INTERNAL: Do not use.
21
+ *
20
22
* Provides models for the `django` PyPI package.
21
23
* See https://www.djangoproject.com/.
22
24
*/
23
- private module Django {
25
+ module Django {
24
26
/** Provides models for the `django.views` module */
25
27
module Views {
26
28
/**
@@ -367,6 +369,52 @@ private module Django {
367
369
}
368
370
}
369
371
372
+ /**
373
+ * Provides models for the `django.contrib.auth.models.User` class
374
+ *
375
+ * See https://docs.djangoproject.com/en/3.2/ref/contrib/auth/#user-model.
376
+ */
377
+ module User {
378
+ /**
379
+ * A source of instances of `django.contrib.auth.models.User`, extend this class to model new instances.
380
+ *
381
+ * This can include instantiations of the class, return values from function
382
+ * calls, or a special parameter that will be set when functions are called by an external
383
+ * library.
384
+ *
385
+ * Use the predicate `User::instance()` to get references to instances of `django.contrib.auth.models.User`.
386
+ */
387
+ abstract class InstanceSource extends DataFlow:: LocalSourceNode { }
388
+
389
+ /** Gets a reference to an instance of `django.contrib.auth.models.User`. */
390
+ private DataFlow:: TypeTrackingNode instance ( DataFlow:: TypeTracker t ) {
391
+ t .start ( ) and
392
+ result instanceof InstanceSource
393
+ or
394
+ exists ( DataFlow:: TypeTracker t2 | result = instance ( t2 ) .track ( t2 , t ) )
395
+ }
396
+
397
+ /** Gets a reference to an instance of `django.contrib.auth.models.User`. */
398
+ DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
399
+
400
+ /**
401
+ * Taint propagation for `django.contrib.auth.models.User`.
402
+ */
403
+ private class InstanceTaintSteps extends InstanceTaintStepsHelper {
404
+ InstanceTaintSteps ( ) { this = "django.contrib.auth.models.User" }
405
+
406
+ override DataFlow:: Node getInstance ( ) { result = instance ( ) }
407
+
408
+ override string getAttributeName ( ) {
409
+ result in [ "username" , "first_name" , "last_name" , "email" ]
410
+ }
411
+
412
+ override string getMethodName ( ) { none ( ) }
413
+
414
+ override string getAsyncMethodName ( ) { none ( ) }
415
+ }
416
+ }
417
+
370
418
/**
371
419
* Provides models for the `django.core.files.uploadedfile.UploadedFile` class
372
420
*
@@ -466,10 +514,12 @@ private module Django {
466
514
}
467
515
468
516
/**
517
+ * INTERNAL: Do not use.
518
+ *
469
519
* Provides models for the `django` PyPI package (that we are not quite ready to publicly expose yet).
470
520
* See https://www.djangoproject.com/.
471
521
*/
472
- private module PrivateDjango {
522
+ module PrivateDjango {
473
523
// ---------------------------------------------------------------------------
474
524
// django
475
525
// ---------------------------------------------------------------------------
@@ -496,6 +546,7 @@ private module PrivateDjango {
496
546
/** Gets a reference to the `django.db.connection` object. */
497
547
API:: Node connection ( ) { result = db ( ) .getMember ( "connection" ) }
498
548
549
+ /** A `django.db.connection` is a PEP249 compliant DB connection. */
499
550
class DjangoDbConnection extends PEP249:: Connection:: InstanceSource {
500
551
DjangoDbConnection ( ) { this = connection ( ) .getAUse ( ) }
501
552
}
@@ -692,6 +743,7 @@ private module PrivateDjango {
692
743
693
744
/** Provides models for the `django.conf` module */
694
745
module conf {
746
+ /** Provides models for the `django.conf.urls` module */
695
747
module conf_urls {
696
748
// -------------------------------------------------------------------------
697
749
// django.conf.urls
@@ -890,14 +942,15 @@ private module PrivateDjango {
890
942
* See https://docs.djangoproject.com/en/3.1/ref/request-response/#django.http.HttpResponse.
891
943
*/
892
944
module HttpResponse {
945
+ /** Gets a reference to the `django.http.response.HttpResponse` class. */
893
946
API:: Node baseClassRef ( ) {
894
947
result = response ( ) .getMember ( "HttpResponse" )
895
948
or
896
949
// Handle `django.http.HttpResponse` alias
897
950
result = http ( ) .getMember ( "HttpResponse" )
898
951
}
899
952
900
- /** Gets a reference to the `django.http.response.HttpResponse` class. */
953
+ /** Gets a reference to the `django.http.response.HttpResponse` class or any subclass . */
901
954
API:: Node classRef ( ) { result = baseClassRef ( ) .getASubclass * ( ) }
902
955
903
956
/**
@@ -1893,14 +1946,11 @@ private module PrivateDjango {
1893
1946
* with the django framework.
1894
1947
*
1895
1948
* Most functions take a django HttpRequest as a parameter (but not all).
1949
+ *
1950
+ * Extend this class to refine existing API models. If you want to model new APIs,
1951
+ * extend `DjangoRouteHandler::Range` instead.
1896
1952
*/
1897
- private class DjangoRouteHandler extends Function {
1898
- DjangoRouteHandler ( ) {
1899
- exists ( DjangoRouteSetup route | route .getViewArg ( ) = poorMansFunctionTracker ( this ) )
1900
- or
1901
- any ( DjangoViewClass vc ) .getARequestHandler ( ) = this
1902
- }
1903
-
1953
+ class DjangoRouteHandler extends Function instanceof DjangoRouteHandler:: Range {
1904
1954
/**
1905
1955
* Gets the index of the parameter where the first routed parameter can be passed --
1906
1956
* that is, the one just after any possible `self` or HttpRequest parameters.
@@ -1920,6 +1970,24 @@ private module PrivateDjango {
1920
1970
Parameter getRequestParam ( ) { result = this .getArg ( this .getRequestParamIndex ( ) ) }
1921
1971
}
1922
1972
1973
+ /** Provides a class for modeling new django route handlers. */
1974
+ module DjangoRouteHandler {
1975
+ /**
1976
+ * Extend this class to model new APIs. If you want to refine existing API models,
1977
+ * extend `DjangoRouteHandler` instead.
1978
+ */
1979
+ abstract class Range extends Function { }
1980
+
1981
+ /** Route handlers from normal usage of django. */
1982
+ private class StandardDjangoRouteHandlers extends Range {
1983
+ StandardDjangoRouteHandlers ( ) {
1984
+ exists ( DjangoRouteSetup route | route .getViewArg ( ) = poorMansFunctionTracker ( this ) )
1985
+ or
1986
+ any ( DjangoViewClass vc ) .getARequestHandler ( ) = this
1987
+ }
1988
+ }
1989
+ }
1990
+
1923
1991
/**
1924
1992
* A method named `get_redirect_url` on a django view class.
1925
1993
*
@@ -1941,7 +2009,7 @@ private module PrivateDjango {
1941
2009
}
1942
2010
1943
2011
/** A data-flow node that sets up a route on a server, using the django framework. */
1944
- abstract private class DjangoRouteSetup extends HTTP:: Server:: RouteSetup:: Range , DataFlow:: CfgNode {
2012
+ abstract class DjangoRouteSetup extends HTTP:: Server:: RouteSetup:: Range , DataFlow:: CfgNode {
1945
2013
/** Gets the data-flow node that is used as the argument for the view handler. */
1946
2014
abstract DataFlow:: Node getViewArg ( ) ;
1947
2015
0 commit comments