aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2024-09-27 19:16:59 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2024-10-01 18:00:46 +0200
commit870816466f2d1adaf956a83491c0645556b0d02b (patch)
tree2c06b7d333cacf155c07d21870628ba09ce20e32 /apps/dav/lib
parent26762172f5697febc7971a0bf5ac83d7a4c3cf35 (diff)
downloadnextcloud-server-870816466f2d1adaf956a83491c0645556b0d02b.tar.gz
nextcloud-server-870816466f2d1adaf956a83491c0645556b0d02b.zip
fix: make federation address book sync work with allow_local_remote_servers = false
Client.preventLocalAddress expects an absolute URL, which means the base_uri option cannot be used. Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CardDAV/SyncService.php46
1 files changed, 36 insertions, 10 deletions
diff --git a/apps/dav/lib/CardDAV/SyncService.php b/apps/dav/lib/CardDAV/SyncService.php
index 5f8752a9d49..05a08d08286 100644
--- a/apps/dav/lib/CardDAV/SyncService.php
+++ b/apps/dav/lib/CardDAV/SyncService.php
@@ -108,25 +108,54 @@ class SyncService {
}, $this->dbConnection);
}
+ private function prepareUri(string $host, string $path): string {
+ /*
+ * The trailing slash is important for merging the uris together.
+ *
+ * $host is stored in oc_trusted_servers.url and usually without a trailing slash.
+ *
+ * Example for a report request
+ *
+ * $host = 'https://server.internal/cloud'
+ * $path = 'remote.php/dav/addressbooks/system/system/system'
+ *
+ * Without the trailing slash, the webroot is missing:
+ * https://server.internal/remote.php/dav/addressbooks/system/system/system
+ *
+ * Example for a download request
+ *
+ * $host = 'https://server.internal/cloud'
+ * $path = '/cloud/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf'
+ *
+ * The response from the remote usually contains the webroot already and must be normalized to:
+ * https://server.internal/cloud/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf
+ */
+ $host = rtrim($host, '/') . '/';
+
+ $uri = \GuzzleHttp\Psr7\UriResolver::resolve(
+ \GuzzleHttp\Psr7\Utils::uriFor($host),
+ \GuzzleHttp\Psr7\Utils::uriFor($path)
+ );
+
+ return (string)$uri;
+ }
+
/**
* @throws ClientExceptionInterface
*/
protected function requestSyncReport(string $url, string $userName, string $addressBookUrl, string $sharedSecret, ?string $syncToken): array {
$client = $this->clientService->newClient();
-
- // the trailing slash is important for merging base_uri and uri
- $url = rtrim($url, '/') . '/';
+ $uri = $this->prepareUri($url, $addressBookUrl);
$options = [
'auth' => [$userName, $sharedSecret],
- 'base_uri' => $url,
'body' => $this->buildSyncCollectionRequestBody($syncToken),
'headers' => ['Content-Type' => 'application/xml']
];
$response = $client->request(
'REPORT',
- $addressBookUrl,
+ $uri,
$options
);
@@ -138,17 +167,14 @@ class SyncService {
protected function download(string $url, string $userName, string $sharedSecret, string $resourcePath): string {
$client = $this->clientService->newClient();
-
- // the trailing slash is important for merging base_uri and uri
- $url = rtrim($url, '/') . '/';
+ $uri = $this->prepareUri($url, $resourcePath);
$options = [
'auth' => [$userName, $sharedSecret],
- 'base_uri' => $url,
];
$response = $client->get(
- $resourcePath,
+ $uri,
$options
);