From 280d70a5f42309b28df0baf675893abed2a391a2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 26 Jun 2024 10:40:31 +0200 Subject: fix(federation): Fix missing protocol on CloudID remote Signed-off-by: Joas Schilling --- lib/private/Federation/CloudIdManager.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/private/Federation') 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); -- cgit v1.2.3