From dababa5138a4c6c313bb731f20356a2fb169f7e1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2024 13:20:16 +0100 Subject: fix(federation): Fix creating local cloudIds with http:// protocol Signed-off-by: Joas Schilling --- lib/private/Federation/CloudIdManager.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/private/Federation/CloudIdManager.php b/lib/private/Federation/CloudIdManager.php index 22b06af386f..70431ce2289 100644 --- a/lib/private/Federation/CloudIdManager.php +++ b/lib/private/Federation/CloudIdManager.php @@ -168,17 +168,16 @@ class CloudIdManager implements ICloudIdManager { public function getCloudId(string $user, ?string $remote): ICloudId { $isLocal = $remote === null; if ($isLocal) { - $remote = rtrim($this->removeProtocolFromUrl($this->urlGenerator->getAbsoluteURL('/')), '/'); - $fixedRemote = $this->fixRemoteURL($remote); - $host = $fixedRemote; - } else { - // 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 - $fixedRemote = $this->fixRemoteURL($remote); - $host = $this->removeProtocolFromUrl($fixedRemote); + $remote = rtrim($this->urlGenerator->getAbsoluteURL('/'), '/'); } + // 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->removeProtocolFromUrl($remote, true); + $remote = $this->fixRemoteURL($remote); + $host = $this->removeProtocolFromUrl($remote); + $key = $user . '@' . ($isLocal ? 'local' : $host); $cached = $this->cache[$key] ?? $this->memCache->get($key); if ($cached) { @@ -197,23 +196,23 @@ class CloudIdManager implements ICloudIdManager { $data = [ 'id' => $id, 'user' => $user, - 'remote' => $fixedRemote, + 'remote' => $remote, 'displayName' => $displayName, ]; $this->cache[$key] = $data; $this->memCache->set($key, $data, 15 * 60); - return new CloudId($id, $user, $fixedRemote, $displayName); + return new CloudId($id, $user, $remote, $displayName); } /** * @param string $url * @return string */ - public function removeProtocolFromUrl(string $url): string { + public function removeProtocolFromUrl(string $url, bool $httpsOnly = false): string { if (str_starts_with($url, 'https://')) { return substr($url, 8); } - if (str_starts_with($url, 'http://')) { + if (!$httpsOnly && str_starts_with($url, 'http://')) { return substr($url, 7); } -- cgit v1.2.3