Remove users refresh tokens when the user get's deactivated#159443
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a security issue by ensuring that when a user is deactivated, all their refresh tokens are immediately removed, preventing them from maintaining active sessions. This is a bugfix that enhances security by ensuring deactivated users lose access immediately.
Key changes:
- Added automatic refresh token cleanup when users are deactivated
- Added comprehensive test coverage for the new behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/auth/__init__.py |
Adds logic to iterate through and remove all refresh tokens when a user is deactivated |
tests/auth/test_init.py |
Adds test case verifying that deactivating a user removes all their refresh tokens |
After reviewing the code changes, I found no issues to report. The implementation is well-done and follows Home Assistant best practices:
✅ Correct iteration pattern: Uses list(user.refresh_tokens.values()) to create a snapshot before iteration, preventing modification-during-iteration errors
✅ Proper method usage: Calling the @callback decorated async_remove_refresh_token method from an async function is acceptable in Home Assistant
✅ Comprehensive testing: The test validates all expected behavior including user deactivation, token removal from both user object and manager, and handling of multiple tokens
✅ Security improvement: This change enhances security by ensuring deactivated users immediately lose all active sessions
✅ Consistent patterns: The implementation follows existing patterns in the auth manager (similar to how async_remove_user handles credentials removal)
The code is ready for merge.
Breaking change
Proposed change
Remove users refresh tokens when the user get's deactivated
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: