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 ;
@@ -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 ' )
0 commit comments