Skip to content

Commit 931adc8

Browse files
committed
feat(EphemeralSessions): Introduce lax period
Signed-off-by: Louis Chmn <[email protected]>
1 parent 88b7e75 commit 931adc8

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

3rdparty

Submodule 3rdparty updated 2189 files

lib/private/AppFramework/Middleware/FlowV2EphemeralSessionsMiddleware.php

Lines changed: 15 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;
@@ -21,22 +22,34 @@ class FlowV2EphemeralSessionsMiddleware extends Middleware {
2122
private ISession $session;
2223
private IUserSession $userSession;
2324
private ControllerMethodReflector $reflector;
25+
private ITimeFactory $timeFactory;
2426

2527
public function __construct(
2628
ISession $session,
2729
IUserSession $userSession,
28-
ControllerMethodReflector $reflector
30+
ControllerMethodReflector $reflector,
31+
ITimeFactory $timeFactory
2932
) {
3033
$this->session = $session;
3134
$this->userSession = $userSession;
3235
$this->reflector = $reflector;
36+
$this->timeFactory = $timeFactory;
3337
}
3438

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

52+
// Allow certain controllers/methods to proceed without logging out.
4053
if (
4154
$controller instanceof ClientFlowLoginV2Controller &&
4255
($methodName === 'grantPage' || $methodName === 'generateAppPassword')

lib/private/Authentication/Login/FlowV2EphemeralSessionsCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@
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
private ISession $session;
1718
private IURLGenerator $urlGenerator;
19+
private ITimeFactory $timeFactory;
1820

1921
public function __construct(
2022
ISession $session,
21-
IURLGenerator $urlGenerator
23+
IURLGenerator $urlGenerator,
24+
ITimeFactory $timeFactory
2225
) {
2326
$this->session = $session;
2427
$this->urlGenerator = $urlGenerator;
28+
$this->timeFactory = $timeFactory;
2529
}
2630

2731
public function process(LoginData $loginData): LoginResult {
2832
$loginV2GrantRoute = $this->urlGenerator->linkToRoute('core.ClientFlowLoginV2.grantPage');
2933
if (str_starts_with($loginData->getRedirectUrl() ?? '', $loginV2GrantRoute)) {
30-
$this->session->set(ClientFlowLoginV2Controller::EPHEMERAL_NAME, true);
34+
$this->session->set(ClientFlowLoginV2Controller::EPHEMERAL_NAME, $this->timeFactory->getTime());
3135
}
3236

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

0 commit comments

Comments
 (0)