Skip to content

dataprovider: surface bcrypt 72-byte limit as a typed validation error - #2230

Open
rupivbluegreen wants to merge 1 commit into
drakkan:mainfrom
rupivbluegreen:fix/2171-password-too-long-error
Open

dataprovider: surface bcrypt 72-byte limit as a typed validation error#2230
rupivbluegreen wants to merge 1 commit into
drakkan:mainfrom
rupivbluegreen:fix/2171-password-too-long-error

Conversation

@rupivbluegreen

Copy link
Copy Markdown

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:

  • WebAdmin / WebClient: getRespStatus falls through to http.StatusInternalServerError because 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.
  • CLI (sftpgo resetpwd --admin): the implementation-level bcrypt message is printed verbatim.

Change

Add a small wrapBcryptError helper in internal/dataprovider/dataprovider.go that translates bcrypt.ErrPasswordTooLong into util.NewI18nError(util.NewValidationError(...), util.I18nErrorPasswordTooLong). Wire it into the four bcrypt call sites (Admin.hashPassword, hashPlainPassword, Share.hashPassword, APIKey.hashKey). Add the matching general.err_password_too_long i18n key + EN translation.

argon2id setups 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 ./...
  • New TestAddAdminPasswordTooLongMock in internal/httpd/httpd_test.go posts an admin with a 73-byte password, expects HTTP 400, and asserts the response body contains "too long".
  • Existing TestAddAdminNoPasswordMock, TestAddAdmin, TestUserPassword, TestSharePassword, TestChangeAdminPassword, TestUserPasswordHashing all pass.
  • Manually verified: hitting the WebAdmin "Add Admin" form with a 100-character password now shows the friendly length message instead of "Unable to fulfill your request".

Out of scope

  • Pre-hashing long passwords with SHA-256 before bcrypt (would change the security model).
  • Translating the new key into ZH/ES/FR/IT/DE — those go through Crowdin per the project's i18n workflow.

Diff stats

7 files changed, 39 insertions, 3 deletions.

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>
@rupivbluegreen
rupivbluegreen requested a review from drakkan as a code owner May 8, 2026 21:12
@CLAassistant

CLAassistant commented May 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@drakkan

drakkan commented May 9, 2026

Copy link
Copy Markdown
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.

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.

[Bug]: Password Length Limit not shown to end user

3 participants