Skip to content

Commit bbf7920

Browse files
Merge pull request #53279 from nextcloud/backport/53278/stable30
[stable30] fix(dav): file drop nickname
2 parents b166d4b + 04b5d37 commit bbf7920

18 files changed

+139
-21
lines changed

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

apps/files_sharing/src/views/PublicAuthPrompt.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@
4949

5050
<script lang="ts">
5151
import { defineComponent } from 'vue'
52+
import { loadState } from '@nextcloud/initial-state'
5253
import { t } from '@nextcloud/l10n'
5354
5455
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
5556
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
5657
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
5758
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
58-
import { loadState } from '@nextcloud/initial-state'
59+
60+
import { getFilenameValidity } from '../../../files/src/utils/filenameValidity'
5961
6062
export default defineComponent({
6163
name: 'PublicAuthPrompt',
@@ -91,6 +93,21 @@ export default defineComponent({
9193
},
9294
},
9395
96+
watch: {
97+
name() {
98+
// Check validity of the new name
99+
const newName = this.name.trim?.() || ''
100+
const input = (this.$refs.input as Vue|undefined)?.$el.querySelector('input')
101+
if (!input) {
102+
return
103+
}
104+
105+
const validity = getFilenameValidity(newName)
106+
input.setCustomValidity(validity)
107+
input.reportValidity()
108+
},
109+
},
110+
94111
beforeMount() {
95112
// Pre-load the name from local storage if already set by another app
96113
// like Talk, Colabora or Text...

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"

dist/2142-2142.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,62 @@ SPDX-FileCopyrightText: escape-html developers
88
SPDX-FileCopyrightText: assert developers
99
SPDX-FileCopyrightText: Tobias Koppers @sokra
1010
SPDX-FileCopyrightText: Roman Shtylman <[email protected]>
11+
SPDX-FileCopyrightText: Roeland Jago Douma
1112
SPDX-FileCopyrightText: Raynos <[email protected]>
1213
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
1314
SPDX-FileCopyrightText: Joyent
1415
SPDX-FileCopyrightText: Jordan Harband <[email protected]>
1516
SPDX-FileCopyrightText: Jordan Harband
17+
SPDX-FileCopyrightText: Jonas Schade <[email protected]>
1618
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
1719
SPDX-FileCopyrightText: Guillaume Chau <[email protected]>
20+
SPDX-FileCopyrightText: GitHub Inc.
1821
SPDX-FileCopyrightText: Evan You
1922
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
2023
SPDX-FileCopyrightText: David Clark
24+
SPDX-FileCopyrightText: Christoph Wurst <[email protected]>
2125
SPDX-FileCopyrightText: Christoph Wurst
2226
SPDX-FileCopyrightText: Anthony Fu <https://github.com/antfu>
27+
SPDX-FileCopyrightText: Alkemics
2328

2429

2530
This file is generated from multiple sources. Included packages:
31+
- @nextcloud/auth
32+
- version: 2.5.1
33+
- license: GPL-3.0-or-later
34+
- @nextcloud/browser-storage
35+
- version: 0.4.0
36+
- license: GPL-3.0-or-later
37+
- @nextcloud/capabilities
38+
- version: 1.2.0
39+
- license: GPL-3.0-or-later
40+
- semver
41+
- version: 7.6.3
42+
- license: ISC
43+
- @nextcloud/event-bus
44+
- version: 3.3.2
45+
- license: GPL-3.0-or-later
46+
- @nextcloud/files
47+
- version: 3.10.2
48+
- license: AGPL-3.0-or-later
2649
- @nextcloud/initial-state
2750
- version: 2.2.0
2851
- license: GPL-3.0-or-later
2952
- @nextcloud/l10n
3053
- version: 3.2.0
3154
- license: GPL-3.0-or-later
55+
- @nextcloud/logger
56+
- version: 3.0.2
57+
- license: GPL-3.0-or-later
58+
- @nextcloud/paths
59+
- version: 2.2.1
60+
- license: GPL-3.0-or-later
3261
- @nextcloud/router
3362
- version: 3.0.1
3463
- license: GPL-3.0-or-later
64+
- @nextcloud/sharing
65+
- version: 0.2.4
66+
- license: GPL-3.0-or-later
3567
- @nextcloud/vue
3668
- version: 8.27.0
3769
- license: AGPL-3.0-or-later
@@ -56,6 +88,9 @@ This file is generated from multiple sources. Included packages:
5688
- call-bound
5789
- version: 1.0.4
5890
- license: MIT
91+
- cancelable-promise
92+
- version: 4.3.1
93+
- license: MIT
5994
- console-browserify
6095
- version: 1.2.0
6196
- license: MIT
@@ -149,6 +184,15 @@ This file is generated from multiple sources. Included packages:
149184
- object.assign
150185
- version: 4.1.7
151186
- license: MIT
187+
- inherits
188+
- version: 2.0.3
189+
- license: ISC
190+
- util
191+
- version: 0.10.4
192+
- license: MIT
193+
- path
194+
- version: 0.12.7
195+
- license: MIT
152196
- possible-typed-array-names
153197
- version: 1.0.0
154198
- license: MIT
@@ -164,6 +208,9 @@ This file is generated from multiple sources. Included packages:
164208
- tabbable
165209
- version: 6.2.0
166210
- license: MIT
211+
- typescript-event-target
212+
- version: 1.1.1
213+
- license: MIT
167214
- util
168215
- version: 0.12.5
169216
- license: MIT

dist/2142-2142.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/2142-2142.js.map.license

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2142-2142.js.license

dist/5315-5315.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)