aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2024-06-27 14:59:19 +0200
committerGitHub <noreply@github.com>2024-06-27 14:59:19 +0200
commit00aa8f543841c6bfd853a3ac5cb4ff3ab0a058ae (patch)
treeb47151ce86cfd6c5ea2ea3313c6775406e4ad1ca /lib
parent1b49c864808dd95d069cf4ffe4c3fb1794aa8ca8 (diff)
parent280d70a5f42309b28df0baf675893abed2a391a2 (diff)
downloadnextcloud-server-00aa8f543841c6bfd853a3ac5cb4ff3ab0a058ae.tar.gz
nextcloud-server-00aa8f543841c6bfd853a3ac5cb4ff3ab0a058ae.zip
Merge pull request #46133 from nextcloud/bugfix/noid/fix-missing-protocol-on-remotes
fix(federation): Fix missing protocol on CloudID remote
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Collaboration/Collaborators/RemotePlugin.php2
-rw-r--r--lib/private/Federation/CloudIdManager.php16
-rw-r--r--lib/public/Federation/ICloudIdManager.php4
3 files changed, 17 insertions, 5 deletions
diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php
index e46b71eb710..788ece70cb9 100644
--- a/lib/private/Collaboration/Collaborators/RemotePlugin.php
+++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php
@@ -157,7 +157,7 @@ class RemotePlugin implements ISearchPlugin {
public function splitUserRemote(string $address): array {
try {
$cloudId = $this->cloudIdManager->resolveCloudId($address);
- return [$cloudId->getUser(), $cloudId->getRemote()];
+ return [$cloudId->getUser(), $this->cloudIdManager->removeProtocolFromUrl($cloudId->getRemote(), true)];
} catch (\InvalidArgumentException $e) {
throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
}
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);
diff --git a/lib/public/Federation/ICloudIdManager.php b/lib/public/Federation/ICloudIdManager.php
index 09ef0aae0fa..03b6ced18f5 100644
--- a/lib/public/Federation/ICloudIdManager.php
+++ b/lib/public/Federation/ICloudIdManager.php
@@ -48,9 +48,11 @@ interface ICloudIdManager {
* remove scheme/protocol from an url
*
* @param string $url
+ * @param bool $httpsOnly
*
* @return string
* @since 28.0.0
+ * @since 30.0.0 - Optional parameter $httpsOnly was added
*/
- public function removeProtocolFromUrl(string $url): string;
+ public function removeProtocolFromUrl(string $url, bool $httpsOnly = false): string;
}