Skip to content

Commit 16088cd

Browse files
Merge pull request #55819 from nextcloud/bugfix/noid/allow-federation-with-ocis-cloudids
fix(federation): Allow outgoing and incoming federation with oCIS federated cloud ids
2 parents 802d93e + 75a1a75 commit 16088cd

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

apps/files_sharing/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Turning the feature off removes shared files and folders on the server for all share recipients, and also on the sync clients and mobile apps. More information is available in the Nextcloud Documentation.
1515

1616
</description>
17-
<version>1.25.0</version>
17+
<version>1.25.1</version>
1818
<licence>agpl</licence>
1919
<author>Michael Gapczynski</author>
2020
<author>Bjoern Schiessle</author>

apps/files_sharing/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
'OCA\\Files_Sharing\\Migration\\Version24000Date20220208195521' => $baseDir . '/../lib/Migration/Version24000Date20220208195521.php',
8282
'OCA\\Files_Sharing\\Migration\\Version24000Date20220404142216' => $baseDir . '/../lib/Migration/Version24000Date20220404142216.php',
8383
'OCA\\Files_Sharing\\Migration\\Version31000Date20240821142813' => $baseDir . '/../lib/Migration/Version31000Date20240821142813.php',
84+
'OCA\\Files_Sharing\\Migration\\Version32000Date20251017081948' => $baseDir . '/../lib/Migration/Version32000Date20251017081948.php',
8485
'OCA\\Files_Sharing\\MountProvider' => $baseDir . '/../lib/MountProvider.php',
8586
'OCA\\Files_Sharing\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
8687
'OCA\\Files_Sharing\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',

apps/files_sharing/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class ComposerStaticInitFiles_Sharing
9696
'OCA\\Files_Sharing\\Migration\\Version24000Date20220208195521' => __DIR__ . '/..' . '/../lib/Migration/Version24000Date20220208195521.php',
9797
'OCA\\Files_Sharing\\Migration\\Version24000Date20220404142216' => __DIR__ . '/..' . '/../lib/Migration/Version24000Date20220404142216.php',
9898
'OCA\\Files_Sharing\\Migration\\Version31000Date20240821142813' => __DIR__ . '/..' . '/../lib/Migration/Version31000Date20240821142813.php',
99+
'OCA\\Files_Sharing\\Migration\\Version32000Date20251017081948' => __DIR__ . '/..' . '/../lib/Migration/Version32000Date20251017081948.php',
99100
'OCA\\Files_Sharing\\MountProvider' => __DIR__ . '/..' . '/../lib/MountProvider.php',
100101
'OCA\\Files_Sharing\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
101102
'OCA\\Files_Sharing\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Files_Sharing\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\Attributes\ColumnType;
15+
use OCP\Migration\Attributes\ModifyColumn;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
use Override;
19+
20+
#[ModifyColumn(table: 'share_external', name: 'owner', type: ColumnType::STRING, description: 'Change length to 255 characters')]
21+
class Version32000Date20251017081948 extends SimpleMigrationStep {
22+
/**
23+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
24+
*/
25+
#[Override]
26+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
27+
/** @var ISchemaWrapper $schema */
28+
$schema = $schemaClosure();
29+
30+
$table = $schema->getTable('share_external');
31+
$column = $table->getColumn('owner');
32+
if ($column->getLength() < 255) {
33+
$column->setLength(255);
34+
return $schema;
35+
}
36+
return null;
37+
}
38+
}

lib/private/Federation/CloudIdManager.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function resolveCloudId(string $cloudId): ICloudId {
108108
// We accept slightly more chars when working with federationId than with a local userId.
109109
// We remove those eventual chars from the UserId before using
110110
// the IUserManager API to confirm its format.
111-
$this->userManager->validateUserId(str_replace('=', '-', $user));
111+
$this->validateUser($user, $remote);
112112

113113
if (!empty($user) && !empty($remote)) {
114114
$remote = $this->ensureDefaultProtocol($remote);
@@ -118,6 +118,36 @@ public function resolveCloudId(string $cloudId): ICloudId {
118118
throw new \InvalidArgumentException('Invalid cloud id');
119119
}
120120

121+
protected function validateUser(string $user, string $remote): void {
122+
// Check the ID for bad characters
123+
// Allowed are: "a-z", "A-Z", "0-9", spaces and "_.@-'" (Nextcloud)
124+
// Additional: "=" (oCIS)
125+
if (preg_match('/[^a-zA-Z0-9 _.@\-\'=]/', $user)) {
126+
throw new \InvalidArgumentException('Invalid characters');
127+
}
128+
129+
// No empty user ID
130+
if (trim($user) === '') {
131+
throw new \InvalidArgumentException('Empty user');
132+
}
133+
134+
// No whitespace at the beginning or at the end
135+
if (trim($user) !== $user) {
136+
throw new \InvalidArgumentException('User contains whitespace at the beginning or at the end');
137+
}
138+
139+
// User ID only consists of 1 or 2 dots (directory traversal)
140+
if ($user === '.' || $user === '..') {
141+
throw new \InvalidArgumentException('User must not consist of dots only');
142+
}
143+
144+
// User ID is too long
145+
if (strlen($user . '@' . $remote) > 255) {
146+
// TRANSLATORS User ID is too long
147+
throw new \InvalidArgumentException('Cloud id is too long');
148+
}
149+
}
150+
121151
public function getDisplayNameFromContact(string $cloudId): ?string {
122152
$cachedName = $this->displayNameCache->get($cloudId);
123153
if ($cachedName !== null) {

0 commit comments

Comments
 (0)