Skip to content

Bug/Workaround: Refreshing Office 365 ICS subscription fails #54799

@Cybso

Description

@Cybso

Since a few days or weeks Microsoft denies incoming requests on outlook.office365.com for refreshing ICS calendar subscriptions in Nextcloud.

I did some experiments and found that the seems to be some kind of whitelist check on User-Agent header:

% curl -H 'User-Agent: Nextcloud Webcal Service' 'https://outlook.office365.com/owa/calendar/[...]/reachcalendar.ics' 
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/owa/auth/errorfe.aspx?httpCode=500&amp;msg=...&amp;owaError=Microsoft.Exchange.Clients.Owa2.Server.Core.OwaBasicUnsupportedException&amp;owaVer=15.20.9073.21&amp;be=...&amp;ts=...&amp;fe=...&amp;reqid=&amp;creqid=&amp;cid=&amp;hmac=...">here</a>.</h2>

A minimal working User-Agent I found is Mozilla/5.0 (Linux) Chrome/139:

% curl -H 'User-Agent: Mozilla/5.0 (Linux) Chrome/139' 'https://outlook.office365.com/owa/calendar/[...]/reachcalendar.ics' 
BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:Microsoft Exchange Server 2010
[....]

Of course this is an Outlook issue, but I have no hope that a support call might fix this. So here's a small patch as workaround:

--- apps/dav/lib/CalDAV/WebcalCaching/Connection.php.orig	2025-09-02 11:08:25.447929216 +0200
+++ apps/dav/lib/CalDAV/WebcalCaching/Connection.php	2025-09-02 11:28:36.520658958 +0200
@@ -52,6 +52,12 @@
 			$params[RequestOptions::AUTH] = [$user, $pass];
 		}
 
+		$host = parse_url($subscription['source'], PHP_URL_HOST);
+		if ($host === 'outlook.office365.com') {
+			// https://github.com/nextcloud/server/issues/54799
+			$params[RequestOptions::HEADERS]['User-Agent'] = 'Mozilla/5.0 (Linux) Chrome/139';
+		}
+
 		try {
 			$client = $this->clientService->newClient();
 			$response = $client->get($url, $params)

Even if this won't get merged into Nextcloud this issue might help users to find out what's going on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    4. to releaseReady to be released and/or waiting for tests to finishbugfeature: caldavRelated to CalDAV internals

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions