Skip to content

Commit 6d8cf37

Browse files
authored
Merge pull request #29907 from nextcloud/backport/29902/stable21
[stable21] Check for invalid characters before trimming
2 parents 5bafc9a + 9cc47c5 commit 6d8cf37

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

build/integration/features/bootstrap/WebDav.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ public function userUploadsAFileTo($user, $source, $destination) {
459459
try {
460460
$this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file);
461461
} catch (\GuzzleHttp\Exception\ServerException $e) {
462-
// 4xx and 5xx responses cause an exception
462+
// 5xx responses cause a server exception
463+
$this->response = $e->getResponse();
464+
} catch (\GuzzleHttp\Exception\ClientException $e) {
465+
// 4xx responses cause a client exception
463466
$this->response = $e->getResponse();
464467
}
465468
}
@@ -488,7 +491,10 @@ public function userUploadsAFileWithContentTo($user, $content, $destination) {
488491
try {
489492
$this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file);
490493
} catch (\GuzzleHttp\Exception\ServerException $e) {
491-
// 4xx and 5xx responses cause an exception
494+
// 5xx responses cause a server exception
495+
$this->response = $e->getResponse();
496+
} catch (\GuzzleHttp\Exception\ClientException $e) {
497+
// 4xx responses cause a client exception
492498
$this->response = $e->getResponse();
493499
}
494500
}
@@ -503,7 +509,10 @@ public function userDeletesFile($user, $type, $file) {
503509
try {
504510
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []);
505511
} catch (\GuzzleHttp\Exception\ServerException $e) {
506-
// 4xx and 5xx responses cause an exception
512+
// 5xx responses cause a server exception
513+
$this->response = $e->getResponse();
514+
} catch (\GuzzleHttp\Exception\ClientException $e) {
515+
// 4xx responses cause a client exception
507516
$this->response = $e->getResponse();
508517
}
509518
}
@@ -518,7 +527,10 @@ public function userCreatedAFolder($user, $destination) {
518527
$destination = '/' . ltrim($destination, '/');
519528
$this->response = $this->makeDavRequest($user, "MKCOL", $destination, []);
520529
} catch (\GuzzleHttp\Exception\ServerException $e) {
521-
// 4xx and 5xx responses cause an exception
530+
// 5xx responses cause a server exception
531+
$this->response = $e->getResponse();
532+
} catch (\GuzzleHttp\Exception\ClientException $e) {
533+
// 4xx responses cause a client exception
522534
$this->response = $e->getResponse();
523535
}
524536
}
@@ -589,8 +601,12 @@ public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $
589601
public function downloadingFileAs($fileName, $user) {
590602
try {
591603
$this->response = $this->makeDavRequest($user, 'GET', $fileName, []);
592-
} catch (\GuzzleHttp\Exception\ServerException $ex) {
593-
$this->response = $ex->getResponse();
604+
} catch (\GuzzleHttp\Exception\ServerException $e) {
605+
// 5xx responses cause a server exception
606+
$this->response = $e->getResponse();
607+
} catch (\GuzzleHttp\Exception\ClientException $e) {
608+
// 4xx responses cause a client exception
609+
$this->response = $e->getResponse();
594610
}
595611
}
596612

build/integration/features/webdav-related.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,12 @@ Feature: webdav-related
608608
And user "user0" uploads new chunk file "3" with "CCCCC" to id "chunking-42"
609609
When user "user0" moves new chunk file with id "chunking-42" to "/myChunkedFile.txt" with size 15
610610
Then the HTTP status code should be "201"
611+
612+
Scenario: Creating a folder with invalid characters
613+
Given using new dav path
614+
And As an "admin"
615+
And user "user0" exists
616+
And user "user1" exists
617+
And As an "user1"
618+
And user "user1" created a folder "/testshare "
619+
Then the HTTP status code should be "400"

lib/private/Files/Storage/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ public function verifyPath($path, $fileName) {
554554
* @throws InvalidPathException
555555
*/
556556
protected function verifyPosixPath($fileName) {
557-
$fileName = trim($fileName);
558557
$this->scanForInvalidCharacters($fileName, "\\/");
558+
$fileName = trim($fileName);
559559
$reservedNames = ['*'];
560560
if (in_array($fileName, $reservedNames)) {
561561
throw new ReservedWordException();

0 commit comments

Comments
 (0)