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

Use a new column to log users via RememberMe, so we can force user to re-login from the application #721

Open
calcosta opened this issue Sep 27, 2018 · 7 comments
Labels

Comments

@calcosta
Copy link

We just had the situation, that a user account had to stay in the database, but had to be deactivated.

So we destroyed the user PHP Session and deactivated the user.
However the remember_me cookie of the users browser authenticated the user and he got a new, valid session and stayed logged in.

It seems thats because the remember_me cookie stores the users ID and authenticates the user if there is one in the database with the ID from the cookie.

Isn't it possible to check wether the user account is active when he is authenticated using the remember_me cookie?

Maybe it is better to use a random hash that is saved in the database and the rememberMe cookie to authenticate the user instead of just the ID? That would also give us the possibility to remotely invalidate the rememberMe cookie.

@steinkel
Copy link
Member

steinkel commented Oct 4, 2018

  • RememberMeAuthenticate is calling $this->_findUser($cookie['id']) so your finder/scope would be in effect, did you add the 'active' condition to the users finder?
  • Another way to fix this behaviour would be using the EVENT_AFTER_COOKIE_LOGIN to double check the user should have logged in.

I agree we could improve the cookie storage, using a random hash instead of the user id, allowing you to clear it to force users to re-login. This use case could be useful, for example for requesting acceptance of new terms of service, etc

@calcosta
Copy link
Author

calcosta commented Oct 4, 2018

Thanks for your solutions.
I solved it using a separate Authorize class that runs before the users plugin:

Configure::write('Auth.authorize', [
    'ForceLogout',
    'CakeDC/Auth.Superuser',
    'CakeDC/Auth.SimpleRbac',
]);

That class checks if a user is active. If not, he is logged out and redirected to the login page.

Using a random hash could also improve security as it prevents a user from faking another users's rememberme cookie if its user-id is known?!

@steinkel
Copy link
Member

steinkel commented Oct 4, 2018

Security issue is not a problem, as the id is encrypted by the server and even if the user know another user's id, he won't be able to inject the correctly encrypted value.

@calcosta
Copy link
Author

calcosta commented Oct 4, 2018

Security issue is not a problem, as the id is encrypted by the server and even if the user know another user's id, he won't be able to inject the correctly encrypted value.

Ok, I wasn't sure about how/if the cookie is encrypted. Thanks!

@steinkel
Copy link
Member

steinkel commented Oct 4, 2018

I'll update this ticket a bit to take note of your suggested feature, thanks!

@steinkel steinkel changed the title Allow remote user logout with rememberMe cookie Use a new column to log users via RememberMe, so we can force user to re-login from the application Oct 4, 2018
@calcosta
Copy link
Author

calcosta commented Oct 4, 2018

To force a re-login (invalidate rememberme cookie and current session) it might also be useful, to store the current PHP session-ID in the database (if file-based session handling is used). This helps to invalidate the PHP session quickly.

@ajibarra
Copy link
Member

@steinkel is this still valid? Should we fix it?

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

No branches or pull requests

3 participants