Skip to content

Commit 2c0d6d9

Browse files
Merge pull request #55976 from nextcloud/backport/55819/stable31
[stable31] fix(federation): Allow outgoing and incoming federation with oCIS federated cloud ids
2 parents 42d51aa + 21651a2 commit 2c0d6d9

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.23.1</version>
17+
<version>1.23.2</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
@@ -80,6 +80,7 @@
8080
'OCA\\Files_Sharing\\Migration\\Version24000Date20220208195521' => $baseDir . '/../lib/Migration/Version24000Date20220208195521.php',
8181
'OCA\\Files_Sharing\\Migration\\Version24000Date20220404142216' => $baseDir . '/../lib/Migration/Version24000Date20220404142216.php',
8282
'OCA\\Files_Sharing\\Migration\\Version31000Date20240821142813' => $baseDir . '/../lib/Migration/Version31000Date20240821142813.php',
83+
'OCA\\Files_Sharing\\Migration\\Version32000Date20251017081948' => $baseDir . '/../lib/Migration/Version32000Date20251017081948.php',
8384
'OCA\\Files_Sharing\\MountProvider' => $baseDir . '/../lib/MountProvider.php',
8485
'OCA\\Files_Sharing\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
8586
'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
@@ -95,6 +95,7 @@ class ComposerStaticInitFiles_Sharing
9595
'OCA\\Files_Sharing\\Migration\\Version24000Date20220208195521' => __DIR__ . '/..' . '/../lib/Migration/Version24000Date20220208195521.php',
9696
'OCA\\Files_Sharing\\Migration\\Version24000Date20220404142216' => __DIR__ . '/..' . '/../lib/Migration/Version24000Date20220404142216.php',
9797
'OCA\\Files_Sharing\\Migration\\Version31000Date20240821142813' => __DIR__ . '/..' . '/../lib/Migration/Version31000Date20240821142813.php',
98+
'OCA\\Files_Sharing\\Migration\\Version32000Date20251017081948' => __DIR__ . '/..' . '/../lib/Migration/Version32000Date20251017081948.php',
9899
'OCA\\Files_Sharing\\MountProvider' => __DIR__ . '/..' . '/../lib/MountProvider.php',
99100
'OCA\\Files_Sharing\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
100101
'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
@@ -109,7 +109,7 @@ public function resolveCloudId(string $cloudId): ICloudId {
109109
// We accept slightly more chars when working with federationId than with a local userId.
110110
// We remove those eventual chars from the UserId before using
111111
// the IUserManager API to confirm its format.
112-
$this->userManager->validateUserId(str_replace('=', '-', $user));
112+
$this->validateUser($user, $remote);
113113

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

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

0 commit comments

Comments
 (0)