-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using default queryset is insecure when filtering across relationships #100
Comments
This also leaks information in the rendered form, as the dropdown for the |
It should be documented that a My recommendation would be to write queryset methods that provides the set of objects that a user should have read access to, then use that queryset method where necessary. e.g., # Get authors/books for which users have read permissions
class AuthorQuerySet(models.QuerySet):
def for_user(self, user):
return self.filter(something=user)
class BookQuerySet(models.QuerySet):
def for_user(self, user):
return self.filter(something=user)
# filters
class AuthorFilterSet:
...
class BookFilterSet:
author = RelatedFilter(queryset=Author.objects.for_request)
...
# views
class AuthorViewSet:
filterset_class = AuthorFilterSet
def get_queryset(self):
return Author.objects.for_request(self.request)
class BookViewSet:
filterset_class = BookFilterSet
def get_queryset(self):
return Book.objects.for_request(self.request) |
@rpkilby when using related filter I can pass a queryset to it and it works. Like this for example:
So I think this issue is resolved and can be closed, what do you think? |
Hi @sassanh. Thanks - this is more a reminder that the docs need to be updated to better inform the user on how to use |
Filtering across relationships currently uses the default queryset. For example:
While you're not able to view unpublished posts of other authors, you are able to filter across the relationship and derive that an author may be preparing an article about some topic.
eg:
/api/authors?post__is_published=false&post__body__contains=juicy%20story%20details
The text was updated successfully, but these errors were encountered: