diff --git a/weed/s3api/s3_objectlock/object_lock_check.go b/weed/s3api/s3_objectlock/object_lock_check.go index 89debe98e1..9c28fca44b 100644 --- a/weed/s3api/s3_objectlock/object_lock_check.go +++ b/weed/s3api/s3_objectlock/object_lock_check.go @@ -95,7 +95,7 @@ func paginateEntries(ctx context.Context, client filer_pb.SeaweedFilerClient, di for _, entry := range page { // Skip invalid entry names to prevent path traversal if entry.Name == "" || entry.Name == "." || entry.Name == ".." || - strings.ContainsAny(entry.Name, "/\\") { + strings.Contains(entry.Name, "/") { glog.V(2).Infof("Skipping invalid entry name: %q in %s", entry.Name, dir) continue } diff --git a/weed/s3api/s3_objectlock/object_lock_check_test.go b/weed/s3api/s3_objectlock/object_lock_check_test.go index a35fe067af..df07f48e84 100644 --- a/weed/s3api/s3_objectlock/object_lock_check_test.go +++ b/weed/s3api/s3_objectlock/object_lock_check_test.go @@ -137,3 +137,19 @@ func TestHasObjectsWithActiveLocksReadsEachPageBeforeSubdirectories(t *testing.T t.Fatalf("expected the held object in the subdirectory to be reported") } } + +func TestHasObjectsWithActiveLocksNamesWithBackslashes(t *testing.T) { + held := map[string][]byte{s3_constants.ExtLegalHoldKey: []byte(s3_constants.LegalHoldOn)} + for name, dirs := range map[string]map[string][]*filer_pb.Entry{ + "object": {"/buckets/b": {{Name: `a\b`, Extended: held}}}, + "prefix": {"/buckets/b": {{Name: `a\b`, IsDirectory: true}}, `/buckets/b/a\b`: {{Name: "c", Extended: held}}}, + } { + has, err := HasObjectsWithActiveLocks(context.Background(), &fakeFilerClient{dirs: dirs}, "/buckets/b") + if err != nil { + t.Fatalf("%s: unexpected error: %v", name, err) + } + if !has { + t.Fatalf("%s: expected the held object with a backslash in its key to be reported", name) + } + } +}