Skip to content

Tighten security for resetting password #382

Closed

Description

@offlinehacker

With POST /user/{id} user can change password without of presence of old password. This is security problem, because anyone who stoles any valid access token from user can change users password.

Tasks

  • Only allow resetPassword by email if email verification is required and done.
  • Provide a solution to finish the user's registration when the email verification token has expired #3303 - Provide solution for finishing the registration when the verification link was not followed (opened) before it has expired.
  • Add a new method, let's call it User.changePassword(id, oldPassword, newPassword, cb). This method should have ACLs configured to allow only the owner to execute it (i.e. users can change only their own passwords) - see Add User.changePassword(id, old, new, cb) #3299
  • Scope the password-reset token so that it allows only changing User's password and nothing else. Regular access tokens must not allow changing User's password without providing the old one.
    Save the password-reset token the same way as the verification token i.e. with the user. That way you would know with which token you can change the password without knowing your old one. It would also mean that if you request another password reset it would delete/invalidate the previous token so that at max only one can be active at one time. Because the current implementation relies on the client to call updateAttributes with a temporary access token, I think we will need to implement a new method similar to User.changePassword that will accept the new reset-token instead of the old password.
  • Set password with token, disable password changes via patch/replace #3350 - Disable changing the password property via other methods. To preserve backwards-compatibility, there should be a feature flag controlling this behaviour.

Next

Activity

  1. raymondfeng commented on Jul 19, 2014

    @raymondfeng
    Member

    Good catch. We already have code to protect emailVerified flag. It should apply to password too.

    See https://github.com/strongloop/loopback/blob/master/lib/models/user.js#L443.

    Would you like to submit a patch?

  2. offlinehacker commented on Jul 19, 2014

    @offlinehacker
    ContributorAuthor

    The problem here is that on password reset you get normal short lived token, that you can't distinct from other tokens and at the same time you can't require old password on password reset, also having another view is a security issue. My proposal would be to tag tokens or is there any better idea?

  3. TFaga commented on Jul 19, 2014

    @TFaga

    Another idea would be to save it the same way as the verification token i.e. with the user. That way you would know with which token you can change the password without knowing your old one. It would also mean that if you request another password reset it would delete/invalidate the previous token so that at max only one can be active at one time.

  4. karlmikko commented on Jul 20, 2014

    @karlmikko

    @TFaga you want to be able to multiple tokens active at once. As a single user may be logged into a service from multiple locations (mobile, web, desktop app).

  5. karlmikko commented on Jul 20, 2014

    @karlmikko

    @offlinehacker you would want the token to stay valid, even if the password changes. As you if you change the password you would still want your moblie device to stay active.

    Github manage this by being able to see what tokens are currently valid/active. Then the user can choose to remove the tokens to force that device to re-authenticate.

  6. offlinehacker commented on Jul 20, 2014

    @offlinehacker
    ContributorAuthor

    @karlmikko why wouldn't they, in loopback tokens are randomly generated and unrelated to password. Most general solution would be to have tokens with the scope where they can be used(verify,reset,auth).

  7. offlinehacker commented on Jul 20, 2014

    @offlinehacker
    ContributorAuthor

    @karlmikko And multiple tokens are already active at once

  8. TFaga commented on Jul 20, 2014

    @TFaga

    @karlmikko Yes of course that functionality would remain unchanged. The problem is that when you request for a password reset it generates a normal (however short lived) token with which you can then do anything. However if the user model is changed so that you need to provide your current password when changing it you cannot reset your password with this method anymore (which is OK, you shouldn't be able to change your password without your current one). I currently see two ways to fix this issue (also using your password reset token, you should only be allowed to change your password and do nothing else - not the case now):

    1. Don't save the password reset token as a normal one, instead save it the same way as the verification token, that way you would know what is it for. Also would mean that only one can be active at any time (not unreasonable), however you would need to save an expire date, which could prove to be a bit annoying.

    2. Save all the tokens (normal, reset, verify) in the accessToken collection/table and add a type field to every token (possible values: reset, verify, auth as stated by @offlinehacker ), so that you know exactly what it's for and as such decide what the user can or cannot do with it (eg. token with type reset can only reset password, same for verify, ...). It would require a bit more change however I still think it's not that much actually and it would be a more general solution that nr. 1.

    Of course there might be somethings I missed.

  9. raymondfeng commented on Jul 20, 2014

    @raymondfeng
    Member

    Great discussions!

    The access token model will be aligned with oAuth 2.0. It will have a scopes properties to represent the granted permissions. The access token will also have more identities, such as clientId (client application) and user id (resource owner). The oAuth 2.0 integration is under development. In the interim, we can start with an enhanced access token model.

  10. offlinehacker commented on Aug 5, 2014

    @offlinehacker
    ContributorAuthor

    Why was this one closed?
    On Aug 5, 2014 7:56 PM, "Al Tsang" notifications@github.com wrote:

    Closed #382 #382.

    —
    Reply to this email directly or view it on GitHub
    #382 (comment).

  11. altsang commented on Aug 5, 2014

    @altsang
    Contributor

    same thing here - I'm trying to clean up issues, I've labelled so I can track and closed them if there isn't further action/discussion at this moment

  12. reopened this on Aug 5, 2014
  13. 72 remaining items

  14. bajtos commented on Apr 27, 2017

    @bajtos
    Member

    All tasks listed in the issue in the issue description were landed and released in loopback@3.7.0. I am going to close this issue as resolved. See #3349 for the issue/task tracking update of documentation, examples and project templates. Help is welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions