|
13 | 13 | use OCP\AppFramework\Controller; |
14 | 14 | use OCP\AppFramework\Http\Attribute\PublicPage; |
15 | 15 | use OCP\AppFramework\Middleware; |
| 16 | +use OCP\AppFramework\Utility\ITimeFactory; |
16 | 17 | use OCP\Authentication\TwoFactorAuth\ALoginSetupController; |
17 | 18 | use OCP\ISession; |
18 | 19 | use OCP\IUserSession; |
|
22 | 23 | // Will close the session if the user session is ephemeral. |
23 | 24 | // Happens when the user logs in via the login flow v2. |
24 | 25 | class FlowV2EphemeralSessionsMiddleware extends Middleware { |
| 26 | + |
| 27 | + private const EPHEMERAL_SESSION_TTL = 5 * 60; // 5 minutes |
| 28 | + |
25 | 29 | public function __construct( |
26 | 30 | private ISession $session, |
27 | 31 | private IUserSession $userSession, |
28 | 32 | private ControllerMethodReflector $reflector, |
29 | 33 | private LoggerInterface $logger, |
| 34 | + private ITimeFactory $timeFactory, |
30 | 35 | ) { |
31 | 36 | } |
32 | 37 |
|
33 | 38 | 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) { |
35 | 48 | return; |
36 | 49 | } |
37 | 50 |
|
| 51 | + // Allow certain controllers/methods to proceed without logging out. |
38 | 52 | if ( |
39 | 53 | $controller instanceof ClientFlowLoginV2Controller && |
40 | 54 | ($methodName === 'grantPage' || $methodName === 'generateAppPassword') |
|
0 commit comments