fix(import): enforce object-level authorization on import profiles and runs

ImportProfile and ImportRun had no owner, and neither the web views nor the
REST viewsets filtered by the requesting user, so any authenticated user could
read, edit and delete every other user's import profiles and runs
(GHSA-q668-h56g-mfp4).

- ImportProfile is now a SharedObject, with share and take-ownership views
  like transaction rules; the global unique constraint on name is dropped.
- ImportRun is now an OwnedObject owned by the uploader, so runs made with a
  shared profile stay private to whoever ran them.
- Existing runs are backfilled with the owner of their imported
  transactions; existing profiles stay unowned and usable by everyone.
This commit is contained in:
Herculino Trotta committed 2026-10-24 13:26:37 -03:00
1 parent 8888a850bd
commit 1e486a608e
9 files changed
+660 -15

No files matched your search

+5
View File
@@ -39,3 +39,8 @@ class ImportFileSerializer(serializers.Serializer):
queryset=ImportProfile.objects.all(), source="profile"
)
file = serializers.FileField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Reload the queryset to get an updated version with the requesting user
self.fields["profile_id"].queryset = ImportProfile.objects.all()
+7 -2
View File
@@ -37,6 +37,9 @@ class ImportProfileViewSet(viewsets.ReadOnlyModelViewSet):
ordering_fields = '__all__'
ordering = ['name']
def get_queryset(self):
return ImportProfile.objects.all()
@extend_schema_view(
list=extend_schema(
@@ -81,7 +84,7 @@ class ImportRunViewSet(viewsets.ReadOnlyModelViewSet):
ordering = ['-id']
def get_queryset(self):
queryset = super().get_queryset()
queryset = ImportRun.objects.all().order_by("-id")
profile_id = self.request.query_params.get("profile_id")
if profile_id:
queryset = queryset.filter(profile_id=profile_id)
@@ -132,7 +135,9 @@ class ImportViewSet(viewsets.ViewSet):
file_path = fs.path(filename)
# Create ImportRun record
import_run = ImportRun.objects.create(profile=profile, file_name=filename)
import_run = ImportRun.objects.create(
profile=profile, file_name=filename, owner=request.user
)
# Queue import task
process_import.defer(