From 5ef9972f266abedbaa910b1f7f5f802c8b9445bd Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Thu, 29 Oct 2026 09:14:39 -0400 Subject: [PATCH] Require connections permission on the upload page DatabaseConnectionUploadCreateView was the one view in this module without PermissionRequiredMixin, so anyone who could reach the URL -- including an anonymous visitor -- got the upload form back with a 200. The template renders valid_connections, the list of uploaded SQLite connections, so it also disclosed the alias and id of every user's uploaded database. Those ids are the values UploadDbView accepts as "append". The POST that actually uploads is guarded, so this was disclosure rather than an upload path; still, it was the upload flow's entry point and every sibling view requires connections_permission. Added ExplorerContextMixin alongside the permission mixin, matching the other connection views, so the page is rendered with the same context (can_manage_connections and friends) rather than silently missing it. --- HISTORY.rst | 4 ++++ explorer/ee/db_connections/views.py | 3 ++- explorer/tests/test_views.py | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) 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)