-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: exit early when password is non-string #1465
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
Conversation
|
Any feedback on this? |
common/models/user.js
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
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;
}There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Will do.
|
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. |
|
@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. |
|
ping @raymondfeng |
|
Sorry for the delay. It skipped out of my eyes. I added a comment. |
|
@raymondfeng done |
fix: exit early when password is non-string
prevent errors when plain is non-string by using call on indexOf method
closes #1437