Skip to content

fix(api): store is_non_default_password when a user chooses a password - #12

Merged
appflowy merged 2 commits into
appflowy4from
fix/password-flag
Nov 25, 2026
Merged

appflowy merged 2 commits into
appflowy4from
fix/password-flag

Conversation

@appflowy

@appflowy appflowy commented Nov 25, 2026 •

Copy link
Copy Markdown

Why

Five tests in internal/api fail on appflowy4, so Test is red on the branch and on every pull request against it, #10 included. Nobody saw them fail before 2026-11-25 because the fork's checks never ran (#11). They have three causes, and one of them is a real defect in the password feature.

The feature

auth.users.is_non_default_password says whether a password is one the user chose. A password generated for a passwordless sign-up, or set by an administrator, is not: its owner may never have seen it.

  • POST /user/change-password asks for current_password only when the flag is set.
  • GET /user/auth-info reports the flag, and Web uses it to decide whether to show a current-password field.

What was wrong

1. Nothing stored the flag. The appflowy branch (2025-04) wrote the column in UpdatePassword's column list. The port to appflowy2 (2025-11) kept the assignments in memory and dropped the column from that list. Since then:

  • a password changed through /user/change-password did not set the flag, so the endpoint never asked for it on the next change;
  • auth-info kept reporting such passwords as not chosen;
  • the reset on recovery was an assignment in recover.go that was never saved.

Rows written by the appflowy branch before the port kept their value.

2. One test changed shared configuration and did not restore it. TestUserChangePasswordWeakPassword set the minimum password length to 10. The tests of a suite share one configuration and run in name order, so two later tests that set the seven-character password newpass were refused. They pass when run alone.

3. Two tests required behaviour that no version of the fork had. Both required the password to be deleted: one when a recovery is verified, one when an email change is verified. The second also required the email change to reset the flag, and expected the change to be complete after one of its two confirmations.

Why the fork's notes said these passed. appflowy/TESTING_GUIDE.md ran them as go test -run TestUserChangePassword. They are methods of the TestUser and TestVerify suites, so that pattern matches no test and go test prints ok ... [no tests to run].

What changes

Area Change
internal/models/user.go User.SetIsNonDefaultPassword stores the flag. UpdatePassword is untouched.
POST /user/change-password Stores the flag as set, in the transaction that stores the password.
PUT /user with a password Stores the flag as set. Web and Desktop use this endpoint after a recovery, and Desktop for a first password, so without it a password set that way would never count as chosen.
GET and POST /verify, type recovery A verified recovery resets the flag. The password is untouched.
POST /recover The assignment that was never saved is removed.
Tests See below.
appflowy/ notes The guide's commands name the suite first, and the notes describe what the flag does and where it is stored.

What users see

  • After choosing a password, the next change asks for it. That is the feature working. It applies to passwords chosen from now on; a password chosen while the flag was not stored is asked for only after the next change.
  • Nobody is locked out. A user who forgot a chosen password recovers it by email as before, and sets a new one with PUT /user, which does not ask for the current password unless the operator turned that on.
  • Web reads the flag from auth-info and shows the current-password field; if the server asks for it unexpectedly it handles incorrect_current_password by asking. Desktop always sends current_password from its change form. The Admin console sets passwords through the admin API, which this change does not touch.
  • No migration: the column exists.

Decisions

  • A method of its own, not UpdatePassword's column list. That list is an upstream line that changes when upstream adds a column, and a fork edit inside it is how the write was lost once already. The flag is now written by fork code that says so.
  • Reset when a recovery is verified, not when it is requested. The appflowy branch reset it on POST /recover, which anyone can send for any address. Verification proves control of the mailbox, the same proof that already lets a user set a new password.
  • Only a recovery resets it. A magic-link sign-in runs through the same verification code and proves the same mailbox, but says nothing about the password; most AppFlowy sign-ins are magic links, so resetting there would leave the flag unset for almost everyone. An email change says nothing about the password either.
  • A recovery does not delete the password. The fork tried that first and replaced it with the flag within the same month (2025-04). Verification links are also opened by mail scanners, and a deleted password cannot be undone.
  • Not restored: the appflowy branch also set the flag for users created through the admin API with a password hash. Nothing in AppFlowy creates users that way; the backup restore sets the column itself.

Tests

The five that failed:

Test Was Now
TestUserChangePasswordNoCurrentPasswordForDefaultPassword Failed: the flag was not stored Passes unchanged
TestUserUpdatePasswordReauthentication, TestUserUpdatePasswordLogoutOtherSessions Failed in the suite, passed alone Pass: the test before them restores the minimum length
TestPasswordRecoveryResetsIsNonDefaultPassword Failed: no reset, and required the password to be deleted Requires the reset on verification only; that a requested recovery and a magic link change nothing; and that the password still signs the user in
TestEmailChangeResetsIsNonDefaultPassword Could not pass Replaced by TestEmailChangeKeepsThePasswordAndIsNonDefaultPassword: a completed change keeps the flag and the password

