Skip to content

Commit 0dcb4fc

Browse files
committed
feat(EphemeralSessions): Introduce lax period
Signed-off-by: Louis Chmn <louis@chmn.me>
1 parent e896bdc commit 0dcb4fc

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/private/AppFramework/Middleware/FlowV2EphemeralSessionsMiddleware.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@
1111
use OC\Core\Controller\ClientFlowLoginV2Controller;
1212
use OC\Core\Controller\TwoFactorChallengeController;
1313
use OCP\AppFramework\Middleware;
14+
use OCP\AppFramework\Utility\ITimeFactory;
1415
use OCP\Authentication\TwoFactorAuth\ALoginSetupController;
1516
use OCP\ISession;
1617
use OCP\IUserSession;
1718

1819
// Will close the session if the user session is ephemeral.
1920
// Happens when the user logs in via the login flow v2.
2021
class FlowV2EphemeralSessionsMiddleware extends Middleware {
22+
23+
private const EPHEMERAL_SESSION_TTL = 5 * 60; // 5 minutes
24+
2125
public function __construct(
2226
private ISession $session,
2327
private IUserSession $userSession,
2428
private ControllerMethodReflector $reflector,
29+
private ITimeFactory $timeFactory,
2530
) {
2631
}
2732

@@ -30,6 +35,12 @@ public function beforeController($controller, $methodName) {
3035
return;
3136
}
3237

38+
// Lax enforcement until TTL is reached.
39+
if ($this->timeFactory->getTime() < $sessionCreationTime + self::EPHEMERAL_SESSION_TTL) {
40+
return;
41+
}
42+
43+
// Allow certain controllers/methods to proceed without logging out.
3344
if (
3445
$controller instanceof ClientFlowLoginV2Controller &&
3546
($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)