diff options
author | Joas Schilling <coding@schilljs.com> | 2024-06-26 10:40:31 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-06-27 11:26:08 +0200 |
commit | 280d70a5f42309b28df0baf675893abed2a391a2 (patch) | |
tree | d13cfa72cc6958f85eea11322cfa9c89d164b7d2 /lib/private/Federation | |
parent | 5dcb807a98a9863f7d730c3f190e85311eda512b (diff) | |
download | nextcloud-server-280d70a5f42309b28df0baf675893abed2a391a2.tar.gz nextcloud-server-280d70a5f42309b28df0baf675893abed2a391a2.zip |
fix(federation): Fix missing protocol on CloudID remote
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Federation')
-rw-r--r-- | lib/private/Federation/CloudIdManager.php | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php index cd5e4d511c3..3528d06a167 100644 --- a/lib/private/Federation/CloudIdManager.php +++ b/lib/private/Federation/CloudIdManager.php @@ -84,7 +84,7 @@ class CloudIdManager implements ICloudIdManager { } // Find the first character that is not allowed in user names - $id = $this->fixRemoteURL($cloudId); + $id = $this->stripShareLinkFragments($cloudId); $posSlash = strpos($id, '/'); $posColon = strpos($id, ':'); @@ -107,6 +107,7 @@ class CloudIdManager implements ICloudIdManager { $this->userManager->validateUserId($user); if (!empty($user) && !empty($remote)) { + $remote = $this->ensureDefaultProtocol($remote); return new CloudId($id, $user, $remote, $this->getDisplayNameFromContact($id)); } } @@ -152,8 +153,9 @@ class CloudIdManager implements ICloudIdManager { // note that for remote id's we don't strip the protocol for the remote we use to construct the CloudId // this way if a user has an explicit non-https cloud id this will be preserved // we do still use the version without protocol for looking up the display name - $remote = $this->fixRemoteURL($remote); + $remote = $this->stripShareLinkFragments($remote); $host = $this->removeProtocolFromUrl($remote); + $remote = $this->ensureDefaultProtocol($remote); $key = $user . '@' . ($isLocal ? 'local' : $host); $cached = $this->cache[$key] ?? $this->memCache->get($key); @@ -198,6 +200,14 @@ class CloudIdManager implements ICloudIdManager { return $url; } + protected function ensureDefaultProtocol(string $remote): string { + if (!str_contains($remote, '://')) { + $remote = 'https://' . $remote; + } + + return $remote; + } + /** * Strips away a potential file names and trailing slashes: * - http://localhost @@ -210,7 +220,7 @@ class CloudIdManager implements ICloudIdManager { * @param string $remote * @return string */ - protected function fixRemoteURL(string $remote): string { + protected function stripShareLinkFragments(string $remote): string { $remote = str_replace('\\', '/', $remote); if ($fileNamePosition = strpos($remote, '/index.php')) { $remote = substr($remote, 0, $fileNamePosition); |