Skip to content

Commit

Permalink
Remove files/get endpoint which is not used (#5109)
Browse files Browse the repository at this point in the history
* remove `files/get` endpoint

* Update nautobot/core/tests/test_views.py

Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>

* update based on review

---------

Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
  • Loading branch information
gertzakis and glennmatthews committed Jan 17, 2024
1 parent 747167d commit fe5658c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
1 change: 1 addition & 0 deletions changes/5109.security
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed `/files/get/` URL endpoint (for viewing FileAttachment files in the browser), as it was unused and could potentially pose security issues.
39 changes: 12 additions & 27 deletions nautobot/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,30 +424,21 @@ def setUp(self):
self.file_proxy_1 = FileProxy.objects.create(name=self.test_file_1.name, file=self.test_file_1)
self.test_file_2 = SimpleUploadedFile(name="test_file_2.txt", content=b"I am content.\n")
self.file_proxy_2 = FileProxy.objects.create(name=self.test_file_2.name, file=self.test_file_2)
self.urls = [
f"{reverse('db_file_storage.download_file')}?name={self.file_proxy_1.file.name}",
f"{reverse('db_file_storage.get_file')}?name={self.file_proxy_1.file.name}",
]
self.url = f"{reverse('db_file_storage.download_file')}?name={self.file_proxy_1.file.name}"

def test_get_file_anonymous(self):
self.client.logout()
for url in self.urls:
with self.subTest(url):
response = self.client.get(url)
self.assertHttpStatus(response, 403)
response = self.client.get(self.url)
self.assertHttpStatus(response, 403)

def test_get_file_without_permission(self):
for url in self.urls:
with self.subTest(url):
response = self.client.get(url)
self.assertHttpStatus(response, 403)
response = self.client.get(self.url)
self.assertHttpStatus(response, 403)

def test_get_object_with_permission(self):
self.add_permissions(get_permission_for_model(FileProxy, "view"))
for url in self.urls:
with self.subTest(url):
response = self.client.get(url)
self.assertHttpStatus(response, 200)
response = self.client.get(self.url)
self.assertHttpStatus(response, 200)

def test_get_object_with_constrained_permission(self):
obj_perm = ObjectPermission(
Expand All @@ -458,14 +449,8 @@ def test_get_object_with_constrained_permission(self):
obj_perm.save()
obj_perm.users.add(self.user)
obj_perm.object_types.add(ContentType.objects.get_for_model(FileProxy))
for url in self.urls:
with self.subTest(url):
response = self.client.get(url)
self.assertHttpStatus(response, 200)
for url in [
f"{reverse('db_file_storage.download_file')}?name={self.file_proxy_2.file.name}",
f"{reverse('db_file_storage.get_file')}?name={self.file_proxy_2.file.name}",
]:
with self.subTest(url):
response = self.client.get(url)
self.assertHttpStatus(response, 404)
response = self.client.get(self.url)
self.assertHttpStatus(response, 200)
url = f"{reverse('db_file_storage.download_file')}?name={self.file_proxy_2.file.name}"
response = self.client.get(url)
self.assertHttpStatus(response, 404)
6 changes: 0 additions & 6 deletions nautobot/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@
{"add_attachment_headers": True},
name="db_file_storage.download_file",
),
url(
"files/get/",
get_file_with_authorization,
{"add_attachment_headers": False},
name="db_file_storage.get_file",
),
]


Expand Down

0 comments on commit fe5658c

Please sign in to comment.