Skip to content

Commit f06f1d0

Browse files
Merge pull request #63718 from nextcloud/backport/63705/stable35
[stable35] fix: Check rememberme cookie previous session id matches uid
2 parents 3ad7b12 + c25d676 commit f06f1d0

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

lib/private/User/Session.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,26 @@ public function loginWithCookie($uid, $currentToken, $oldSessionId) {
903903
]);
904904
return false;
905905
}
906+
907+
try {
908+
$oldToken = $this->tokenProvider->getToken($oldSessionId);
909+
} catch (InvalidTokenException $ex) {
910+
$this->logger->error('Could not find the session token to renew', [
911+
'app' => 'core',
912+
'user' => $uid,
913+
'exception' => $ex,
914+
]);
915+
return false;
916+
}
917+
918+
if ($oldToken->getUID() !== $user->getUID()) {
919+
$this->logger->warning('Tried to renew a session token belonging to a different user', [
920+
'app' => 'core',
921+
'user' => $uid,
922+
]);
923+
return false;
924+
}
925+
906926
// replace successfully used token with a new one
907927
$this->config->deleteUserValue($uid, 'login_token', $currentToken);
908928
$newToken = $this->random->generate(32);

tests/lib/User/SessionTest.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,14 @@ public function testRememberLoginValidToken(): void {
794794
->with($oldSessionId, $sessionId)
795795
->willReturn($tokenObject);
796796

797-
$this->tokenProvider->expects($this->never())
798-
->method('getToken');
797+
$oldTokenObject = $this->createMock(IToken::class);
798+
$oldTokenObject->expects($this->once())
799+
->method('getUID')
800+
->willReturn('foo');
801+
802+
$this->tokenProvider->expects($this->once())
803+
->method('getToken')
804+
->willReturn($oldTokenObject);
799805

800806
$user->expects($this->any())
801807
->method('getUID')
@@ -872,7 +878,16 @@ public function testRememberLoginInvalidSessionToken(): void {
872878
->with($oldSessionId, $sessionId)
873879
->willThrowException(new InvalidTokenException());
874880

875-
$user->expects($this->never())
881+
$oldTokenObject = $this->createMock(IToken::class);
882+
$oldTokenObject->expects($this->once())
883+
->method('getUID')
884+
->willReturn('foo');
885+
886+
$this->tokenProvider->expects($this->once())
887+
->method('getToken')
888+
->willReturn($oldTokenObject);
889+
890+
$user->expects($this->once())
876891
->method('getUID')
877892
->willReturn('foo');
878893
$userSession->expects($this->never())

0 commit comments

Comments
 (0)