diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 3ff87051f738d..67d4666c31ed0 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -144,6 +144,10 @@ export const configureNextcloud = async function() { // Speed up test and make them less flaky. If a cron execution is needed, it can be triggered manually. await runExec(container, ['php', 'occ', 'background:cron'], true) + // Disable bruteforce protection to not run into it + await runExec(container, ['php', 'occ', 'config:system:set', 'auth.bruteforce.protection.enabled', '--value', 'false', '--type', 'boolean'], true) + await runExec(container, ['php', 'occ', 'config:system:set', 'ratelimit.protection.enabled', '--value', 'false', '--type', 'boolean'], true) + // Checking apcu const distributed = await runExec(container, ['php', 'occ', 'config:system:get', 'memcache.distributed']) const local = await runExec(container, ['php', 'occ', 'config:system:get', 'memcache.local']) diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 46897845cbdf8..339c13bfe4800 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OC\User; use OC; @@ -70,6 +71,8 @@ class Session implements IUserSession, Emitter { /** @var User $activeUser */ protected $activeUser; + private ?IThrottler $throttler = null; + public function __construct( private Manager $manager, private ISession $session, @@ -83,6 +86,11 @@ public function __construct( ) { } + private function getThrottler(): IThrottler { + $this->throttler ??= Server::get(IThrottler::class); + return $this->throttler; + } + /** * @param IProvider $provider */ @@ -829,6 +837,7 @@ private function validateTokenLoginName(?string $loginName, IToken $token): bool * @return boolean */ public function tryTokenLogin(IRequest $request) { + $throttler = $this->getThrottler(); $authHeader = $request->getHeader('Authorization'); $tokenFromCookie = false; if (str_starts_with($authHeader, 'Bearer ')) { @@ -846,10 +855,13 @@ public function tryTokenLogin(IRequest $request) { return false; } + $remoteAddress = $request->getRemoteAddress(); + $currentDelay = $throttler->sleepDelayOrThrowOnMax($remoteAddress, 'login'); + try { $dbToken = $this->tokenProvider->getToken($token); } catch (InvalidTokenException $e) { - // Can't really happen but better safe than sorry + $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, '', $token); return false; } @@ -859,9 +871,11 @@ public function tryTokenLogin(IRequest $request) { } if (!$this->loginWithToken($token)) { + $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $dbToken->getUID(), $token); return false; } if (!$this->validateToken($token)) { + $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $dbToken->getUID(), $token); return false; }