Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Logout user when their activated status is switched to off #10876

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

snipe
Copy link
Owner

@snipe snipe commented Mar 29, 2022

Hey nerds,

This PR fixes a potential issue in business logic where when a user's status is toggled from activated to deactivated (and therefore should not be able to be logged in anymore). While we would disallow the user from ever logging in again if that flag is toggled, we weren't checking on their activated status on page load (via middleware for example), so a user who had an existing active session could still potentially see things that should be gated behind an activated user account.

This could normally be mitigated by using the KillAllSessions console command, clearing the contents of the storage/framework/sessions directory, or changing the cookie name, but all of those options logout ALL users, which could be kind of annoying.

This fixes https://huntr.dev/bounties/ebc26354-2414-4f72-88aa-f044aec2b2e1/ (which may not be visible until the CVE is publicly issued.)

We've tested this locally and I think it should be good to go, but always appreciate extra eyeballs. TY!

Signed-off-by: snipe <snipe@snipe.net>
Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really solid! I know it sucks to be messing with Auth because it's so scary, but it's also awesome to know that our stuff is buttoned-up really well. And I think because all the other login methods check the Activated flag, that I'm comfortable that this change will probably not start locking out users or causing any kind of ruckus. Nice work and really clean way of handling the problem, love it :)

@@ -3,7 +3,7 @@
return array(

'account_already_exists' => 'An account with the this email already exists.',
'account_not_found' => 'The username or password is incorrect.',
'account_not_found' => 'The username or password is incorrect or this user is not approved to login.',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UGH - I hate to have to re-do a string this way, but I can totally see why we would.

// to inactive (aka unable to login)
if (($request->user()) && (!$request->user()->isActivated())) {
Auth::logout();
return redirect()->guest('login');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't know this ->guest() method but so long as that takes you to /# that's good enough for me!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a built-in laravel-ism that still applies middleware (like CSRF protection, etc) but doesn't apply the auth routes.

@snipe snipe merged commit d56552a into master Mar 29, 2022
@snipe snipe deleted the fixes/huntr_ebc26354_logout_user_when_deactivated branch March 29, 2022 14:57
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants