Logout inactive user
See original GitHub issueDescribe the bug
The @login_required
decorator does not check if a user is active. I’m not sure if this was a design choice, but intuitively I would expect to be able to log a user out by deactivating it.
To Reproduce Steps to reproduce the behavior:
- Create a user
- Login with that user
- Set
user.is_active = False
- User is still able to access view decorated with
@login_required
Expected behavior
Intuitively I would expect this line in the @login_required
decorator
elif not current_user.is_authenticated:
return current_app.login_manager.unauthorized()
to read
elif not (current_user.is_authenticated and current_user.is_active):
return current_app.login_manager.unauthorized()
Screenshots NA
Desktop (please complete the following information):
- OS: N/A
- Browser [e.g. chrome, safari]: N/A
- Version [e.g. 22]: 0.4.1 (I think it came as a dependency from
flask-security
)
Additional context
Again, not sure whether it is a genuine bug or a misunderstanding from my side.
We could get around it on our side by overriding user.is_authenticated
in our User
class to return super().is_authenticated and self.is_active
.
Addressed in #489
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
Inactive Logout – WordPress plugin
Use the Inactive Logout plugin to automatically terminate idle user sessions, thus protecting the site if the users leave unattended sessions.
Read more >How to detect inactive user to auto logout by using idle timeout ...
How to detect inactive user to auto logout by using idle timeout in JavaScript, React, Angular and more? · Step 1: Create user...
Read more >Auto Logout Inactive Users After A Period Of Time In Linux
Method 1: ... This makes the user to logout automatically after an inactivity of 100 seconds. You can define this value as per...
Read more >How to Automatically Log Out Idle Users in WordPress
The first thing you need to do is install and activate the Inactive Logout plugin. For more details, see our step by step...
Read more >How to Automatically Logout Inactive Linux Users
Method 1: Use TMOUT to auto logout users from idle shell sessions. In bash and other shells, you can use the TMOUT variable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If
@login_required
checks theUser.is_active
property it leads people to not checkis_active
in theiris_authenticated
method. That leads to inactive users still able to access resources requiring login when manually checkingcurrent_user.is_authenticated
. Instead, we’ll update UserMixin.is_authenticated to:Setting a logged-in user inactive is meaningless.
is_active = False
prevents inactive users from logging in, andlogin_user()
is doing the job.To inactivate an already logged-in user, logout first, and then set
is_active = False
to prevent it from logging in again.