Skip to content

Commit 3e71d7f

Browse files
committed
Python: Add note about / for Django upload_to
I did a test locally, something like import requests req = requests.Request( "POST", "http://127.0.0.1:8000/app/upload-test/", data={"name": "foo"}, files={"upload" : ("wat/haha|!#$%^&", open("foo.txt", "rb"))}, ) # print(req.prepare().body.decode('ascii')) requests.session().send(req.prepare()) and the `wat/` part was stripped from the filename
1 parent f962d8e commit 3e71d7f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

python/ql/lib/semmle/python/frameworks/Django.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,6 +2272,12 @@ module PrivateDjango {
22722272
* A parameter that accepts the filename used to upload a file. This is the second
22732273
* parameter in functions used for the `upload_to` argument to a `FileField`.
22742274
*
2275+
* Note that the value this parameter accepts cannot contain a slash. Even when
2276+
* forcing the filename to contain a slash when sending the request, django does
2277+
* something like `input_filename.split("/")[-1]` (so other special characters still
2278+
* allowed). This also means that although the return value from `upload_to` is used
2279+
* to construct a path, path injection is not possible.
2280+
*
22752281
* See
22762282
* - https://docs.djangoproject.com/en/3.1/ref/models/fields/#django.db.models.FileField.upload_to
22772283
* - https://docs.djangoproject.com/en/3.1/topics/http/file-uploads/#handling-uploaded-files-with-a-model

0 commit comments

Comments
 (0)