Skip to content

Commit c09f27a

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

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/private/AppFramework/Middleware/FlowV2EphemeralSessionsMiddleware.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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;
@@ -25,18 +26,28 @@ class FlowV2EphemeralSessionsMiddleware extends Middleware {
2526
public function __construct(
2627
ISession $session,
2728
IUserSession $userSession,
28-
ControllerMethodReflector $reflector
29+
ControllerMethodReflector $reflector,
30+
private ITimeFactory $timeFactory
2931
) {
3032
$this->session = $session;
3133
$this->userSession = $userSession;
3234
$this->reflector = $reflector;
3335
}
3436

3537
public function beforeController($controller, $methodName) {
36-
if (!$this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME)) {
38+
$sessionCreationTime = $this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME);
39+
40+
// Not an ephemeral session.
41+
if ($sessionCreationTime === null) {
42+
return;
43+
}
44+
45+
// Lax enforcement until TTL is reached.
46+
if ($this->timeFactory->getTime() < $sessionCreationTime + self::EPHEMERAL_SESSION_TTL) {
3747
return;
3848
}
3949

50+
// Allow certain controllers/methods to proceed without logging out.
4051
if (
4152
$controller instanceof ClientFlowLoginV2Controller &&
4253
($methodName === 'grantPage' || $methodName === 'generateAppPassword')

lib/private/Authentication/Login/FlowV2EphemeralSessionsCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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

@@ -27,7 +28,7 @@ public function __construct(
2728
public function process(LoginData $loginData): LoginResult {
2829
$loginV2GrantRoute = $this->urlGenerator->linkToRoute('core.ClientFlowLoginV2.grantPage');
2930
if (str_starts_with($loginData->getRedirectUrl() ?? '', $loginV2GrantRoute)) {
30-
$this->session->set(ClientFlowLoginV2Controller::EPHEMERAL_NAME, true);
31+
$this->session->set(ClientFlowLoginV2Controller::EPHEMERAL_NAME, $this->timeFactory->getTime());
3132
}
3233

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

0 commit comments

Comments
 (0)