fix(subsonic): a handler without a caller answers error 50 everywhere (#8002)

Sixteen handlers answered a missing caller with error 50 "Not
authenticated"; the star, unstar and scrobble handlers answered error 0
"Unauthenticated". Middleware stops such a request first, so no app saw
it, but the next handler copied would pick one at random. requireUser
now holds the check, the same shape as /api's, at all 21 sites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 12:44:05 -05:00
co-authored by Claude Opus 5.5
parent 0811775af6
commit cfdd6b916f
10 changed files with 32 additions and 42 deletions
+4 -8
View File
@@ -91,9 +91,8 @@ func playlistRef(p *playlists.PlaylistRow) PlaylistRef {
// what Minstrel makes fresh each day; within each group the service's order
// (most recently changed first) stands.
func (h *pickHandlers) getPlaylists(w http.ResponseWriter, r *http.Request) {
user, ok := UserFromContext(r.Context())
user, ok := requireUser(w, r)
if !ok {
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
return
}
rows, err := h.playlists.List(r.Context(), user.ID)
@@ -126,9 +125,8 @@ func (h *pickHandlers) getPlaylists(w http.ResponseWriter, r *http.Request) {
// whose file is missing, or that has left the library, keeps its place in
// Minstrel but is not listed here, since a Subsonic app would try to play it.
func (h *pickHandlers) getPlaylist(w http.ResponseWriter, r *http.Request) {
user, ok := UserFromContext(r.Context())
user, ok := requireUser(w, r)
if !ok {
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
return
}
raw := r.URL.Query().Get("id")
@@ -272,9 +270,8 @@ type RandomSongsResponse struct {
// size defaults to 10, as the Subsonic API defines it, and is capped at the
// server's radio length. genre, fromYear and toYear narrow the library first.
func (h *pickHandlers) getRandomSongs(w http.ResponseWriter, r *http.Request) {
user, ok := UserFromContext(r.Context())
user, ok := requireUser(w, r)
if !ok {
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
return
}
params := r.URL.Query()
@@ -404,9 +401,8 @@ func (h *pickHandlers) getSimilarSongs2(w http.ResponseWriter, r *http.Request)
// album id; otherwise only an artist id is a seed. It writes the failure
// itself and reports false when there is nothing to answer.
func (h *pickHandlers) similar(w http.ResponseWriter, r *http.Request, anyKind bool) ([]SongRef, bool) {
user, ok := UserFromContext(r.Context())
user, ok := requireUser(w, r)
if !ok {
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
return nil, false
}
params := r.URL.Query()