Skip to content

Commit 66c9507

Browse files
committed
Error out early on an expired token
Fixes #12131 If we hit an expired token there is no need to continue checking. Since we know it is a token. We also should not register this with the bruteforce throttler as it is actually a valid token. Just expired. Instead the authentication should fail. And buisness continues as usual. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 360d7b9 commit 66c9507

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/private/User/Session.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
namespace OC\User;
3939

4040
use OC;
41+
use OC\Authentication\Exceptions\ExpiredTokenException;
4142
use OC\Authentication\Exceptions\InvalidTokenException;
4243
use OC\Authentication\Exceptions\PasswordlessTokenException;
4344
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
@@ -401,7 +402,13 @@ public function logClientIn($user,
401402
$this->manager->emit('\OC\User', 'preLogin', array($user, $password));
402403
}
403404

404-
$isTokenPassword = $this->isTokenPassword($password);
405+
try {
406+
$isTokenPassword = $this->isTokenPassword($password);
407+
} catch (ExpiredTokenException $e) {
408+
// Just return on an expired token no need to check further or record a failed login
409+
return false;
410+
}
411+
405412
if (!$isTokenPassword && $this->isTokenAuthEnforced()) {
406413
throw new PasswordLoginForbiddenException();
407414
}
@@ -474,11 +481,14 @@ protected function isTwoFactorEnforced($username) {
474481
*
475482
* @param string $password
476483
* @return boolean
484+
* @throws ExpiredTokenException
477485
*/
478486
public function isTokenPassword($password) {
479487
try {
480488
$this->tokenProvider->getToken($password);
481489
return true;
490+
} catch (ExpiredTokenException $e) {
491+
throw $e;
482492
} catch (InvalidTokenException $ex) {
483493
return false;
484494
}

0 commit comments

Comments
 (0)