Skip to content

Commit d2f2ee2

Browse files
authored
Merge pull request #42544 from HLFH/fix-chrome-logout
Fix Slow logout on Chrome-like browsers
2 parents ab2bb2b + 08ff644 commit d2f2ee2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

core/Controller/LoginController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636
namespace OC\Core\Controller;
3737

38+
use OC\AppFramework\Http\Request;
3839
use OC\Authentication\Login\Chain;
3940
use OC\Authentication\Login\LoginData;
4041
use OC\Authentication\WebAuthn\Manager as WebAuthnManager;
@@ -105,8 +106,10 @@ public function logout() {
105106
$this->session->set('clearingExecutionContexts', '1');
106107
$this->session->close();
107108

108-
if ($this->request->getServerProtocol() === 'https') {
109-
// This feature is available only in secure contexts
109+
if (
110+
$this->request->getServerProtocol() === 'https' &&
111+
!$this->request->isUserAgent([Request::USER_AGENT_CHROME, Request::USER_AGENT_ANDROID_MOBILE_CHROME])
112+
) {
110113
$response->addHeader('Clear-Site-Data', '"cache", "storage"');
111114
}
112115

tests/Core/Controller/LoginControllerTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ public function testLogoutWithoutToken() {
143143
->with('nc_token')
144144
->willReturn(null);
145145
$this->request
146-
->method('getServerProtocol')
147-
->willReturn('https');
146+
->expects($this->once())
147+
->method('isUserAgent')
148+
->willReturn(false);
148149
$this->config
149150
->expects($this->never())
150151
->method('deleteUserValue');
@@ -159,6 +160,26 @@ public function testLogoutWithoutToken() {
159160
$this->assertEquals($expected, $this->loginController->logout());
160161
}
161162

163+
public function testLogoutNoClearSiteData() {
164+
$this->request
165+
->expects($this->once())
166+
->method('getCookie')
167+
->with('nc_token')
168+
->willReturn(null);
169+
$this->request
170+
->expects($this->once())
171+
->method('isUserAgent')
172+
->willReturn(true);
173+
$this->urlGenerator
174+
->expects($this->once())
175+
->method('linkToRouteAbsolute')
176+
->with('core.login.showLoginForm')
177+
->willReturn('/login');
178+
179+
$expected = new RedirectResponse('/login');
180+
$this->assertEquals($expected, $this->loginController->logout());
181+
}
182+
162183
public function testLogoutWithToken() {
163184
$this->request
164185
->expects($this->once())
@@ -167,8 +188,8 @@ public function testLogoutWithToken() {
167188
->willReturn('MyLoginToken');
168189
$this->request
169190
->expects($this->once())
170-
->method('getServerProtocol')
171-
->willReturn('https');
191+
->method('isUserAgent')
192+
->willReturn(false);
172193
$user = $this->createMock(IUser::class);
173194
$user
174195
->expects($this->once())

0 commit comments

Comments
 (0)