Skip to content

Commit b64b106

Browse files
authored
Merge pull request #49966 from nextcloud/block-dav-move-parent
fix: block moving files to it's own parent with dav
2 parents 3ab0d67 + 9193cd6 commit b64b106

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public function checkMove(string $source, string $target): void {
203203
if (!$sourceNodeFileInfo->isDeletable()) {
204204
throw new Forbidden($source . ' cannot be deleted');
205205
}
206+
207+
// The source is not allowed to be the parent of the target
208+
if (str_starts_with($source, $target . '/')) {
209+
throw new Forbidden($source . ' cannot be moved to it\'s parent');
210+
}
206211
}
207212

208213
/**

build/integration/dav_features/dav-v2.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ Feature: dav-v2
1212
When User "user0" moves file "/textfile0.txt" to "/FOLDER/textfile0.txt"
1313
Then the HTTP status code should be "201"
1414

15+
Scenario: Moving and overwriting it's parent
16+
Given using new dav path
17+
And As an "admin"
18+
And user "user0" exists
19+
And As an "user0"
20+
And user "user0" created a folder "/test"
21+
And user "user0" created a folder "/test/test"
22+
When User "user0" moves file "/test/test" to "/test"
23+
Then the HTTP status code should be "403"
24+
1525
Scenario: download a file with range using new endpoint
1626
Given using new dav path
1727
And As an "admin"

build/integration/dav_features/webdav-related.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Feature: webdav-related
3838
Then the HTTP status code should be "204"
3939
And Downloaded content when downloading file "/textfile0.txt" with range "bytes=0-6" should be "Welcome"
4040

41+
Scenario: Moving and overwriting it's parent
42+
Given using old dav path
43+
And As an "admin"
44+
And user "user0" exists
45+
And As an "user0"
46+
And user "user0" created a folder "/test"
47+
And user "user0" created a folder "/test/test"
48+
When User "user0" moves file "/test/test" to "/test"
49+
Then the HTTP status code should be "403"
50+
4151
Scenario: Moving a file to a folder with no permissions
4252
Given using old dav path
4353
And As an "admin"

0 commit comments

Comments
 (0)