Skip to content

Commit

Permalink
Merge pull request #48519 from nextcloud/bug/48518/ignore-invalid-dates
Browse files Browse the repository at this point in the history
fix(dav): don't crash subscription on invalid calendar object
  • Loading branch information
SebastianKrupinski authored Oct 2, 2024
2 parents 16d125c + a5eb38f commit 2d004c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions apps/dav/lib/CalDAV/WebcalCaching/RefreshWebcalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\AppFramework\Utility\ITimeFactory;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\PropPatch;
use Sabre\VObject\Component;
use Sabre\VObject\DateTimeParser;
Expand Down Expand Up @@ -101,7 +102,13 @@ public function refreshSubscription(string $principalUri, string $uri) {
continue;
}

$denormalized = $this->calDavBackend->getDenormalizedData($vObject->serialize());
try {
$denormalized = $this->calDavBackend->getDenormalizedData($vObject->serialize());
} catch (InvalidDataException|Forbidden $ex) {
$this->logger->warning('Unable to denormalize calendar object from subscription {subscriptionId}', ['exception' => $ex, 'subscriptionId' => $subscription['id'], 'source' => $subscription['source']]);
continue;
}

// Find all identical sets and remove them from the update
if (isset($localData[$uid]) && $denormalized['etag'] === $localData[$uid]['etag']) {
unset($localData[$uid]);
Expand All @@ -127,7 +134,7 @@ public function refreshSubscription(string $principalUri, string $uri) {
$objectUri = $this->getRandomCalendarObjectUri();
$this->calDavBackend->createCalendarObject($subscription['id'], $objectUri, $vObject->serialize(), CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
} catch (NoInstancesException|BadRequest $ex) {
$this->logger->error('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $ex, 'subscriptionId' => $subscription['id'], 'source' => $subscription['source']]);
$this->logger->warning('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $ex, 'subscriptionId' => $subscription['id'], 'source' => $subscription['source']]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function testRunCreateCalendarNoException(string $body, string $contentTy
->willThrowException($noInstanceException);

$this->logger->expects(self::once())
->method('error')
->method('warning')
->with('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $noInstanceException, 'subscriptionId' => '42', 'source' => 'webcal://foo.bar/bla2']);

$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
Expand Down Expand Up @@ -302,7 +302,7 @@ public function testRunCreateCalendarBadRequest(string $body, string $contentTyp
->willThrowException($badRequestException);

$this->logger->expects(self::once())
->method('error')
->method('warning')
->with('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $badRequestException, 'subscriptionId' => '42', 'source' => 'webcal://foo.bar/bla2']);

$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
Expand Down

0 comments on commit 2d004c3

Please sign in to comment.