mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-30 01:05:26 +00:00
* fix(server): check admin before changing a radio image
The radio image upload and delete handlers wrote or removed the file first,
and only then called Radio().Put, which refuses non-admin users. A regular
user got a 403, but the image file was already replaced or deleted.
Both /radio/{id}/image routes now use adminOnlyMiddleware, so the check runs
before the handlers touch the disk. Admin upload and delete work as before.
* fix(server): keep radio REST writes from setting the uploaded image path
The radio REST create and update wrote every field from the request body,
including uploaded_image. That value is later joined to the artwork folder
and removed on image delete or replace, so a value like ../../file pointed
at any file the server can remove.
Radio Save now drops the client id and uploaded image. Update writes only
name, stream_url and home_page_url, and also clears the uploaded image,
because put inserts the full row when the id does not exist.
model.UploadedImagePath now returns an empty path for any name that is not a
plain file name, so values already stored are harmless for radios, artists
and playlists. SetImage refuses a generated name that fails the same check,
and the artist image cleanup skips empty paths.
* refactor(server): simplify the radio image path checks
Update now has a single Put call, using slice.Filter over the allowed
columns. The two radio image routes share one adminOnlyMiddleware group.
isPlainFileName drops a redundant empty check, since filepath.IsLocal
already rejects it. The route test reuses createAuthenticatedRequest.
Comments are shorter. No behavior change.
* test(server): run the radio image specs on the real test database
Master replaced the shared repository fakes with a per-suite database,
so the specs no longer built after the rebase.
22 lines
653 B
Go
22 lines
653 B
Go
package model
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/navidrome/navidrome/conf"
|
|
"github.com/navidrome/navidrome/consts"
|
|
)
|
|
|
|
// UploadedImagePath returns the absolute filesystem path for a manually uploaded entity cover
|
|
// image. It returns "" unless filename is a plain file name, so it can't leave the artwork folder.
|
|
func UploadedImagePath(entityType, filename string) string {
|
|
if !isPlainFileName(filename) {
|
|
return ""
|
|
}
|
|
return filepath.Join(conf.Server().DataFolder.String(), consts.ArtworkFolder, entityType, filename)
|
|
}
|
|
|
|
func isPlainFileName(name string) bool {
|
|
return name != "." && filepath.IsLocal(name) && filepath.Base(name) == name
|
|
}
|