From cfd7a571849ece0572b6e801cf0f21666e519ddb Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Sat, 25 Mar 2023 23:58:14 +0100 Subject: [PATCH 1/2] Send header to all browsers under HTTPS Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Don't send Clear-Site-Data to Safari Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Fix lint Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- core/Controller/LoginController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index d3873d1329e31..2ddba2bb98abf 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -34,7 +34,6 @@ */ 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; @@ -125,7 +124,8 @@ public function logout() { $this->session->set('clearingExecutionContexts', '1'); $this->session->close(); - if (!$this->request->isUserAgent([Request::USER_AGENT_CHROME, Request::USER_AGENT_ANDROID_MOBILE_CHROME])) { + if ($this->request->getServerProtocol() === 'https') { + // This feature is available only in secure contexts $response->addHeader('Clear-Site-Data', '"cache", "storage"'); } From 346054f85402bcf6a2ccd9d672abf6d9194ea793 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Tue, 28 Mar 2023 09:41:04 +0200 Subject: [PATCH 2/2] Fix tests Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- tests/Core/Controller/LoginControllerTest.php | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index ae033582d3c41..6044440bdaf0e 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -143,9 +143,8 @@ public function testLogoutWithoutToken() { ->with('nc_token') ->willReturn(null); $this->request - ->expects($this->once()) - ->method('isUserAgent') - ->willReturn(false); + ->method('getServerProtocol') + ->willReturn('https'); $this->config ->expects($this->never()) ->method('deleteUserValue'); @@ -160,26 +159,6 @@ 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 - ->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()) @@ -188,8 +167,8 @@ public function testLogoutWithToken() { ->willReturn('MyLoginToken'); $this->request ->expects($this->once()) - ->method('isUserAgent') - ->willReturn(false); + ->method('getServerProtocol') + ->willReturn('https'); $user = $this->createMock(IUser::class); $user ->expects($this->once())