-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
IsAdminUser class allows users without authentication to access objects (security issue) #7720
Comments
You should user
|
Actually |
Actually I agree that this implementation is counterintuitive. I think most people would expect |
I think it is not the fault of the
I agree that the default BasePermission should return False, this is meaningfull and more safe. But this will create a huge break change for many people. Maybe some global settings like |
The question being asked is "Should permission be granted". If the job of a |
I think the problem might be in the E.g. To make class OR:
def __init__(self, op1, op2):
self.op1 = op1
self.op2 = op2
def has_permission(self, request, view):
return (
self.op1.has_permission(request, view) or
self.op2.has_permission(request, view)
)
def has_object_permission(self, request, view, obj):
# Previous
# return (
# self.op1.has_object_permission(request, view, obj) or
# self.op2.has_object_permission(request, view, obj)
# )
# New
return (
(
self.op1.has_permission(request, view) and # True only for staff
self.op1.has_object_permission(request, view, obj) # True for all objects
) or (
self.op2.has_permission(request, view) and # True for all users
self.op2.has_object_permission(request, view, obj) # Only True for MyCustomPermission
)
) |
Closing as a duplicate. Thanks @MattFisher |
Checklist
master
branch of Django REST framework.Steps to reproduce
Create a simple view with such code:
Try to open this view not using authentication at all (without authentication token).
Expected behavior
Actual behavior
IsAdminUser always returns True on
has_object_permission
.Actually it works as intended after I added
into
MyCustomPermission
. MaybeBasePermission
shouldn't return True at every request?The text was updated successfully, but these errors were encountered: