Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BerkeleyTrue
Copy link
Contributor

prevent errors when plain is non-string by using call on indexOf method
closes #1437

@BerkeleyTrue
Copy link
Contributor Author

Any feedback on this?

Copy link
Member

Choose a reason for hiding this comment

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

Why do you have to the reflection api instead of plain.indexOf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1437 states that if plain is of type number indexOf breaks as it is a method on string instances. Using indexOf.call keeps this from breaking on numbers as it will cast it to string first.

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 can remove the indexOf.call if it will help move things along.

The main thing I am worried about is users who have no passwords throwing and crashing.

The indexOf call was added as a bonus as address #1437

Copy link
Member

Choose a reason for hiding this comment

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

I would rather test if typeof plain === 'string'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

like this?

if (typeof plain !== 'string') {
  return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raymondfeng I don't think this really covers our use case. Most of our users coming in through github/twitter auth, they don't set passwords. We need to make sure users who do not have passwords do not crash the site just by logging in.

I can get ride of the indexOf reflection and just set it to this:

    UserModel.setter.password = function(plain) {
      if (!plain) {
        return;
      }
      if (plain.indexOf('$2a$') === 0 && plain.length === 60) {
        // The password is already hashed. It can be the case
        // when the instance is loaded from DB
        this.$password = plain;
      } else {
        this.$password = this.constructor.hashPassword(plain);
      }
    };

This prevents crashes when plain is undefined, which is the use case I am trying to solve, but won't do anything for the case when plain is a number, which I don't really need right now.

@raymondfeng How does that sound?

Copy link
Member

Choose a reason for hiding this comment

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

The following test returns for null, undefined, and non-strings.

if (typeof plain !== 'string') {
  return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Will do.

@BerkeleyTrue
Copy link
Contributor Author

Any way we can move this along? I really don't like the idea of having to support our own fork of loopback for lack of this PR.

@BerkeleyTrue
Copy link
Contributor Author

@raymondfeng I hate to ping you directly but it is important that this fix gets in. Our development servers using loopback have shown lots of promise, but the fact that there has been no traction on this issue scares me.

If there is anything I can do to help move this along please let me know.

@BerkeleyTrue
Copy link
Contributor Author

ping @raymondfeng

@raymondfeng
Copy link
Member

Sorry for the delay. It skipped out of my eyes. I added a comment.

@BerkeleyTrue
Copy link
Contributor Author

@raymondfeng done

@BerkeleyTrue BerkeleyTrue changed the title exit early when no password is detected fix exit early when password is non-string Jul 29, 2015
@BerkeleyTrue BerkeleyTrue changed the title fix exit early when password is non-string fix: exit early when password is non-string Jul 29, 2015
raymondfeng added a commit that referenced this pull request Jul 29, 2015
fix: exit early when password is non-string
@raymondfeng raymondfeng merged commit 66d5cc0 into strongloop:master Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server break down if password is in numeric form on reset password

3 participants