diff --git a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php index aef3c75ca38..de5f5b987d2 100644 --- a/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php +++ b/apps/dav/lib/CalDAV/Federation/CalendarFederationProvider.php @@ -63,6 +63,13 @@ class CalendarFederationProvider implements ICloudFederationProvider { } $rawProtocol = $share->getProtocol(); + if (!isset($rawProtocol[ICalendarFederationProtocol::PROP_VERSION])) { + throw new ProviderCouldNotAddShareException( + 'No protocol version', + '', + Http::STATUS_BAD_REQUEST, + ); + } switch ($rawProtocol[ICalendarFederationProtocol::PROP_VERSION]) { case CalendarFederationProtocolV1::VERSION: try { diff --git a/apps/dav/lib/CalDAV/Federation/FederationSharingService.php b/apps/dav/lib/CalDAV/Federation/FederationSharingService.php index 8dcb8c7cebc..57df75b01a0 100644 --- a/apps/dav/lib/CalDAV/Federation/FederationSharingService.php +++ b/apps/dav/lib/CalDAV/Federation/FederationSharingService.php @@ -46,10 +46,10 @@ class FederationSharingService { */ private function decodeRemoteUserPrincipal(string $principal): ?string { // Expected format: principals/remote-users/abcdef123 - [$prefix, $collection, $encodedId] = explode('/', $principal); - if ($prefix !== 'principals' || $collection !== 'remote-users') { + if (!str_starts_with($principal, 'principals/remote-users/')) { return null; } + $encodedId = substr($principal, strlen('principals/remote-users/')); $decodedId = base64_decode($encodedId); if (!is_string($decodedId)) { diff --git a/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php b/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php index aba2f927934..8e436897789 100644 --- a/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Federation/CalendarFederationProviderTest.php @@ -175,7 +175,7 @@ class CalendarFederationProviderTest extends TestCase { ->method('add'); $this->expectException(ProviderCouldNotAddShareException::class); - $this->expectExceptionMessage('Unknown protocol version'); + $this->expectExceptionMessage('No protocol version'); $this->expectExceptionCode(400); $this->assertEquals(10, $this->calendarFederationProvider->shareReceived($share)); }