Skip to content

Commit cccf5a2

Browse files
committed
fix(dav): file drop nickname
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 709fa4b commit cccf5a2

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

apps/dav/lib/Files/Sharing/FilesDropPlugin.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use OC\Files\View;
1010
use OCP\Share\IShare;
11+
use Sabre\DAV\Exception\BadRequest;
1112
use Sabre\DAV\Exception\MethodNotAllowed;
1213
use Sabre\DAV\ServerPlugin;
1314
use Sabre\HTTP\RequestInterface;
@@ -65,14 +66,28 @@ public function beforeMethod(RequestInterface $request, ResponseInterface $respo
6566
// Extract the attributes for the file request
6667
$isFileRequest = false;
6768
$attributes = $this->share->getAttributes();
68-
$nickName = $request->hasHeader('X-NC-Nickname') ? urldecode($request->getHeader('X-NC-Nickname')) : null;
69+
$nickName = $request->hasHeader('X-NC-Nickname') ? trim(urldecode($request->getHeader('X-NC-Nickname'))) : null;
6970
if ($attributes !== null) {
7071
$isFileRequest = $attributes->getAttribute('fileRequest', 'enabled') === true;
7172
}
7273

7374
// We need a valid nickname for file requests
74-
if ($isFileRequest && ($nickName == null || trim($nickName) === '')) {
75-
throw new MethodNotAllowed('Nickname is required for file requests');
75+
if ($isFileRequest && !$nickName) {
76+
throw new BadRequest('Nickname is required for file requests');
77+
}
78+
79+
if ($nickName !== null) {
80+
try {
81+
$this->view->verifyPath($path, $nickName);
82+
} catch (\Exception $e) {
83+
// If the path is not valid, we throw an exception
84+
throw new BadRequest('Invalid nickname: ' . $nickName);
85+
}
86+
87+
// Forbid nicknames starting with a dot
88+
if (str_starts_with($nickName, '.')) {
89+
throw new BadRequest('Invalid nickname: ' . $nickName);
90+
}
7691
}
7792

7893
// If this is a file request we need to create a folder for the user

build/integration/filesdrop_features/filesdrop.feature

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Feature: FilesDrop
4747
And Downloading file "/drop/a.txt"
4848
Then Downloaded content should be "abc"
4949

50-
Scenario: Files drop forbis MKCOL
50+
Scenario: Files drop forbid MKCOL
5151
Given user "user0" exists
5252
And As an "user0"
5353
And user "user0" created a folder "/drop"
@@ -90,3 +90,42 @@ Feature: FilesDrop
9090
Then Downloaded content should be "abc"
9191
And Downloading file "/drop/Mallory/a (2).txt"
9292
Then Downloaded content should be "def"
93+
94+
Scenario: Files request drop with invalid nickname with slashes
95+
Given user "user0" exists
96+
And As an "user0"
97+
And user "user0" created a folder "/drop"
98+
And as "user0" creating a share with
99+
| path | drop |
100+
| shareType | 4 |
101+
| permissions | 4 |
102+
| attributes | [{"scope":"fileRequest","key":"enabled","value":true}] |
103+
| shareWith | |
104+
When Dropping file "/folder/a.txt" with "abc" as "Alice/Bob/Mallory"
105+
Then the HTTP status code should be "400"
106+
107+
Scenario: Files request drop with invalid nickname with forbidden characters
108+
Given user "user0" exists
109+
And As an "user0"
110+
And user "user0" created a folder "/drop"
111+
And as "user0" creating a share with
112+
| path | drop |
113+
| shareType | 4 |
114+
| permissions | 4 |
115+
| attributes | [{"scope":"fileRequest","key":"enabled","value":true}] |
116+
| shareWith | |
117+
When Dropping file "/folder/a.txt" with "abc" as ".htaccess"
118+
Then the HTTP status code should be "400"
119+
120+
Scenario: Files request drop with invalid nickname with forbidden characters
121+
Given user "user0" exists
122+
And As an "user0"
123+
And user "user0" created a folder "/drop"
124+
And as "user0" creating a share with
125+
| path | drop |
126+
| shareType | 4 |
127+
| permissions | 4 |
128+
| attributes | [{"scope":"fileRequest","key":"enabled","value":true}] |
129+
| shareWith | |
130+
When Dropping file "/folder/a.txt" with "abc" as ".Mallory"
131+
Then the HTTP status code should be "400"

0 commit comments

Comments
 (0)