Skip to content

Commit 9e8cb2b

Browse files
artongebackportbot[bot]
authored andcommitted
feat(EphemeralSessions): Introduce lax period
Signed-off-by: Louis Chmn <louis@chmn.me> [skip ci]
1 parent f77b9c2 commit 9e8cb2b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/private/AppFramework/Middleware/FlowV2EphemeralSessionsMiddleware.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCP\AppFramework\Controller;
1414
use OCP\AppFramework\Http\Attribute\PublicPage;
1515
use OCP\AppFramework\Middleware;
16+
use OCP\AppFramework\Utility\ITimeFactory;
1617
use OCP\Authentication\TwoFactorAuth\ALoginSetupController;
1718
use OCP\ISession;
1819
use OCP\IUserSession;
@@ -21,6 +22,9 @@
2122
// Will close the session if the user session is ephemeral.
2223
// Happens when the user logs in via the login flow v2.
2324
class FlowV2EphemeralSessionsMiddleware extends Middleware {
25+
26+
private const EPHEMERAL_SESSION_TTL = 5 * 60; // 5 minutes
27+
2428
public function __construct(
2529
private ISession $session,
2630
private IUserSession $userSession,
@@ -29,10 +33,19 @@ public function __construct(
2933
}
3034

3135
public function beforeController(Controller $controller, string $methodName) {
32-
if (!$this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME)) {
36+
$sessionCreationTime = $this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME);
37+
38+
// Not an ephemeral session.
39+
if ($sessionCreationTime === null) {
40+
return;
41+
}
42+
43+
// Lax enforcement until TTL is reached.
44+
if ($this->timeFactory->getTime() < $sessionCreationTime + self::EPHEMERAL_SESSION_TTL) {
3345
return;
3446
}
3547

48+
// Allow certain controllers/methods to proceed without logging out.
3649
if (
3750
$controller instanceof ClientFlowLoginV2Controller &&
3851
($methodName === 'grantPage' || $methodName === 'generateAppPassword')

lib/private/Authentication/Login/FlowV2EphemeralSessionsCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@
99
namespace OC\Authentication\Login;
1010

1111
use OC\Core\Controller\ClientFlowLoginV2Controller;
12+
use OCP\AppFramework\Utility\ITimeFactory;
1213
use OCP\ISession;
1314
use OCP\IURLGenerator;
1415

1516
class FlowV2EphemeralSessionsCommand extends ALoginCommand {
1617
public function __construct(
1718
private ISession $session,
1819
private IURLGenerator $urlGenerator,
20+
private ITimeFactory $timeFactory,
1921
) {
2022
}
2123

2224
public function process(LoginData $loginData): LoginResult {
2325
$loginV2GrantRoute = $this->urlGenerator->linkToRoute('core.ClientFlowLoginV2.grantPage');
2426
if (str_starts_with($loginData->getRedirectUrl() ?? '', $loginV2GrantRoute)) {
25-
$this->session->set(ClientFlowLoginV2Controller::EPHEMERAL_NAME, true);
27+
$this->session->set(ClientFlowLoginV2Controller::EPHEMERAL_NAME, $this->timeFactory->getTime());
2628
}
2729

2830
return $this->processNextOrFinishSuccessfully($loginData);

0 commit comments

Comments
 (0)