fix: match admin share paths by owner scope (#5992)

This commit is contained in:
JinHyuk Sung authored and GitHub committed 2026-06-27 07:43:22 +02:00
1 parent d9cf2f0100
commit 43a404ca69
4 files changed
+139 -103

No files matched your search

+29 -1
View File
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"net/http"
"path/filepath"
"sort"
"strconv"
"strings"
@@ -14,6 +15,7 @@ import (
fberrors "github.com/filebrowser/filebrowser/v2/errors"
"github.com/filebrowser/filebrowser/v2/share"
"github.com/filebrowser/filebrowser/v2/users"
"golang.org/x/crypto/bcrypt"
)
@@ -61,7 +63,7 @@ var shareGetsHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
err error
)
if d.user.Perm.Admin {
s, err = d.store.Share.GetsByPath(r.URL.Path)
s, err = getSharesForAdminPath(d, r.URL.Path)
} else {
s, err = d.store.Share.Gets(r.URL.Path, d.user.ID)
}
@@ -76,6 +78,32 @@ var shareGetsHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
return renderJSON(w, r, s)
})
func getSharesForAdminPath(d *data, path string) ([]*share.Link, error) {
links, err := d.store.Share.All()
if err != nil {
return nil, err
}
adminPath := filepath.Clean(d.user.FullPath(path))
owners := make(map[uint]*users.User)
filtered := make([]*share.Link, 0, len(links))
for _, link := range links {
owner, ok := owners[link.UserID]
if !ok {
owner, err = d.store.Users.Get(d.server.Root, d.server.FollowExternalSymlinks, link.UserID)
if err != nil && !errors.Is(err, fberrors.ErrNotExist) {
return nil, err
}
owners[link.UserID] = owner // owner is nil on ErrNotExist
}
if owner != nil && filepath.Clean(owner.FullPath(link.Path)) == adminPath {
filtered = append(filtered, link)
}
}
return filtered, nil
}
var shareDeleteHandler = withPermShare(func(_ http.ResponseWriter, r *http.Request, d *data) (int, error) {
hash := strings.TrimSuffix(r.URL.Path, "/")
hash = strings.TrimPrefix(hash, "/")