-
Notifications
You must be signed in to change notification settings - Fork 133
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
Fix: groups and permissions filter redirects #589
Fix: groups and permissions filter redirects #589
Conversation
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.
Thanks for your report. I confirm this bug.
I think that if the user's group is deleted, we should completely logout
the user from the system.
something like
if (auth()->loggedIn()) {
if (!auth()->user()->inGroup(...$arguments)) {
return redirect()->route('logout');
}
}
I also think this is the case for filter PermissionFilter
, which you should consider.
Edite:
The code below includes both filters (PermissionFilter
and GroupFilter
).
if (auth()->loggedIn()) {
if (!$this->isAuthorized($arguments)) {
return redirect()->route('logout');
}
}
Yes, you are correct @datamweb, I had it in mind to state it as part of my observation, but it completely skipped my mind. I'll push a commit as per you suggestion. |
On a second thought, I think the remainder of the code covers for the removed or deleted group(s)/permission(s). This covers for an authenticated user: shield/src/Filters/AbstractAuthFilter.php Lines 32 to 34 in 49887d9
This covers for both valid groups and permissions: shield/src/Filters/AbstractAuthFilter.php Lines 36 to 38 in 49887d9
And this will present a descriptive information for the user without forcing logout: shield/src/Filters/AbstractAuthFilter.php Line 47 in 49887d9
Please check again and let me know what you think. |
https://github.com/codeigniter4/shield/actions/runs/3867406237/jobs/6592163575 |
I am not sure if there is a normal use case of accessing a page without permission. |
I'm just thinking out loud. Maybe this is not related to PR. Lines 48 to 52 in 49887d9
Why don't we have these two? public array $redirects = [
'register' => '/',
'login' => '/',
'logout' => 'login',
'afterPermissionDenied' => '/',
'afterGroupDenied' => '/',
]; |
05929d1
to
5be75ac
Compare
@sammyskills It looks like you are using tag To check further, run the following command in the terminal git config --list user.name=Samuel Asor
user.email=your emaillllllllll
user.signingkey=9079CC1BED930E60
commit.gpgsign=false
tag.forcesignannotated=true If you see git config --global commit.gpgsign true But In this PR, you have two commits that you must use gpg-signing-old-commits (all commit) given below to sign them. |
@kenjis, please clarify, is this implementation what you had in mind? |
I'm okay with this implementation. |
Hi @datamweb , I've tried to follow the instruction on signing all commits, but each time I run the command, a new file opens up in my text editor and the terminal just stops. I've waited for hours, but it is still at the same spot, as if it is expecting an input. |
Which command?
I saw that it took a while for you to answer. You wait for the terminal, the terminal waits for you 😊.
The easiest way is the following, considering your lack of familiarity with git fetch upstream
git switch develop
git merge upstream/develop
git switch fix/update-groups-permissions-redirects
git branch -m fix/update-groups-permissions-redirects fix/update-groups-permissions-redirects.bk1
git switch -c fix/update-groups-permissions-redirects develop
code . After that, change git add .
git commit -m "fix: groups and permissions filter redirects"
git push -f origin fix/update-groups-permissions-redirects |
Thank you @datamweb. |
16705a2
to
98d0d04
Compare
@sammyskills thanks! |
Steps to reproduce:
What you'll notice is that the browser dies of too many redirects error. This happens because the filter is redirecting the user back to the previous page, which at this point, the user no longer has enough privileges to access it.
A real-life scenario:
A forum website with multiple groups and permissions, an admin might decide to remove a certain permission from a user or remove the user from a certain group WHILE that user might be logged in. If this user visits another page that requires the same permission or group that s/he has been stripped of, then it causes the browser to die due to too many redirects.