Skip to content

Commit 28d02b6

Browse files
committed
Merge #252 [backport25] No session on DAV API call
2 parents 826f416 + 311ff80 commit 28d02b6

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

apps/files/lib/Controller/ViewController.php

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ protected function getStorageInfo() {
158158
/**
159159
* @NoCSRFRequired
160160
* @NoAdminRequired
161+
* @UseSession
161162
*
162163
* @param string $fileid
163164
* @return TemplateResponse|RedirectResponse

lib/base.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
use OCP\EventDispatcher\IEventDispatcher;
6767
use OCP\Group\Events\UserRemovedEvent;
6868
use OCP\ILogger;
69+
use OCP\IRequest;
6970
use OCP\Server;
7071
use OCP\Share;
7172
use OC\Encryption\HookManager;
@@ -414,8 +415,22 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig) {
414415
$tmpl->printPage();
415416
}
416417

417-
public static function initSession() {
418-
if (self::$server->getRequest()->getServerProtocol() === 'https') {
418+
public static function initSession(): void {
419+
$request = Server::get(IRequest::class);
420+
421+
// TODO: Temporary disabled again to solve issues with CalDAV/CardDAV clients like DAVx5 that use cookies
422+
// TODO: See https://github.com/nextcloud/server/issues/37277#issuecomment-1476366147 and the other comments
423+
// TODO: for further information.
424+
// MagentaCLOUD stays with original version of the solution from production
425+
$isDavRequest = strpos($request->getRequestUri(), '/remote.php/dav') === 0 ||
426+
strpos($request->getRequestUri(), '/remote.php/webdav') === 0;
427+
if ($request->getHeader('Authorization') !== '' && $isDavRequest && !isset($_COOKIE['nc_session_id'])) {
428+
// Do not initialize the session if a request is authenticated directly
429+
// unless there is a session cookie already sent along
430+
return;
431+
}
432+
433+
if ($request->getServerProtocol() === 'https') {
419434
ini_set('session.cookie_secure', 'true');
420435
}
421436

lib/private/Authentication/TwoFactorAuth/Manager.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCP\IConfig;
4343
use OCP\ISession;
4444
use OCP\IUser;
45+
use OCP\Session\Exceptions\SessionNotAvailableException;
4546
use Psr\Log\LoggerInterface;
4647
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4748
use Symfony\Component\EventDispatcher\GenericEvent;
@@ -362,7 +363,7 @@ public function needsSecondFactor(IUser $user = null): bool {
362363
$this->session->set(self::SESSION_UID_DONE, $user->getUID());
363364
return false;
364365
}
365-
} catch (InvalidTokenException $e) {
366+
} catch (InvalidTokenException|SessionNotAvailableException $e) {
366367
}
367368
}
368369

0 commit comments

Comments
 (0)