Skip to content

Commit 770de1c

Browse files
authored
Merge pull request #56234 from nextcloud/backport/56215/stable31
[stable31] feat(EphemeralSessions): Introduce lax period
2 parents 4cc140d + 41f3ec8 commit 770de1c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/private/AppFramework/Middleware/FlowV2EphemeralSessionsMiddleware.php

Lines changed: 15 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;
@@ -22,19 +23,32 @@
2223
// Will close the session if the user session is ephemeral.
2324
// Happens when the user logs in via the login flow v2.
2425
class FlowV2EphemeralSessionsMiddleware extends Middleware {
26+
27+
private const EPHEMERAL_SESSION_TTL = 5 * 60; // 5 minutes
28+
2529
public function __construct(
2630
private ISession $session,
2731
private IUserSession $userSession,
2832
private ControllerMethodReflector $reflector,
2933
private LoggerInterface $logger,
34+
private ITimeFactory $timeFactory,
3035
) {
3136
}
3237

3338
public function beforeController(Controller $controller, string $methodName) {
34-
if (!$this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME)) {
39+
$sessionCreationTime = $this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME);
40+
41+
// Not an ephemeral session.
42+
if ($sessionCreationTime === null) {
43+
return;
44+
}
45+
46+
// Lax enforcement until TTL is reached.
47+
if ($this->timeFactory->getTime() < $sessionCreationTime + self::EPHEMERAL_SESSION_TTL) {
3548
return;
3649
}
3750

51+
// Allow certain controllers/methods to proceed without logging out.
3852
if (
3953
$controller instanceof ClientFlowLoginV2Controller &&
4054
($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)