dataprovider: surface bcrypt 72-byte limit as a typed validation error - #2230
Open
rupivbluegreen wants to merge 1 commit into
Open
dataprovider: surface bcrypt 72-byte limit as a typed validation error#2230rupivbluegreen wants to merge 1 commit into
rupivbluegreen wants to merge 1 commit into
Conversation
When a password longer than bcrypt's 72-byte limit was submitted (admin or user creation, password reset, share password, or API key), the bare bcrypt.ErrPasswordTooLong propagated up as a generic 500 "Unable to fulfill your request" in the WebAdmin/WebClient and a low-level "bcrypt: password length exceeds 72 bytes" message in the CLI. Wrap the error at the four hash sites with a typed validation error and a new i18n key so the existing error-to-status mapping returns 400 instead of 500 and the user sees a clear localized message. The CLI gets the same friendlier wording. argon2id setups are unaffected. Fixes drakkan#2171 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
|
Same as for your other PR here. We need the CLA signed to accept contributions and we already have shipped this small enhancement in SFTPGo Enterprise. Anyway, thanks for asking Claude to work on this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2171.
When a password longer than bcrypt's 72-byte limit was submitted, the bare
bcrypt.ErrPasswordTooLong("bcrypt: password length exceeds 72 bytes") propagated up unwrapped:getRespStatusfalls through tohttp.StatusInternalServerErrorbecause the error isn't a*ValidationError. The user sees the generic "The server is unable to fulfill your request" warning, with no hint that password length is the problem.sftpgo resetpwd --admin): the implementation-level bcrypt message is printed verbatim.Change
Add a small
wrapBcryptErrorhelper ininternal/dataprovider/dataprovider.gothat translatesbcrypt.ErrPasswordTooLongintoutil.NewI18nError(util.NewValidationError(...), util.I18nErrorPasswordTooLong). Wire it into the four bcrypt call sites (Admin.hashPassword,hashPlainPassword,Share.hashPassword,APIKey.hashKey). Add the matchinggeneral.err_password_too_longi18n key + EN translation.argon2idsetups are unaffected — there is no 72-byte limit on that path. Other bcrypt errors (e.g., cost-related failures) flow through unchanged.Test plan
go build ./...go vet ./...TestAddAdminPasswordTooLongMockininternal/httpd/httpd_test.goposts an admin with a 73-byte password, expects HTTP 400, and asserts the response body contains "too long".TestAddAdminNoPasswordMock,TestAddAdmin,TestUserPassword,TestSharePassword,TestChangeAdminPassword,TestUserPasswordHashingall pass.Out of scope
Diff stats
7 files changed, 39 insertions, 3 deletions.