security: harden recursive file operations
This commit is contained in:
@@ -74,6 +74,26 @@ func TestSameWebDAVDestinationHost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebDAVStorageFSRejectsDestinationInsideSource(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, "src", "child"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "src", "file.txt"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fs := &webdavStorageFS{store: storage.Local{Root: root}}
|
||||
if _, err := fs.Copy(context.Background(), "/src", "/src/child/copy", &webdav.CopyOptions{}); err == nil {
|
||||
t.Fatal("copying a directory into its descendant should fail")
|
||||
}
|
||||
if _, err := fs.Move(context.Background(), "/src", "/src/child/moved", &webdav.MoveOptions{}); err == nil {
|
||||
t.Fatal("moving a directory into its descendant should fail")
|
||||
}
|
||||
if _, err := fs.Copy(context.Background(), "/src", "/src", &webdav.CopyOptions{}); err == nil {
|
||||
t.Fatal("copying a resource onto itself should fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebDAVStorageFSCopyAndMove(t *testing.T) {
|
||||
root1 := t.TempDir()
|
||||
root2 := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user