Skip to content

Commit 6e110c3

Browse files
authored
Merge pull request #14275 from nextcloud/backport/12573/stable15
[stable15] Do not do redirect handling when loggin out
2 parents f6b4f1f + 78842d2 commit 6e110c3

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

core/Controller/LoginController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public function logout() {
131131
$this->userSession->logout();
132132

133133
$response = new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
134+
$this->session->set('clearingExecutionContexts', '1');
135+
$this->session->close();
134136
$response->addHeader('Clear-Site-Data', '"cache", "storage", "executionContexts"');
135137
return $response;
136138
}
@@ -146,7 +148,6 @@ public function logout() {
146148
* @return TemplateResponse|RedirectResponse
147149
*/
148150
public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response {
149-
150151
if ($this->userSession->isLoggedIn()) {
151152
return new RedirectResponse(OC_Util::getDefaultPageUrl());
152153
}

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,12 @@
430430
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotAdminException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php',
431431
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotConfirmedException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotConfirmedException.php',
432432
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotLoggedInException.php',
433+
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\ReloadExecutionException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/ReloadExecutionException.php',
433434
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\SecurityException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/SecurityException.php',
434435
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php',
435436
'OC\\AppFramework\\Middleware\\Security\\PasswordConfirmationMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php',
436437
'OC\\AppFramework\\Middleware\\Security\\RateLimitingMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php',
438+
'OC\\AppFramework\\Middleware\\Security\\ReloadExecutionMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/ReloadExecutionMiddleware.php',
437439
'OC\\AppFramework\\Middleware\\Security\\SameSiteCookieMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php',
438440
'OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php',
439441
'OC\\AppFramework\\Middleware\\SessionMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/SessionMiddleware.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,12 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
460460
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotAdminException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php',
461461
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotConfirmedException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotConfirmedException.php',
462462
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotLoggedInException.php',
463+
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\ReloadExecutionException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/ReloadExecutionException.php',
463464
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\SecurityException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/SecurityException.php',
464465
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php',
465466
'OC\\AppFramework\\Middleware\\Security\\PasswordConfirmationMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php',
466467
'OC\\AppFramework\\Middleware\\Security\\RateLimitingMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php',
468+
'OC\\AppFramework\\Middleware\\Security\\ReloadExecutionMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/ReloadExecutionMiddleware.php',
467469
'OC\\AppFramework\\Middleware\\Security\\SameSiteCookieMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php',
468470
'OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php',
469471
'OC\\AppFramework\\Middleware\\SessionMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/SessionMiddleware.php',

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public function __construct($appName, $urlParams = array(), ServerContainer $ser
279279
$middleWares = &$this->middleWares;
280280
$this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) use (&$middleWares) {
281281
$dispatcher = new MiddlewareDispatcher();
282+
$dispatcher->registerMiddleware($c->query(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class));
282283
$dispatcher->registerMiddleware($c[OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware::class]);
283284
$dispatcher->registerMiddleware($c['CORSMiddleware']);
284285
$dispatcher->registerMiddleware($c['OCSMiddleware']);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
5+
*
6+
* @author Roeland Jago Douma <roeland@famdouma.nl>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OC\AppFramework\Middleware\Security\Exceptions;
26+
27+
class ReloadExecutionException extends SecurityException {
28+
29+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
5+
*
6+
* @author Roeland Jago Douma <roeland@famdouma.nl>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OC\AppFramework\Middleware\Security;
26+
27+
use OC\AppFramework\Middleware\Security\Exceptions\ReloadExecutionException;
28+
use OCP\AppFramework\Http\RedirectResponse;
29+
use OCP\AppFramework\Middleware;
30+
use OCP\ISession;
31+
use OCP\IURLGenerator;
32+
33+
/**
34+
* Simple middleware to handle the clearing of the execution context. This will trigger
35+
* a reload but if the session variable is set we properly redirect to the login page.
36+
*/
37+
class ReloadExecutionMiddleware extends Middleware {
38+
/** @var ISession */
39+
private $session;
40+
/** @var IURLGenerator */
41+
private $urlGenerator;
42+
43+
public function __construct(ISession $session, IURLGenerator $urlGenerator) {
44+
$this->session = $session;
45+
$this->urlGenerator = $urlGenerator;
46+
}
47+
48+
public function beforeController($controller, $methodName) {
49+
if ($this->session->exists('clearingExecutionContexts')) {
50+
throw new ReloadExecutionException();
51+
}
52+
}
53+
54+
public function afterException($controller, $methodName, \Exception $exception) {
55+
if ($exception instanceof ReloadExecutionException) {
56+
$this->session->remove('clearingExecutionContexts');
57+
58+
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute(
59+
'core.login.showLoginForm',
60+
['clear' => true] // this param the the code in login.js may be removed when the "Clear-Site-Data" is working in the browsers
61+
));
62+
}
63+
64+
return parent::afterException($controller, $methodName, $exception);
65+
}
66+
67+
68+
}

0 commit comments

Comments
 (0)