Skip to content

Commit

Permalink
Merge pull request #37405 from nextcloud/clear-site-data
Browse files Browse the repository at this point in the history
Send Clear-Site-Data header and let browsers ignore it if unsupported
  • Loading branch information
skjnldsv authored Mar 28, 2023
2 parents 7db8e22 + 346054f commit 8ee52d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
4 changes: 2 additions & 2 deletions core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"');
}

Expand Down
29 changes: 4 additions & 25 deletions tests/Core/Controller/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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())
Expand All @@ -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())
Expand Down

0 comments on commit 8ee52d3

Please sign in to comment.