Skip to content

Limit choices for related foreign key fields based on view queryset. #1906

Closed
@erikcw

Description

@erikcw

I was just doing some experimenting with DRF and found a potential security issue (information leak).

The generated forms in the Browseable API for ForeignKey fields should limit the displayed choices to the related field's ViewSet.queryset.

Currently, If a ViewSet filters its queryset to prevent users from accessing objects they don't own like so:

MyViewSet(ViewSet):
    #...
    def get_queryset(self, queryset, *args, **kwargs):
       return queryset.filter(user=self.request.user)

the user will only be able to access those objects. However, the select list in the Browseable API form will display objects belonging to all users.

Ideally this would hook into permission_classes and filter_backends as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions