-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(security) Fix: Privilege Escalation Vulnerability in reNgine
- Loading branch information
Showing
6 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rest_framework.permissions import BasePermission | ||
from rest_framework.exceptions import PermissionDenied | ||
from rolepermissions.checkers import has_permission | ||
|
||
class HasPermission(BasePermission): | ||
""" | ||
This is a custom permission class for DRF that checks if the user | ||
has the required permission. | ||
Usage in drf views: | ||
permission_classes = [HasPermission] | ||
permission_required = PERM_MODIFY_SCAN_CONFIGURATIONS | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
permission_code = getattr(view, 'permission_required', None) | ||
if not permission_code: | ||
raise PermissionDenied(detail="Permission is not specified for this view.") | ||
|
||
if not has_permission(request.user, permission_code): | ||
raise PermissionDenied(detail="This user does not have enough permissions") | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters