-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add bruteforce prevention in wallet changepassword function #73
base: master
Are you sure you want to change the base?
Conversation
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.
Overall good!
req = httptest.NewRequest(http.MethodPost, "/v2/validator/wallet/change-password", &buf) | ||
wr = httptest.NewRecorder() | ||
wr.Body = &bytes.Buffer{} | ||
s.ChangePassword(wr, req) |
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.
Wonder why this test requests /v2/validator/wallet/change-password
twice
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 first attempt triggers the lockout and the second attempt checks if lockout is properly performed. I should have added comments about this.
validator/rpc/handler_wallet_test.go
Outdated
require.Equal(t, http.StatusBadRequest, wr.Code) | ||
require.StringContains(t, "Old password is not correct", wr.Body.String()) | ||
} else { | ||
// On the final attempt, we expect the server to lock out the user (429 or similar). |
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.
Current implementation doesn't return 429
code, so this comment might be misleading.
validator/rpc/handler_wallet_test.go
Outdated
wr.Body = &bytes.Buffer{} | ||
s.ChangePassword(wr, req) | ||
|
||
// Expect locked-out response (429 or 400 with a lockout message). |
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.
Either for this comment!
validator/rpc/handler_wallet_test.go
Outdated
wrongPassword := "wrong-old-password" | ||
encryptedWrongPassword, err := aes.Encrypt(cipher, []byte(wrongPassword)) | ||
require.NoError(t, err) | ||
encryptedNewPassword, err := aes.Encrypt(cipher, []byte("newValidPassword")) |
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.
encryptedNewPassword, err := aes.Encrypt(cipher, []byte("newValidPassword")) | |
newValidPassword := "new-valid-password" | |
encryptedNewPassword, err := aes.Encrypt(cipher, []byte(newValidPassword)) |
validator/rpc/handler_wallet_test.go
Outdated
// 2. Provide correct old password but an obviously too-short new password | ||
encryptedOldPassword, err := aes.Encrypt(cipher, []byte(oldPassword)) | ||
require.NoError(t, err) | ||
encryptedShortPassword, err := aes.Encrypt(cipher, []byte("12")) // fails ValidatePasswordInput? |
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.
As minPasswordLength
is 8, how about explictly define a shortPassword
whose length is less than 8?
Add bruteforce prevention in
validator/rpc/handler_wallet.ChangePassword
.