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:
@@ -37,6 +37,17 @@ func UserFromContext(ctx context.Context) (dbq.User, bool) {
|
||||
return u, ok
|
||||
}
|
||||
|
||||
// requireUser returns the caller Middleware put in the context. Without one
|
||||
// (a handler mounted outside Middleware) it answers error 50 and returns
|
||||
// false, and the handler must return at once.
|
||||
func requireUser(w http.ResponseWriter, r *http.Request) (dbq.User, bool) {
|
||||
user, ok := UserFromContext(r.Context())
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
||||
}
|
||||
return user, ok
|
||||
}
|
||||
|
||||
// Middleware authenticates the request against users.api_token_hash (apiKey) or
|
||||
// users.subsonic_password (t/s or p). On failure it writes a Subsonic failed
|
||||
// envelope using the request's f= format; downstream handlers never see an
|
||||
|
||||
Reference in New Issue
Block a user