Conversation
The strong-password validator measured len(password), i.e. bytes, so a multibyte password with fewer characters than the policy requires was accepted by the API while the frontend rejected it; the frontend in turn counted UTF-16 units. Both now count Unicode code points, and the tests cover the multibyte cases.
fadiroot
force-pushed
the
fix/password-policy-character-count
branch
2 times, most recently
from
September 28, 2026 08:50
6646740 to
df5f117
Compare
Author
|
Heads-up on the noise here: this morning my fork was hit by a git worm that used my credentials to force-push a payload commit ( |
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.
Description of the Change
Problem
The password policy is expressed in characters (8–15 with composition, or 16+ of any composition), and
CLAUDE.mdasks for the backend and the frontend to enforce exactly the same rule. They currently measure length differently:strongPasswordValidatorString(backend/pkg/server/models/init.go) useslen(password), which is the byte length in Go. A password of 8 non-ASCII letters (ññññññññ, 16 bytes) is accepted by the API as a "16+ character" password, andPa1!ñbc(7 characters, 8 bytes) is accepted as an 8-character one. The frontend rejects both.frontend/src/features/authentication/password-change-form.tsx) usespassword.length, which counts UTF-16 code units, so 8 emoji pass as 16 characters in the UI while the backend (after this fix) counts 8.So the API is more lenient than the UI for multibyte passwords, and the two sides disagree on what a "character" is.
Solution
utf8.RuneCountInStringfor both the> 15and the>= 8checks. Thepasslenvalidator (72 bytes, the bcrypt limit) is intentionally left in bytes, matching the frontend'sTextEncodercheck.Array.from(password).lengthso both sides use the same definition.TestStrongPasswordValidator(two of them fail onmain), and one vitest case that types 8 emoji and expects the policy error instead of a request.Closes #
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
cd backend && go test ./pkg/server/models/ -run TestStrongPasswordValidator -vcd frontend && pnpm exec vitest run src/features/authentication/password-change-form.test.tsxgofmt -l ./pkg/server/models && go vet ./pkg/server/models/;pnpm exec eslint --max-warnings 0andprettier --checkon the two changed frontend filesTest Results
On
mainwithout the fix,8_non-ascii_chars_(16_bytes)_still_need_requirementsand7_chars_with_requirements_(8_bytes)fail, and the new vitest case fails (the form submits 8 emoji). With the fix:ok pentagi/pkg/server/models,Tests 5 passed (5), lint and formatting clean.Security Considerations
Tightens the server-side check for multibyte passwords so the API cannot be used to bypass the documented policy. No new dependencies, no change to hashing or storage.
Performance Impact
None: one
utf8.RuneCountInStringper validation.Documentation Updates
CLAUDE.mdalready says "characters"Deployment Notes
None.
Checklist
Code Quality
go fmtandgo vet(for Go code)pnpm run lint(for TypeScript/JavaScript code)Security
Compatibility
Documentation
Additional Notes
Existing ASCII passwords validate exactly as before; only multibyte input changes, and only in the direction of matching the documented policy.