1111use OC \Core \Controller \ClientFlowLoginV2Controller ;
1212use OC \Core \Controller \TwoFactorChallengeController ;
1313use OCP \AppFramework \Middleware ;
14+ use OCP \AppFramework \Utility \ITimeFactory ;
1415use OCP \Authentication \TwoFactorAuth \ALoginSetupController ;
1516use OCP \ISession ;
1617use 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 ' )
0 commit comments