-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
[6.x] Re-work super user authorization check #11516
base: master
Are you sure you want to change the base?
Conversation
…tatamic permission
Otherwise, when the `Authorize` middleware checks if the user has access to the CP, `Permission:all()` in the `Gate::before()` closure won't return any permissions as they haven't been booted yet.
Until I figure out a better solution. 🤔
Since there's no `DroidsClass` policy, I've updated this test to authorize using a permission instead, which'll work.
@@ -84,7 +85,13 @@ public function boot() | |||
}); | |||
|
|||
Gate::before(function ($user, $ability) { | |||
return optional(User::fromUser($user))->isSuper() ? true : null; | |||
Permission::boot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think this approach is broadly on the right track, I don't really want to be booting permissions here. Although, I'm not sure what the best alternative is... 🤔
- Without booting permissions here, users can't access the CP because the
Authorize
middleware checks if the user has the relevant permissions, however it happens before theBootPermissions
middleware is called. - We can't reorder the middleware, otherwise it might cause issues with translations in permission labels, which Ability to defer permission and utility registration for translations #7343 solved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with booting in there? It only happens when the closure is executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was just thinking it was weird since we're already booting them in a middleware, and that trying to boot them multiple times would hurt performance?
Maybe I'm wrong though, and it's fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make Permissions::boot()
return early and do nothing if it's already been booted once.
This pull request attempts to fix an issue with how super users are authorized in Statamic.
Currently, when an authorization check is performed against a super user, authorization will be granted. This is obviously far from ideal, especially when you're integrating Statamic as part of an existing Laravel application.
This PR aims to fix this issue by only granting authorization when we know the ability/permission "belongs" to Statamic.
Closes #8337.
Closes #10832.