fix(share): delete exact directory share on trailing-slash delete (GHSA-pp88-jhwj-5qh5)

DeleteWithPathPrefix queried the share index with the raw path, so deleting a
directory through a trailing-slash path (e.g. DELETE /api/resources/a/) only
matched descendants like /a/child and missed the exact /a share, leaving it in
storage. If the same path was later recreated, the stale public share re-exposed
the new content. Normalize the path before the prefix query so the exact share
and its descendants are both removed. Adds a regression test.
This commit is contained in:
Henrique Dias committed 2026-06-27 09:08:57 +02:00
1 parent ec13054671
commit f30fca636c
2 files changed
+42 -3

No files matched your search

+4 -3
View File
@@ -78,16 +78,17 @@ func (s shareBackend) Delete(hash string) error {
}
func (s shareBackend) DeleteWithPathPrefix(pathPrefix string, userID uint) error {
// Share paths are stored without a trailing slash
prefix := strings.TrimRight(pathPrefix, "/")
var links []share.Link
if err := s.db.Prefix("Path", pathPrefix, &links); err != nil {
if err := s.db.Prefix("Path", prefix, &links); err != nil {
if errors.Is(err, storm.ErrNotFound) {
return nil
}
return err
}
prefix := strings.TrimRight(pathPrefix, "/")
var err error
for _, link := range links {
if link.UserID != userID {