|
11 | 11 | use OC\Core\Controller\ClientFlowLoginV2Controller; |
12 | 12 | use OC\Core\Controller\TwoFactorChallengeController; |
13 | 13 | use OCP\AppFramework\Middleware; |
| 14 | +use OCP\AppFramework\Utility\ITimeFactory; |
14 | 15 | use OCP\Authentication\TwoFactorAuth\ALoginSetupController; |
15 | 16 | use OCP\ISession; |
16 | 17 | use OCP\IUserSession; |
17 | 18 |
|
18 | 19 | // Will close the session if the user session is ephemeral. |
19 | 20 | // Happens when the user logs in via the login flow v2. |
20 | 21 | class FlowV2EphemeralSessionsMiddleware extends Middleware { |
| 22 | + private const EPHEMERAL_SESSION_TTL = 5 * 60; // 5 minutes |
| 23 | + |
21 | 24 | public function __construct( |
22 | 25 | private ISession $session, |
23 | 26 | private IUserSession $userSession, |
24 | 27 | private ControllerMethodReflector $reflector, |
| 28 | + private ITimeFactory $timeFactory, |
25 | 29 | ) { |
26 | 30 | } |
27 | 31 |
|
28 | 32 | public function beforeController($controller, $methodName) { |
29 | | - if (!$this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME)) { |
| 33 | + $sessionCreationTime = $this->session->get(ClientFlowLoginV2Controller::EPHEMERAL_NAME); |
| 34 | + |
| 35 | + // Not an ephemeral session. |
| 36 | + if ($sessionCreationTime === null) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + // Lax enforcement until TTL is reached. |
| 41 | + if ($this->timeFactory->getTime() < $sessionCreationTime + self::EPHEMERAL_SESSION_TTL) { |
30 | 42 | return; |
31 | 43 | } |
32 | 44 |
|
| 45 | + // Allow certain controllers/methods to proceed without logging out. |
33 | 46 | if ( |
34 | 47 | $controller instanceof ClientFlowLoginV2Controller && |
35 | 48 | ($methodName === 'grantPage' || $methodName === 'generateAppPassword') |
|
0 commit comments