Prevent bucket renaming in filer, fuse mount, and S3 (#8048)

* prevent bucket renaming in filer, fuse mount, s3

* refactor CanRename to support context propagation

* harden bucket rename validation to fail closed on find error
This commit is contained in:
Chris Lu
2026-01-16 19:48:09 -08:00
committed by GitHub
parent a473278bfa
commit 796a911cb3
4 changed files with 17 additions and 6 deletions

View File

@@ -1,18 +1,29 @@
package filer
import (
"context"
"fmt"
"strings"
"github.com/seaweedfs/seaweedfs/weed/util"
)
func (f *Filer) CanRename(source, target util.FullPath, oldName string) error {
func (f *Filer) CanRename(ctx context.Context, source, target util.FullPath, oldName string) error {
sourcePath := source.Child(oldName)
if strings.HasPrefix(string(target), string(sourcePath)) {
return fmt.Errorf("mv: can not move directory to a subdirectory of itself")
}
// Check if attempting to rename a bucket itself
// Need to load the entry to check if it's a bucket
entry, err := f.FindEntry(ctx, sourcePath)
if err != nil {
return err
}
if f.IsBucket(entry) {
return fmt.Errorf("bucket renaming is not allowed")
}
sourceBucket := f.DetectBucket(source)
targetBucket := f.DetectBucket(target)
if sourceBucket != targetBucket {