From 01417172e47d8bd90e779ca3e5ae073632969a11 Mon Sep 17 00:00:00 2001 From: John Vorsten Date: Sun, 23 Feb 2020 14:01:22 -0600 Subject: [PATCH 1/3] Add compatability on windows systems A drive letter will not be prefixed onto the user specified save path. The django utility django.utils._os.safe_join is used if the operating system is not windows 'nt'. If the operating sytem is windows 'nt' then the passed name will be checked against a path style specified for the dropbox SDK. AKA the root is kept as '/' and no drive is prefixed --- storages/backends/dropbox.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index b2a0c1616..5b5affc91 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -83,7 +83,28 @@ def __init__(self, oauth2_access_token=oauth2_access_token, root_path=location, def _full_path(self, name): if name == '/': name = '' - return safe_join(self.root_path, name).replace('\\', '/') + print('Root path in dropbox.storage : ', self.root_path) + + # If the machine is windows do not append the drive letter to file path + if os.name == 'nt': + final_path = os.path.join(self.root_path, name).replace('\\', '/') + + # Separator on linux system + sep = '//' + base_path = self.root_path + + if (not os.path.normcase(final_path).startswith(os.path.normcase(base_path + sep)) and + os.path.normcase(final_path) != os.path.normcase(base_path) and + os.path.dirname(os.path.normcase(base_path)) != os.path.normcase(base_path)): + raise SuspiciousFileOperation( + 'The joined path ({}) is located outside of the base path ' + 'component ({})'.format(final_path, base_path)) + + print('Full file path in storage.dropbox._full_path : ', final_path) + return final_path + + else: + return safe_join(self.root_path, name).replace('\\', '/') def delete(self, name): self.client.files_delete(self._full_path(name)) From 572fe3af5f42fb73d7986fcee6807ad039cc1fb6 Mon Sep 17 00:00:00 2001 From: John Vorsten Date: Sun, 23 Feb 2020 14:05:16 -0600 Subject: [PATCH 2/3] Remove debug print statement --- storages/backends/dropbox.py | 1 - 1 file changed, 1 deletion(-) diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index 5b5affc91..eeefde35b 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -100,7 +100,6 @@ def _full_path(self, name): 'The joined path ({}) is located outside of the base path ' 'component ({})'.format(final_path, base_path)) - print('Full file path in storage.dropbox._full_path : ', final_path) return final_path else: From afc1e92b0db5edf4e6e30a086c8079d9f7e0139d Mon Sep 17 00:00:00 2001 From: John Vorsten Date: Sat, 29 Feb 2020 19:14:27 -0600 Subject: [PATCH 3/3] Removed unnecessary print --- storages/backends/dropbox.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/storages/backends/dropbox.py b/storages/backends/dropbox.py index eeefde35b..e00f6175b 100644 --- a/storages/backends/dropbox.py +++ b/storages/backends/dropbox.py @@ -82,9 +82,7 @@ def __init__(self, oauth2_access_token=oauth2_access_token, root_path=location, def _full_path(self, name): if name == '/': - name = '' - print('Root path in dropbox.storage : ', self.root_path) - + name = '' # If the machine is windows do not append the drive letter to file path if os.name == 'nt': final_path = os.path.join(self.root_path, name).replace('\\', '/')