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

Revoke all authorized applications on password reset #21325

Merged

Conversation

FrancisMurillo
Copy link
Contributor

@FrancisMurillo FrancisMurillo commented Nov 21, 2022

Clear all user sessions after a successful password reset if this is the desired behavior. I noticed that User::reset_password! is not really being invoked by the password reset flow so I am not sure if this is intentional as the tests are working as well. I would also like to add a controller test for this behavior but would need some guidance.

For change password, the behavior is the same and may not clear the sessions except the current. So this might also be considered.

Steps I took when I tested with my instance:

  1. Login with the Mastodon iOS client
  2. Login with the Web interface
  3. Complete reset password with another browser
  4. Refreshing on iOS client should return token revoked message
  5. Refreshing on Web interface should return to start page

@@ -373,6 +373,15 @@ def reset_password(new_password, new_password_confirmation)
super
end

def clear_sessions!
Copy link
Member

Choose a reason for hiding this comment

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

This name feels a little misleading, given that what it's really doing is removing/revoking authorised applications and push subscriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions for a clearer name?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe revoke_access?

Copy link
Contributor

Choose a reason for hiding this comment

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

revoke_tokens would be even more explicit, I think

Copy link
Member

Choose a reason for hiding this comment

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

I considered that, but it's also revoking access grants and deleting push subscriptions.

Maybe that's implementation detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I refactor this method to also delete session_activations if it was used for change password, would the original name be more helpful?

@ClearlyClaire
Copy link
Contributor

Thank you for your contribution! I don't think it's addressing #20431 as this issue was explicitly about /auth/edit, which is different from the password reset flow, but this is not necessarily a problem (apart from incorrectly marking #20431 as resolved).

I am not completely sure we want that behavior, especially since current apps handle revoked tokens quite poorly (see #20431 (comment)) but I understand the reasoning, and I think revoking tokens in the password reset flow as addressed in this PR would cause less issue than doing it in the /auth/edit flow.

I noticed that User::reset_password! is not really being invoked by the password reset flow so I am not sure if this is intentional as the tests are working as well.

The password reset is taken care of by Devise::PasswordsController#update which is called through the super call. The block is then executed right after that. I think not calling reset_password! here is intentional.

I would also like to add a controller test for this behavior but would need some guidance.

That would be great! This would be a new describe block for POST #update in spec/controllers/auth/passwords_controller_spec.rb. You could read the tests for #reset_password! in spec/models/user_spec.rb for inspiration.

@FrancisMurillo
Copy link
Contributor Author

I started with the password reset to understand if this behavior is acceptable which I was hoping then to reuse for change password without removing the current session that is. If this behavior is currently not desired, I will remove marking the issue resolved. For now, will just add the controller test.

Comment on lines 87 to 89
it 'returns http success' do
expect(response).to have_http_status(200)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that actually the expected behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point. So I changed the test expectation to redirection on success and render a error template on failure which might be better.

@FrancisMurillo FrancisMurillo force-pushed the fix-clear-sessions-on-password-change branch from 2a7b4fa to ace0341 Compare November 23, 2022 01:38
@mastodon mastodon deleted a comment Nov 23, 2022
@ineffyble ineffyble added the security Security issues and fixes, vulnerabilities label Nov 24, 2022
@ineffyble
Copy link
Member

@FrancisMurillo your commits are showing up as Unverified, as you've requested GitHub to require GPG signing for your account. Can you look into this?

@FrancisMurillo FrancisMurillo force-pushed the fix-clear-sessions-on-password-change branch from ace0341 to 2a57e6e Compare November 24, 2022 15:35
@FrancisMurillo
Copy link
Contributor Author

@ineffyble Was able to finally recover my keys and gpg sign the commits so they are now marked as verified.

@Gargron Gargron changed the title Clear all sessions on password reset Revoke all authorized applications on password reset Dec 15, 2022
@Gargron Gargron merged commit 5fb1c3e into mastodon:main Dec 15, 2022
neatchee pushed a commit to neatchee/mastodon that referenced this pull request Dec 16, 2022
* Clear sessions on password change

* Rename User::clear_sessions to revoke_access for a clearer meaning

* Add reset paassword controller test

* Use User.find instead of User.find_for_authentication for reset password test

* Use redirect and render for better test meaning in reset password

Co-authored-by: Effy Elden <effy@effy.space>
nametoolong pushed a commit to nametoolong/nuage that referenced this pull request Jan 12, 2023
* Clear sessions on password change

* Rename User::clear_sessions to revoke_access for a clearer meaning

* Add reset paassword controller test

* Use User.find instead of User.find_for_authentication for reset password test

* Use redirect and render for better test meaning in reset password

Co-authored-by: Effy Elden <effy@effy.space>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Security issues and fixes, vulnerabilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants