Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport25] No session on DAV API call #252

Open
wants to merge 2 commits into
base: stable25
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ protected function getStorageInfo() {
/**
* @NoCSRFRequired
* @NoAdminRequired
* @UseSession
*
* @param string $fileid
* @return TemplateResponse|RedirectResponse
Expand Down
19 changes: 17 additions & 2 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\UserRemovedEvent;
use OCP\ILogger;
use OCP\IRequest;
use OCP\Server;
use OCP\Share;
use OC\Encryption\HookManager;
Expand Down Expand Up @@ -414,8 +415,22 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig) {
$tmpl->printPage();
}

public static function initSession() {
if (self::$server->getRequest()->getServerProtocol() === 'https') {
public static function initSession(): void {
$request = Server::get(IRequest::class);

// TODO: Temporary disabled again to solve issues with CalDAV/CardDAV clients like DAVx5 that use cookies
// TODO: See https://github.com/nextcloud/server/issues/37277#issuecomment-1476366147 and the other comments
// TODO: for further information.
// MagentaCLOUD stays with original version of the solution from production
$isDavRequest = strpos($request->getRequestUri(), '/remote.php/dav') === 0 ||
strpos($request->getRequestUri(), '/remote.php/webdav') === 0;
if ($request->getHeader('Authorization') !== '' && $isDavRequest && !isset($_COOKIE['nc_session_id'])) {
// Do not initialize the session if a request is authenticated directly
// unless there is a session cookie already sent along
return;
}

if ($request->getServerProtocol() === 'https') {
ini_set('session.cookie_secure', 'true');
}

Expand Down
3 changes: 2 additions & 1 deletion lib/private/Authentication/TwoFactorAuth/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCP\IConfig;
use OCP\ISession;
use OCP\IUser;
use OCP\Session\Exceptions\SessionNotAvailableException;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand Down Expand Up @@ -362,7 +363,7 @@ public function needsSecondFactor(IUser $user = null): bool {
$this->session->set(self::SESSION_UID_DONE, $user->getUID());
return false;
}
} catch (InvalidTokenException $e) {
} catch (InvalidTokenException|SessionNotAvailableException $e) {
}
}

Expand Down