Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

qqqeck
Copy link
Contributor

@qqqeck qqqeck commented Jan 14, 2025

Add bruteforce prevention in validator/rpc/handler_wallet.ChangePassword .

@qqqeck qqqeck requested a review from a team as a code owner January 14, 2025 07:13
Copy link
Collaborator

@syjn99 syjn99 left a comment

Choose a reason for hiding this comment

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

Overall good!

Comment on lines +1056 to +1059
req = httptest.NewRequest(http.MethodPost, "/v2/validator/wallet/change-password", &buf)
wr = httptest.NewRecorder()
wr.Body = &bytes.Buffer{}
s.ChangePassword(wr, req)
Copy link
Collaborator

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

Copy link
Contributor Author

@qqqeck qqqeck Jan 15, 2025

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.

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).
Copy link
Collaborator

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.

wr.Body = &bytes.Buffer{}
s.ChangePassword(wr, req)

// Expect locked-out response (429 or 400 with a lockout message).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Either for this comment!

wrongPassword := "wrong-old-password"
encryptedWrongPassword, err := aes.Encrypt(cipher, []byte(wrongPassword))
require.NoError(t, err)
encryptedNewPassword, err := aes.Encrypt(cipher, []byte("newValidPassword"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
encryptedNewPassword, err := aes.Encrypt(cipher, []byte("newValidPassword"))
newValidPassword := "new-valid-password"
encryptedNewPassword, err := aes.Encrypt(cipher, []byte(newValidPassword))

// 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?
Copy link
Collaborator

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?

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.

2 participants