Skip to content

User.validatePassword throws uncaught exception in User.create #1364

Closed

Description

@cleas

related to #941

Creating user with empty password : loopback@2.8 user created , loopback@2.9 application crash due to uncaught exception

User.create({username: 'John', email: 'john@doe.com', password:''},function(err,user){
//invalid password error should be returned in callback
 });

overriding validatePassword to check for minimum length will also give uncaught exception

see also example https://github.com/cleas/loopback-sandbox
https://github.com/cleas/loopback-sandbox/blob/master/server/boot/create-model-instances.js

Activity

  1. self-assigned this
    on Jul 7, 2015
  2. superkhau commented on Jul 7, 2015

    @superkhau
    Contributor

    I tried running your example. I get:

    Error: Invalid password:
      ...
    

    Seems like this is fixed in the latest LoopBack. Can you confirm so I close this?

  3. cleas commented on Jul 7, 2015

    @cleas
    Author

    I tried with loopback 2.18.0 => error is still there.
    looking at the source nothing changed to User.hashPassword and User.validatePassword.
    function User.validatePassword can throw exception , this exception is not handled in UserModel.setter.password

  4. rawrmaan commented on Jul 9, 2015

    @rawrmaan

    I'm having this issue as well. I overrode validatePassword in my own User model subclass and used the default implementation as a reference. Now my instance crashes whenever there's an invalid password. Should I just return false instead of throwing an error?

  5. jlvdh commented on Sep 1, 2015

    @jlvdh

    I also encountered this, and used the following as a quickfix in user.js

    User.observe('before save', function checkEmptyPasswordString(ctx, next) {
      if (ctx.data && ctx.data.password === '') {
        next('Password is empty string');
      }
      next();
    });
    
  6. superkhau commented on Sep 1, 2015

    @superkhau
    Contributor

    @cleas Are you still running into issues? Seems to be fixed by #941 now as I can't reproduce the error in your loopback-sandbox for anymore.

  7. jlvdh commented on Sep 2, 2015

    @jlvdh

    I'm still experiencing the error on Loopback 2.21.0 with the following request:

    PUT /user
    
    {"id":140, "password":""}
    
  8. cleas commented on Sep 2, 2015

    @cleas
    Author

    The error in the loopback-sandbox example is now catched due to the changes in commit:

    loopbackio/loopback-datasource-juggler@21c0067
    "Report deferred exceptions via callback"

    But still validatePassword exceptions are not caught in User.create function it self and returned in cb.
    For example if the create functions are wrapped in a dataSource.autoupdate function, the application crashes.
    see updated loopback-sandbox example. cleas/loopback-sandbox@fd0fd33

  9. removed their assignment
    on Sep 21, 2015
  10. 23 remaining items

  11. dhmlau commented on Jul 20, 2017

    @dhmlau
    Member

    UPDATE: Nevermind, the problem still exists in updateAttribute.

    I'm not sure if this is still an issue. Using loopback@2.38.24, if i set the password to empty string, the error code is INVALID_PASSWORD.

    Here is what I've tried:
    boot/test.js:

    module.exports = function(app) {
      var user = app.models.User;
      user.create({email: 'aa@ca.ibm.com', password: ''}, (err, result)=> {
        if (err) {
          console.log('err.code = ', err.code);
          console.log(err);
        }
        console.log('result = ', result);
      });
    };
    

    Output:

    err.code =  INVALID_PASSWORD
    { [Error: Invalid password: ] code: 'INVALID_PASSWORD', statusCode: 422 }
    
  12. loay commented on Jul 21, 2017

    @loay
    Contributor

    Issue is fixed for all Loopback 2.x.x versions.

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