Skip to content

Commit 8f2d3fc

Browse files
committed
fix(dav): file drop nickname
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 9fd3656 commit 8f2d3fc

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
@@ -7,6 +7,7 @@
77

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

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

7792
// 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)