security: harden recursive file operations

This commit is contained in:
OpenClaw Agent
2026-09-21 21:46:11 +08:00
parent ea6999cddd
commit ece101edd7
4 changed files with 89 additions and 2 deletions
+20
View File
@@ -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()