fix: remove panic() and relay password hashing errors to UI - #1014
fix: remove panic() and relay password hashing errors to UI#1014eternal-flame-AD wants to merge 1 commit into
Conversation
d945ca6 to
6f6ec40
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1014 +/- ##
==========================================
- Coverage 74.53% 74.30% -0.24%
==========================================
Files 66 66
Lines 3483 3514 +31
==========================================
+ Hits 2596 2611 +15
- Misses 688 698 +10
- Partials 199 205 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6f6ec40 to
38eccee
Compare
| if err != nil { | ||
| panic(err) | ||
| if err != nil && err != bcrypt.ErrPasswordTooLong { | ||
| err = ErrUnexpectedError |
There was a problem hiding this comment.
If we mask the error here, we don't get the initial error anywhere, meaning if a user misconfigures the passstrength, it will always return unexpected error without any log about the actual error. I think we can pass the full error without masking into the 500 internal server error, and with the extra validation the length check is done before and results in a 400.
38eccee to
726c34b
Compare
| var ErrUnexpectedError = errors.New("unexpected error") | ||
|
|
||
| func ValidateNewPassword(pw string) error { | ||
| if pw == "" { |
There was a problem hiding this comment.
This is already checked by the binding on the property (binding:"required"). Please add the 72 char validation there too. Then we don't need this method.
There was a problem hiding this comment.
- I actually didn't figure out how to make sure it's no more than 72 bytes long using validator.. do you know how?
There was a problem hiding this comment.
Ahh true, it bytes and not len on string. Then nevermind about the validation on the binding.
Can we do this as extra check for the create password method in the
pw, err := password.CreatePassword(user.Pass, a.PasswordStrength)
if err != nil {
status := http.StatusInternalServerError
if errors.Is(err, bcrypt.ErrPasswordTooLong) {
status = http.StatusBadRequest
}
ctx.AbortWithError(status, fmt.Errorf("failed to prepare password: %s", err))
return
}
and remove the masking described in https://github.com/gotify/server/pull/1014/changes#r3666911979.
Fixes #1013