@@ -737,6 +737,38 @@ module PrivateDjango {
737737 }
738738 }
739739
740+ /**
741+ * Provides models for the `django.db.models.FileField` class and `ImageField` subclasses.
742+ *
743+ * See
744+ * - https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.FileField
745+ * - https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.ImageField
746+ */
747+ module FileField {
748+ /** Gets a reference to the `django.db.models.FileField` or the `django.db.models.ImageField` class or any subclass. */
749+ API:: Node subclassRef ( ) {
750+ exists ( string className | className in [ "FileField" , "ImageField" ] |
751+ // commonly used alias
752+ result =
753+ API:: moduleImport ( "django" )
754+ .getMember ( "db" )
755+ .getMember ( "models" )
756+ .getMember ( className )
757+ .getASubclass * ( )
758+ or
759+ // actual class definition
760+ result =
761+ API:: moduleImport ( "django" )
762+ .getMember ( "db" )
763+ .getMember ( "models" )
764+ .getMember ( "fields" )
765+ .getMember ( "files" )
766+ .getMember ( className )
767+ .getASubclass * ( )
768+ )
769+ }
770+ }
771+
740772 /**
741773 * Gets a reference to the Manager (django.db.models.Manager) for the django Model `modelClass`,
742774 * accessed by `<modelClass>.objects`.
@@ -2599,6 +2631,36 @@ module PrivateDjango {
25992631 }
26002632 }
26012633
2634+ /**
2635+ * A parameter that accepts the filename used to upload a file. This is the second
2636+ * parameter in functions used for the `upload_to` argument to a `FileField`.
2637+ *
2638+ * Note that the value this parameter accepts cannot contain a slash. Even when
2639+ * forcing the filename to contain a slash when sending the request, django does
2640+ * something like `input_filename.split("/")[-1]` (so other special characters still
2641+ * allowed). This also means that although the return value from `upload_to` is used
2642+ * to construct a path, path injection is not possible.
2643+ *
2644+ * See
2645+ * - https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.FileField.upload_to
2646+ * - https://docs.djangoproject.com/en/3.1/topics/http/file-uploads/#handling-uploaded-files-with-a-model
2647+ */
2648+ private class DjangoFileFieldUploadToFunctionFilenameParam extends RemoteFlowSource:: Range ,
2649+ DataFlow:: ParameterNode {
2650+ DjangoFileFieldUploadToFunctionFilenameParam ( ) {
2651+ exists ( DataFlow:: CallCfgNode call , DataFlow:: Node uploadToArg , Function func |
2652+ this .getParameter ( ) = func .getArg ( 1 ) and
2653+ call = DjangoImpl:: DB:: Models:: FileField:: subclassRef ( ) .getACall ( ) and
2654+ uploadToArg in [ call .getArg ( 2 ) , call .getArgByName ( "upload_to" ) ] and
2655+ uploadToArg = poorMansFunctionTracker ( func )
2656+ )
2657+ }
2658+
2659+ override string getSourceType ( ) {
2660+ result = "django filename parameter to function used in FileField.upload_to"
2661+ }
2662+ }
2663+
26022664 // ---------------------------------------------------------------------------
26032665 // django.shortcuts.redirect
26042666 // ---------------------------------------------------------------------------
0 commit comments