fix(auth): a password reset signs out Subsonic apps too, and a change can (#8107)

A reset ended every session but left the API key and Subsonic password
working, and anyone signed in to the account can make either. So whoever had
the account kept it through a Subsonic app after the owner reset the
password. The forgotten-password reset and an admin's reset now replace the
API key with one nobody holds and clear the Subsonic password.

A self-service change keeps Subsonic apps signed in by default, since it
would sign out the owner's own apps too. The web and Android password forms
gain "Sign out Subsonic apps too", sent as sign_out_subsonic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 23:48:21 -05:00
co-authored by Claude Opus 5.5
parent 1c28e17dfc
commit c6a9535cf7
16 changed files with 246 additions and 18 deletions
+36
View File
@@ -143,3 +143,39 @@ func TestSubsonicPassword_StatusAndClear(t *testing.T) {
t.Errorf("stored after clear = %q, want NULL", *got)
}
}
// subsonicCredentials reads what a Subsonic app signs in with: the API key's
// hash and whether a Subsonic password is set.
func subsonicCredentials(t *testing.T, h *handlers, user dbq.User) (apiKeyHash string, hasPassword bool) {
t.Helper()
var pw *string
if err := h.pool.QueryRow(context.Background(),
"SELECT api_token_hash, subsonic_password FROM users WHERE id = $1", user.ID).Scan(&apiKeyHash, &pw); err != nil {
t.Fatalf("read subsonic credentials: %v", err)
}
return apiKeyHash, pw != nil
}
// giveSubsonicPassword stores a Subsonic password for user, as Settings does.
func giveSubsonicPassword(t *testing.T, h *handlers, user dbq.User) {
t.Helper()
req := withUser(httptest.NewRequest(http.MethodPost, "/api/me/subsonic-password", nil), user)
rec := httptest.NewRecorder()
newMeSubsonicPasswordRouter(h).ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("generate subsonic password: %d %s", rec.Code, rec.Body.String())
}
}
// assertSubsonicSignedOut fails unless the API key has changed from before and
// no Subsonic password is left.
func assertSubsonicSignedOut(t *testing.T, h *handlers, user dbq.User, before string) {
t.Helper()
after, hasPassword := subsonicCredentials(t, h, user)
if after == before {
t.Error("the API key still works after the reset")
}
if hasPassword {
t.Error("the Subsonic password still works after the reset")
}
}