New: TestUserChangePasswordAsksForAChosenPasswordNextTime and TestUserUpdatePasswordIsAChosenPassword read the flag back through each endpoint that sets it.

Run in a golang:1.25 container against PostgreSQL 15, with the tool versions CI installs:

Command Result
make vet static sec vulncheck Passed
make test (every package, -race) 30 packages passed; 1,742 tests passed, 0 failed
The old guide command, go test -run "TestPasswordRecoveryResets|TestEmailChangeResets" ./internal/api ok ... [no tests to run]
The corrected guide commands Run 2, 9, 4 and 4 tests, all passing

In CI on 28edc01: Test passed, with 30 packages and 1,742 tests and no failure, the first green Test in this fork.

Against a built image. GoTrue was built with AppFlowy Cloud's Dockerfile from 03a4a52, the head of #10 with this branch merged in, and driven over HTTP with PostgreSQL 15. All 21 checks passed:

  • An administrator-set password is reported as not chosen and can be replaced without presenting it. auth-info then reports a chosen password and the column is stored.
  • The next change is refused without the current password (incorrect_current_password) and with a wrong one, and accepted with the right one.
  • Requesting a recovery does not reset the flag. A wrong recovery code is refused, and the stored token is not in the server log afterwards (#11's fix, seen on a running server).
  • A verified recovery resets the flag and leaves the password in place. The recovery session can set a new password on either endpoint, and that password counts as chosen again.
  • A magic-link sign-in does not reset the flag.

Each part of the fix was removed in turn to see which test notices:

Removed Failing test
The write in /user/change-password …AsksForAChosenPasswordNextTime, …NoCurrentPasswordForDefaultPassword
The write in PUT /user TestUserUpdatePasswordIsAChosenPassword
The reset on a verified recovery TestPasswordRecoveryResetsIsNonDefaultPassword
The restriction to recoveries (a magic link resets too) same test
Reset on request again same test
The restored minimum length TestUserUpdatePasswordReauthentication, TestUserUpdatePasswordLogoutOtherSessions

Not verified

  • Web and Desktop were read, not run, against this build.
  • Clients older than the current sources.

Related PRs

PR Role
#10 Delegated token exchange. Its Test was red only because of these five tests. This branch is merged into it, so #10 passes now and the two can merge in either order
#11 Made the fork's checks run, which is how these failures surfaced
AppFlowy-Cloud-Premium#1653 Pins the GoTrue commit that images are built from

🤖 Generated with Claude Code

appflowy and others added 2 commits November 25, 2026 13:14
The flag says whether a password is one the user chose. POST
/user/change-password asks for the current password only when it is set,
and GET /user/auth-info reports it so that Web can ask for one.

Since the port to appflowy2 (2025-11) nothing stored it. The appflowy
branch wrote the column in UpdatePassword's column list; the port kept the
assignments in memory and dropped the column. The endpoint therefore never
asked for a current password that was set after the port, and auth-info
kept reporting such passwords as not chosen.

- User.SetIsNonDefaultPassword stores the flag. Each place that decides it
  calls this in the transaction of the change it belongs to, so the flag
  no longer depends on an upstream column list.
- POST /user/change-password and PUT /user with a password set it. Web and
  Desktop use PUT /user after a recovery, and Desktop for a first password.
- A verified password recovery resets it. The appflowy branch reset it
  when a recovery was requested, which let anyone reset it for any
  address; the port left that as an assignment that was never saved. A
  magic-link sign-in and an email change do not reset it.

Tests. The five that failed on appflowy4:

- TestUserChangePasswordNoCurrentPasswordForDefaultPassword failed on the
  missing write and passes unchanged.
- TestUserUpdatePasswordReauthentication and
  TestUserUpdatePasswordLogoutOtherSessions passed alone and failed in the
  suite: TestUserChangePasswordWeakPassword left the shared minimum length
  at 10, which refused their seven-character password. It restores it now.
- TestPasswordRecoveryResetsIsNonDefaultPassword also required the
  recovery to delete the password, which no version of the fork did. It
  now requires the reset on verification only, and that the password
  still signs the user in.
- TestEmailChangeResetsIsNonDefaultPassword required an email change to
  reset the flag and delete the password, and expected the change to
  complete after one of its two confirmations. It is replaced by a test
  that a completed change keeps both.

New tests read the flag back through each endpoint that sets it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…no test

The testing guide ran suite methods by their own name, for example
`-run TestUserChangePassword`. Those tests are methods of the TestUser and
TestVerify suites, so the pattern matched nothing and `go test` printed
`ok ... [no tests to run]`. The migration notes recorded that as passing,
for tests that could not pass. The commands now name the suite first.

The notes also said the flag is reset on an email change, which the code
never did and should not do, and did not say where the flag is stored.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@appflowy
appflowy merged commit 18300cf into appflowy4 Nov 25, 2026
4 checks passed
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.

1 participant