-
Notifications
You must be signed in to change notification settings - Fork 935
fix: improve password validation flow #15132
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
Changes from 12 commits
b93dc6b
cf31dde
309d839
388a58b
f9cce4c
8a5e63f
8f695ab
c103559
dc46019
37072ee
b4b8b06
0efd24f
a6ee1cc
51b1e51
e2128e6
f37ef9e
36cadeb
175b4bf
f33eac2
2e0941b
3869dd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -437,6 +437,38 @@ func (api *API) postChangePasswordWithOneTimePasscode(rw http.ResponseWriter, r | |
} | ||
} | ||
|
||
// ValidateUserPassword validates the complexity of a user password and that it is secured enough. | ||
// | ||
// @Summary Validate user password | ||
// @ID validate-user-password | ||
// @Security CoderSessionToken | ||
// @Produce json | ||
// @Accept json | ||
// @Tags Authorization | ||
// @Param request body codersdk.ValidateUserPasswordRequest true "Validate user password request" | ||
// @Success 200 {object} codersdk.ValidateUserPasswordResponse | ||
// @Router /users/validate-password [post] | ||
func (*API) validateUserPassword(rw http.ResponseWriter, r *http.Request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit about referring to all of this stuff as "user password" validation: the password is not yet attached to a user, so it's not a user password, it's just a password, so I'd expect it to be called |
||
var ( | ||
ctx = r.Context() | ||
valid = true | ||
) | ||
|
||
var req codersdk.ValidateUserPasswordRequest | ||
if !httpapi.Read(ctx, rw, r, &req) { | ||
return | ||
} | ||
|
||
err := userpassword.Validate(req.Password) | ||
if err != nil { | ||
valid = false | ||
defelmnq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
httpapi.Write(ctx, rw, http.StatusOK, codersdk.ValidateUserPasswordResponse{ | ||
Valid: valid, | ||
}) | ||
} | ||
|
||
// Authenticates the user with an email and password. | ||
// | ||
// @Summary Log in user | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
"strconv" | ||
"strings" | ||
|
||
passwordvalidator "github.com/wagslane/go-password-validator" | ||
"golang.org/x/crypto/pbkdf2" | ||
"golang.org/x/exp/slices" | ||
"golang.org/x/xerrors" | ||
|
@@ -138,10 +137,8 @@ func hashWithSaltAndIter(password string, salt []byte, iter int) string { | |
// It returns properly formatted errors for detailed form validation on the client. | ||
func Validate(password string) error { | ||
// Ensure passwords are secure enough! | ||
// See: https://github.com/wagslane/go-password-validator#what-entropy-value-should-i-use | ||
err := passwordvalidator.Validate(password, 52) | ||
if err != nil { | ||
return err | ||
if len(password) < 6 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now this logic stays pretty simple - here's the place where we'll be able to apply all the validation logic we want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I'm concerned here, we are squishing together three distinct separate changes:
Of these three options, 1) and 2) are relatively innocuous. 3) is the one I'm mainly concerned about. I propose keeping the existing password validation logic (via entropy) in this PR and opening a separate PR to modify the password validation logic if required. My proposal for a roughly equivalent non-entropy-based password validation logic is:
EDIT: we should however be extremely careful if we change the validation, as users could have existing passwords that are valid per entropy but invalid per the above rule. |
||
return xerrors.Errorf("password must be at least %d characters", 6) | ||
} | ||
if len(password) > 64 { | ||
return xerrors.Errorf("password must be no more than %d characters", 64) | ||
|
defelmnq marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.