diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index 72f69241c9d02..beeb2034fb7cf 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -35,6 +35,7 @@ */ namespace OC\Core\Controller; +use OC\AppFramework\Http\Request; use OC\Authentication\Login\Chain; use OC\Authentication\Login\LoginData; use OC\Authentication\WebAuthn\Manager as WebAuthnManager; @@ -105,8 +106,10 @@ public function logout() { $this->session->set('clearingExecutionContexts', '1'); $this->session->close(); - if ($this->request->getServerProtocol() === 'https') { - // This feature is available only in secure contexts + if ( + $this->request->getServerProtocol() === 'https' && + !$this->request->isUserAgent([Request::USER_AGENT_CHROME, Request::USER_AGENT_ANDROID_MOBILE_CHROME]) + ) { $response->addHeader('Clear-Site-Data', '"cache", "storage"'); } diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index 7d82e256c1751..c17f307d4c79d 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -145,6 +145,10 @@ public function testLogoutWithoutToken() { $this->request ->method('getServerProtocol') ->willReturn('https'); + $this->request + ->expects($this->once()) + ->method('isUserAgent') + ->willReturn(false); $this->config ->expects($this->never()) ->method('deleteUserValue'); @@ -159,6 +163,29 @@ public function testLogoutWithoutToken() { $this->assertEquals($expected, $this->loginController->logout()); } + public function testLogoutNoClearSiteData() { + $this->request + ->expects($this->once()) + ->method('getCookie') + ->with('nc_token') + ->willReturn(null); + $this->request + ->method('getServerProtocol') + ->willReturn('https'); + $this->request + ->expects($this->once()) + ->method('isUserAgent') + ->willReturn(true); + $this->urlGenerator + ->expects($this->once()) + ->method('linkToRouteAbsolute') + ->with('core.login.showLoginForm') + ->willReturn('/login'); + + $expected = new RedirectResponse('/login'); + $this->assertEquals($expected, $this->loginController->logout()); + } + public function testLogoutWithToken() { $this->request ->expects($this->once()) @@ -166,9 +193,12 @@ public function testLogoutWithToken() { ->with('nc_token') ->willReturn('MyLoginToken'); $this->request - ->expects($this->once()) ->method('getServerProtocol') ->willReturn('https'); + $this->request + ->expects($this->once()) + ->method('isUserAgent') + ->willReturn(false); $user = $this->createMock(IUser::class); $user ->expects($this->once())