Skip to content

Commit 60e5a5e

Browse files
committed
Do not do redirect handling when loggin out
Fixes #12568 Since the clearing of the execution context causes another reload. We should not do the redirect_uri handling as this results in redirecting back to the logout page on login. This adds a simple middleware that will just check if the ClearExecutionContext session variable is set. If that is the case it will just redirect back to the login page. Signed-off-by: Roeland Jago Douma <[email protected]>
1 parent 780e148 commit 60e5a5e

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed

core/Controller/LoginController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public function logout() {
134134
'core.login.showLoginForm',
135135
['clear' => true] // this param the the code in login.js may be removed when the "Clear-Site-Data" is working in the browsers
136136
));
137+
138+
$this->session->set('clearingExecutionContexts', '1');
139+
$this->session->close();
137140
$response->addHeader('Clear-Site-Data', '"cache", "storage", "executionContexts"');
138141
return $response;
139142
}
@@ -149,7 +152,6 @@ public function logout() {
149152
* @return TemplateResponse|RedirectResponse
150153
*/
151154
public function showLoginForm(string $user = null, string $redirect_url = null): Http\Response {
152-
153155
if ($this->userSession->isLoggedIn()) {
154156
return new RedirectResponse(OC_Util::getDefaultPageUrl());
155157
}

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,12 @@
432432
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotAdminException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php',
433433
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotConfirmedException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotConfirmedException.php',
434434
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotLoggedInException.php',
435+
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\ReloadExecutionException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/ReloadExecutionException.php',
435436
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\SecurityException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/SecurityException.php',
436437
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php',
437438
'OC\\AppFramework\\Middleware\\Security\\PasswordConfirmationMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php',
438439
'OC\\AppFramework\\Middleware\\Security\\RateLimitingMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php',
440+
'OC\\AppFramework\\Middleware\\Security\\ReloadExecutionMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/ReloadExecutionMiddleware.php',
439441
'OC\\AppFramework\\Middleware\\Security\\SameSiteCookieMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php',
440442
'OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php',
441443
'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
@@ -462,10 +462,12 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
462462
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotAdminException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotAdminException.php',
463463
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotConfirmedException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotConfirmedException.php',
464464
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/NotLoggedInException.php',
465+
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\ReloadExecutionException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/ReloadExecutionException.php',
465466
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\SecurityException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/SecurityException.php',
466467
'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php',
467468
'OC\\AppFramework\\Middleware\\Security\\PasswordConfirmationMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php',
468469
'OC\\AppFramework\\Middleware\\Security\\RateLimitingMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php',
470+
'OC\\AppFramework\\Middleware\\Security\\ReloadExecutionMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/ReloadExecutionMiddleware.php',
469471
'OC\\AppFramework\\Middleware\\Security\\SameSiteCookieMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/SameSiteCookieMiddleware.php',
470472
'OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php',
471473
'OC\\AppFramework\\Middleware\\SessionMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/SessionMiddleware.php',

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ public function __construct($appName, $urlParams = array(), ServerContainer $ser
185185
$server = $this->getServer();
186186

187187
$dispatcher = new MiddlewareDispatcher();
188+
$dispatcher->registerMiddleware(
189+
$c->query(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class)
190+
);
191+
188192
$dispatcher->registerMiddleware(
189193
new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
190194
$c->query(IRequest::class),
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 <[email protected]>
5+
*
6+
* @author Roeland Jago Douma <[email protected]>
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 <[email protected]>
5+
*
6+
* @author Roeland Jago Douma <[email protected]>
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)