diff --git a/HISTORY.rst b/HISTORY.rst index 75e7a307..f4d3d7cd 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,10 @@ This project adheres to `Semantic Versioning `_. Unreleased =========================== +* **Security fix.** ``connections/create_upload/`` had no permission check, so anyone, including + anonymous visitors, could load the upload page and see the list of uploaded database aliases and + ids. It now requires ``EXPLORER_PERMISSION_CONNECTIONS`` like the rest of the connection views. + * `#722`_: The query list (home page) no longer loads the entire query log history on every view. Run counts and last runs are computed in SQL, so the page stays fast as logs accumulate (300k logs: ~9.7s -> ~0.9s). The query list and query log pages also no longer run an extra database query per row. diff --git a/explorer/ee/db_connections/views.py b/explorer/ee/db_connections/views.py index 1b34e6a4..8ab58608 100644 --- a/explorer/ee/db_connections/views.py +++ b/explorer/ee/db_connections/views.py @@ -101,7 +101,8 @@ class DatabaseConnectionCreateView(PermissionRequiredMixin, ExplorerContextMixin success_url = reverse_lazy("explorer_connections") -class DatabaseConnectionUploadCreateView(TemplateView): +class DatabaseConnectionUploadCreateView(PermissionRequiredMixin, ExplorerContextMixin, TemplateView): + permission_required = "connections_permission" template_name = "connections/connection_upload.html" def get_context_data(self, **kwargs): diff --git a/explorer/tests/test_views.py b/explorer/tests/test_views.py index 87d94354..764bfb3e 100644 --- a/explorer/tests/test_views.py +++ b/explorer/tests/test_views.py @@ -1275,6 +1275,20 @@ def setUp(self): port="" ) + def test_database_connection_upload_view_requires_permission(self): + self.client.logout() + response = self.client.get(reverse("explorer_upload_create")) + self.assertTemplateUsed(response, "admin/login.html") + + def test_database_connection_upload_view_hides_connections_from_unauthorized_users(self): + self.client.logout() + response = self.client.get(reverse("explorer_upload_create")) + self.assertNotContains(response, "test_alias") + + def test_database_connection_upload_view_allows_staff(self): + response = self.client.get(reverse("explorer_upload_create")) + self.assertEqual(response.status_code, 200) + def test_database_connection_detail_view(self): response = self.client.get(reverse("explorer_connection_detail", args=[self.connection.pk])) self.assertEqual(response.status_code, 200)