Skip to content
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

_checkperm calls has_perm prematurely #4

Open
DylanYoung opened this issue Jun 19, 2019 · 2 comments
Open

_checkperm calls has_perm prematurely #4

DylanYoung opened this issue Jun 19, 2019 · 2 comments

Comments

@DylanYoung
Copy link

_check_perm calls has_perm first. This is a but of an annoyance in our use-case as we log missing permissions in our has_perm implementation. It also seems unnecessary since we know what a valid permission looks like.

    def _checkperm(user, perm):
        return (user.has_perm(perm)
                or (perm == 'is_authenticated' and user.is_authenticated())
                # Handles, say, is_staff; insist on True so that we
                # don't inadvertently match a function.
                or (True == getattr(user, perm, None)))

Minimal A/C:

  • If a permission contains a dot/period then check has_perm
  • else do the attribute check

An alternative that might be marginally more efficient and definitely more safe would be a whitelist of attributes that can be used by the PermissionRequired Middleware.

@DylanYoung
Copy link
Author

@wolfe Thoughts on the proposed implementations? I'm partial to the whitelist...

@wolfe
Copy link
Owner

wolfe commented Jun 23, 2019

No opinion here... it's been too long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants